From: Wolfgang Bangerth Date: Sun, 6 Mar 2022 06:07:35 +0000 (-0700) Subject: Convert uses of boost::variant to std_cxx17::variant. X-Git-Tag: v9.4.0-rc1~405^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13497%2Fhead;p=dealii.git Convert uses of boost::variant to std_cxx17::variant. --- diff --git a/include/deal.II/base/table_handler.h b/include/deal.II/base/table_handler.h index 3b1c65d6d6..2024c05cac 100644 --- a/include/deal.II/base/table_handler.h +++ b/include/deal.II/base/table_handler.h @@ -20,13 +20,13 @@ #include #include +#include DEAL_II_DISABLE_EXTRA_DIAGNOSTICS #include #include #include #include -#include DEAL_II_ENABLE_EXTRA_DIAGNOSTICS #include @@ -48,10 +48,10 @@ namespace internal /** * A TableEntry stores the value of a table entry. It can either be * of type int, unsigned int, std::uint64_t, double or std::string. In - * essence, this structure is the same as boost::variant@ but we wrap this object in a + * essence, this structure is the same as `std::variant` but we wrap this object in a * structure for which we can write a function that can serialize it. This is - * also why the function is not in fact of type boost::any. + * also why the function is not in fact of type std::any. */ struct TableEntry { @@ -151,7 +151,7 @@ namespace internal * Abbreviation for the data type stored by this object. */ using value_type = - boost::variant; + std_cxx17::variant; /** * Stored value. @@ -820,13 +820,13 @@ namespace internal { // we don't quite know the data type in 'value', but // it must be one of the ones in the type list of the - // boost::variant. so if T is not in the list, or if + // std_cxx17::variant. so if T is not in the list, or if // the data stored in the TableEntry is not of type // T, then we will get an exception that we can // catch and produce an error message try { - return boost::get(value); + return std_cxx17::get(value); } catch (...) { diff --git a/source/base/table_handler.cc b/source/base/table_handler.cc index fd7ba5a938..86df306755 100644 --- a/source/base/table_handler.cc +++ b/source/base/table_handler.cc @@ -36,13 +36,13 @@ namespace internal { // we don't quite know the data type in 'value', but // it must be one of the ones in the type list of the - // boost::variant. Go through this list and return + // std_cxx17::variant. Go through this list and return // the value if this happens to be a number // // first try with int try { - return boost::get(value); + return std_cxx17::get(value); } catch (...) {} @@ -51,7 +51,7 @@ namespace internal // ... then with unsigned int... try { - return boost::get(value); + return std_cxx17::get(value); } catch (...) {} @@ -59,7 +59,7 @@ namespace internal // ... then with std::uint64_t... try { - return boost::get(value); + return std_cxx17::get(value); } catch (...) {} @@ -67,7 +67,7 @@ namespace internal // ...and finally with double precision: try { - return boost::get(value); + return std_cxx17::get(value); } catch (...) { @@ -105,6 +105,7 @@ namespace internal } +#ifndef DEAL_II_HAVE_CXX17 namespace Local { // see which type we can cast to, then use this type to create @@ -119,12 +120,20 @@ namespace internal } }; } // namespace Local +#endif TableEntry TableEntry::get_default_constructed_copy() const { TableEntry new_entry = *this; +#ifndef DEAL_II_HAVE_CXX17 boost::apply_visitor(Local::GetDefaultValue(), new_entry.value); +#else + // Let std::visit figure out which data type is actually stored, + // and then set the object so stored to a default-constructed + // one. + std::visit([](auto &arg) { arg = decltype(arg)(); }, new_entry.value); +#endif return new_entry; }