Prefer std::variant in dataNode_/schemaNode_

Right now, I already got rid of using spirit alternative parser to parse
different types of nodes (leaf, container...), so no reason to use
boost::variant over std::variant.

Change-Id: I1f713427117d7135b8309b7129f3b025465a9f7d
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index b9cf883..ca39b21 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -178,14 +178,14 @@
             boost::optional<std::string> module;
             if (ast.m_nodes.back().m_prefix)
                 module = ast.m_nodes.back().m_prefix.value().m_name;
-            container_ cont = boost::get<container_>(ast.m_nodes.back().m_suffix);
+            container_ cont = std::get<container_>(ast.m_nodes.back().m_suffix);
             auto location = pathWithoutLastNode(parserContext.currentSchemaPath());
 
             if (!schema.isPresenceContainer(location, {module, cont.m_name})) {
                 parserContext.m_errorMsg = "This container is not a presence container.";
                 _pass(context) = false;
             }
-        } catch (boost::bad_get&) {
+        } catch (std::bad_variant_access&) {
             parserContext.m_errorMsg = "This is not a container.";
             _pass(context) = false;
         }
@@ -203,7 +203,7 @@
             return;
         }
 
-        if (ast.m_nodes.back().m_suffix.type() != typeid(listElement_)) {
+        if (!std::holds_alternative<listElement_>(ast.m_nodes.back().m_suffix)) {
             parserContext.m_errorMsg = "This is not a list instance.";
             _pass(context) = false;
         }
@@ -215,7 +215,7 @@
     void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
     {
         auto& parserContext = x3::get<parser_context_tag>(context);
-        if (ast.m_nodes.empty() || ast.m_nodes.back().m_suffix.type() != typeid(leafListElement_)) {
+        if (ast.m_nodes.empty() || !std::holds_alternative<leafListElement_>(ast.m_nodes.back().m_suffix)) {
             parserContext.m_errorMsg = "This is not a leaf list element.";
             _pass(context) = false;
         }
@@ -267,14 +267,14 @@
 
         try {
             auto lastNode = parserContext.currentSchemaPath().m_nodes.back();
-            auto leaf = boost::get<leaf_>(lastNode.m_suffix);
+            auto leaf = std::get<leaf_>(lastNode.m_suffix);
             auto location = pathWithoutLastNode(parserContext.currentSchemaPath());
             ModuleNodePair node{lastNode.m_prefix.flat_map([](const auto& it) { return boost::optional<std::string>{it.m_name}; }), leaf.m_name};
 
             parserContext.m_tmpListKeyLeafPath.m_location = location;
             parserContext.m_tmpListKeyLeafPath.m_node = node;
 
-        } catch (boost::bad_get&) {
+        } catch (std::bad_variant_access&) {
             parserContext.m_errorMsg = "This is not a path to leaf.";
             _pass(context) = false;
         }
diff --git a/src/ast_path.cpp b/src/ast_path.cpp
index b9b9b5a..1a26a1c 100644
--- a/src/ast_path.cpp
+++ b/src/ast_path.cpp
@@ -124,8 +124,7 @@
     return this->m_nodes == b.m_nodes;
 }
 
-
-struct nodeToSchemaStringVisitor : public boost::static_visitor<std::string> {
+struct nodeToSchemaStringVisitor {
     std::string operator()(const nodeup_&) const
     {
         return "..";
@@ -148,7 +147,7 @@
     }
 }
 
-struct nodeToDataStringVisitor : public boost::static_visitor<std::string> {
+struct nodeToDataStringVisitor {
     std::string operator()(const listElement_& node) const
     {
         std::ostringstream res;
@@ -176,7 +175,7 @@
 
 std::string nodeToSchemaString(decltype(dataPath_::m_nodes)::value_type node)
 {
-    return boost::apply_visitor(nodeToSchemaStringVisitor(), node.m_suffix);
+    return std::visit(nodeToSchemaStringVisitor(), node.m_suffix);
 }
 
 std::string pathToDataString(const dataPath_& path, Prefixes prefixes)
@@ -188,9 +187,9 @@
 
     for (const auto& it : path.m_nodes) {
         if (it.m_prefix)
-            res = joinPaths(res, it.m_prefix.value().m_name + ":" + boost::apply_visitor(nodeToDataStringVisitor(), it.m_suffix));
+            res = joinPaths(res, it.m_prefix.value().m_name + ":" + std::visit(nodeToDataStringVisitor(), it.m_suffix));
         else
-            res = joinPaths(res, (prefixes == Prefixes::Always ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + boost::apply_visitor(nodeToDataStringVisitor(), it.m_suffix));
+            res = joinPaths(res, (prefixes == Prefixes::Always ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + std::visit(nodeToDataStringVisitor(), it.m_suffix));
     }
 
     return res;
@@ -205,9 +204,9 @@
 
     for (const auto& it : path.m_nodes) {
         if (it.m_prefix)
-            res = joinPaths(res, it.m_prefix.value().m_name + ":" + boost::apply_visitor(nodeToSchemaStringVisitor(), it.m_suffix));
+            res = joinPaths(res, it.m_prefix.value().m_name + ":" + std::visit(nodeToSchemaStringVisitor(), it.m_suffix));
         else
-            res = joinPaths(res, (prefixes == Prefixes::Always ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + boost::apply_visitor(nodeToSchemaStringVisitor(), it.m_suffix));
+            res = joinPaths(res, (prefixes == Prefixes::Always ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + std::visit(nodeToSchemaStringVisitor(), it.m_suffix));
     }
     return res;
 }
@@ -217,19 +216,20 @@
     return pathToSchemaString(dataPathToSchemaPath(path), prefixes);
 }
 
-struct dataSuffixToSchemaSuffix : boost::static_visitor<decltype(schemaNode_::m_suffix)> {
-    auto operator()(const listElement_& listElement) const
+struct dataSuffixToSchemaSuffix {
+    using ReturnType = decltype(schemaNode_::m_suffix);
+    ReturnType operator()(const listElement_& listElement) const
     {
         return list_{listElement.m_name};
     }
 
-    auto operator()(const leafListElement_& leafListElement) const
+    ReturnType operator()(const leafListElement_& leafListElement) const
     {
         return leafList_{leafListElement.m_name};
     }
 
     template <typename T>
-    auto operator()(const T& suffix) const
+    ReturnType operator()(const T& suffix) const
     {
         return suffix;
     }
@@ -239,7 +239,7 @@
 {
     schemaNode_ res;
     res.m_prefix = node.m_prefix;
-    res.m_suffix = boost::apply_visitor(dataSuffixToSchemaSuffix(), node.m_suffix);
+    res.m_suffix = std::visit(dataSuffixToSchemaSuffix(), node.m_suffix);
     return res;
 }
 
diff --git a/src/ast_path.hpp b/src/ast_path.hpp
index f768461..b1b949c 100644
--- a/src/ast_path.hpp
+++ b/src/ast_path.hpp
@@ -10,8 +10,8 @@
 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
 #include <boost/fusion/include/adapt_struct.hpp>
 #include <boost/fusion/include/std_pair.hpp>
-#include <boost/variant/variant.hpp>
 #include <map>
+#include <variant>
 #include <vector>
 
 #include "ast_values.hpp"
@@ -83,7 +83,7 @@
 
 struct schemaNode_ {
     boost::optional<module_> m_prefix;
-    boost::variant<container_, list_, nodeup_, leaf_, leafList_> m_suffix;
+    std::variant<container_, list_, nodeup_, leaf_, leafList_> m_suffix;
 
     schemaNode_();
     schemaNode_(decltype(m_suffix) node);
@@ -93,7 +93,7 @@
 
 struct dataNode_ {
     boost::optional<module_> m_prefix;
-    boost::variant<container_, listElement_, nodeup_, leaf_, leafListElement_, leafList_, list_> m_suffix;
+    std::variant<container_, listElement_, nodeup_, leaf_, leafListElement_, leafList_, list_> m_suffix;
 
     dataNode_();
     dataNode_(decltype(m_suffix) node);
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index ffe303b..2d69e63 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -65,9 +65,9 @@
 
 void Interpreter::operator()(const create_& create) const
 {
-    if (create.m_path.m_nodes.back().m_suffix.type() == typeid(listElement_))
+    if (std::holds_alternative<listElement_>(create.m_path.m_nodes.back().m_suffix))
         m_datastore.createListInstance(absolutePathFromCommand(create));
-    else if (create.m_path.m_nodes.back().m_suffix.type() == typeid(leafListElement_))
+    else if (std::holds_alternative<leafListElement_>(create.m_path.m_nodes.back().m_suffix))
         m_datastore.createLeafListInstance(absolutePathFromCommand(create));
     else
         m_datastore.createPresenceContainer(absolutePathFromCommand(create));
@@ -75,9 +75,9 @@
 
 void Interpreter::operator()(const delete_& delet) const
 {
-    if (delet.m_path.m_nodes.back().m_suffix.type() == typeid(container_))
+    if (std::holds_alternative<container_>(delet.m_path.m_nodes.back().m_suffix))
         m_datastore.deletePresenceContainer(absolutePathFromCommand(delet));
-    else if (delet.m_path.m_nodes.back().m_suffix.type() == typeid(leafListElement_))
+    else if (std::holds_alternative<leafListElement_>(delet.m_path.m_nodes.back().m_suffix))
         m_datastore.deleteLeafListInstance(absolutePathFromCommand(delet));
     else
         m_datastore.deleteListInstance(absolutePathFromCommand(delet));
diff --git a/src/parser.cpp b/src/parser.cpp
index 2942d56..195789b 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -88,7 +88,7 @@
         m_curDir = name;
     } else {
         for (const auto& it : name.m_nodes) {
-            if (it.m_suffix.type() == typeid(nodeup_))
+            if (std::holds_alternative<nodeup_>(it.m_suffix))
                 m_curDir.m_nodes.pop_back();
             else
                 m_curDir.m_nodes.push_back(it);
diff --git a/src/parser_context.cpp b/src/parser_context.cpp
index 26e6fa3..6b15cb9 100644
--- a/src/parser_context.cpp
+++ b/src/parser_context.cpp
@@ -43,7 +43,7 @@
 void ParserContext::pushPathFragment(const dataNode_& node)
 {
     auto pushNode = [this] (auto& where, const auto& what) {
-        if (what.m_suffix.type() == typeid(nodeup_)) {
+        if (std::holds_alternative<nodeup_>(what.m_suffix)) {
             where.m_nodes.pop_back();
             if (where.m_nodes.empty()) {
                 m_topLevelModulePresent = false;
diff --git a/src/path_parser.hpp b/src/path_parser.hpp
index 6cac725..bb622ef 100644
--- a/src/path_parser.hpp
+++ b/src/path_parser.hpp
@@ -170,19 +170,19 @@
                 parserContext.m_curModule = attr.m_prefix->m_name;
             }
 
-            if (attr.m_suffix.type() == typeid(leaf_)) {
+            if (std::holds_alternative<leaf_>(attr.m_suffix)) {
                 parserContext.m_tmpListKeyLeafPath.m_location = parserContext.currentSchemaPath();
                 ModuleNodePair node{attr.m_prefix.flat_map([](const auto& it) {
                                         return boost::optional<std::string>{it.m_name};
                                     }),
-                                    boost::get<leaf_>(attr.m_suffix).m_name};
+                                    std::get<leaf_>(attr.m_suffix).m_name};
                 parserContext.m_tmpListKeyLeafPath.m_node = node;
             }
 
             if constexpr (std::is_same<attribute_type, dataNode_>()) {
-                if (attr.m_suffix.type() == typeid(listElement_)) {
-                    parserContext.m_tmpListName = boost::get<listElement_>(attr.m_suffix).m_name;
-                    res = listSuffix.parse(begin, end, ctx, rctx, boost::get<listElement_>(attr.m_suffix).m_keys);
+                if (std::holds_alternative<listElement_>(attr.m_suffix)) {
+                    parserContext.m_tmpListName = std::get<listElement_>(attr.m_suffix).m_name;
+                    res = listSuffix.parse(begin, end, ctx, rctx, std::get<listElement_>(attr.m_suffix).m_keys);
 
                     // FIXME: think of a better way to do this, that is, get rid of manual iterator reverting
                     if (!res) {
@@ -190,26 +190,26 @@
                         // If we don't, we fail the whole symbol table.
                         if constexpr (PARSER_MODE == NodeParserMode::IncompleteDataNode) {
                             res = true;
-                            attr.m_suffix = list_{boost::get<listElement_>(attr.m_suffix).m_name};
+                            attr.m_suffix = list_{std::get<listElement_>(attr.m_suffix).m_name};
                         } else {
                             begin = saveIter;
                         }
                     }
                 }
 
-                if (attr.m_suffix.type() == typeid(leafListElement_)) {
+                if (std::holds_alternative<leafListElement_>(attr.m_suffix)) {
                     parserContext.m_tmpListKeyLeafPath.m_location = parserContext.currentSchemaPath();
                     ModuleNodePair node{attr.m_prefix.flat_map([](const auto& it) {
                                             return boost::optional<std::string>{it.m_name};
                                         }),
-                                        boost::get<leafListElement_>(attr.m_suffix).m_name};
+                                        std::get<leafListElement_>(attr.m_suffix).m_name};
                     parserContext.m_tmpListKeyLeafPath.m_node = node;
-                    res = leafListValue.parse(begin, end, ctx, rctx, boost::get<leafListElement_>(attr.m_suffix).m_value);
+                    res = leafListValue.parse(begin, end, ctx, rctx, std::get<leafListElement_>(attr.m_suffix).m_value);
 
                     if (!res) {
                         if constexpr (PARSER_MODE == NodeParserMode::IncompleteDataNode) {
                             res = true;
-                            attr.m_suffix = leafList_{boost::get<leafListElement_>(attr.m_suffix).m_name};
+                            attr.m_suffix = leafList_{std::get<leafListElement_>(attr.m_suffix).m_name};
                         } else {
                             begin = saveIter;
                         }
@@ -303,7 +303,7 @@
         if constexpr (PARSER_MODE == PathParserMode::AnyPath) {
             // If our data path already has some listElement_ fragments, we can't parse rest of the path as a schema path
             auto hasLists = std::any_of(attrData.m_nodes.begin(), attrData.m_nodes.end(),
-                [] (const auto& node) { return node.m_suffix.type() == typeid(listElement_); });
+                [] (const auto& node) { return std::holds_alternative<listElement_>(node.m_suffix); });
             // If parsing failed, or if there's more input we try parsing schema nodes.
             if (!hasLists) {
                 if (!res || !pathEnd.parse(begin, end, ctx, rctx, x3::unused)) {