From 37a5fbec48e5b14ed397fd2f8817bd5012ecb171 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 5 Mar 2022 23:07:35 -0700 Subject: [PATCH] Convert uses of boost::variant to std_cxx17::variant. --- include/deal.II/base/table_handler.h | 14 +++++++------- source/base/table_handler.cc | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) 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; } -- 2.39.5