It was added after 9.6.0. It is not there on spack yet.
You don’t really need to recompile the library. You need one include file (magic_enum.hpp from
https://github.com/Neargye/magic_enum) in your include path, and to copy this to one of your headers:
#include <magic_enum.hpp>
namespace dealii {
namespace Patterns {
namespace Tools {
template <class T>
struct Convert<T, typename std::enable_if<std::is_enum<T>::value>::type>
{
static std::unique_ptr<Patterns::PatternBase>
to_pattern()
{
const auto n = magic_enum::enum_names<T>();
std::vector<std::string> names = {n.begin(), n.end()};
const auto selection =
Patterns::Tools::Convert<decltype(names)>::to_string(
names,
Patterns::List(
Patterns::Anything(), names.size(), names.size(), "|"));
// Allow parsing a list of enums, and make bitwise or between them
return Patterns::List(Patterns::Selection(selection),
0,
names.size(),
"|")
.clone();
}
static std::string
to_string(const T &value,
const Patterns::PatternBase &p = *Convert<T>::to_pattern())
{
const auto values = magic_enum::enum_values<T>();
std::vector<std::string> names;
for (const auto &v : values)
if (magic_enum::bitwise_operators::operator&(value, v) == v)
names.push_back(std::string(magic_enum::enum_name(v)));
return Patterns::Tools::Convert<decltype(names)>::to_string(names, p);
}
static T
to_value(const std::string &s,
const dealii::Patterns::PatternBase &p = *to_pattern())
{
// Make sure we have a valid enum value, or empty value
AssertThrow(p.match(s), ExcNoMatch(s, p.description()));
T value = T();
std::vector<std::string> value_names;
value_names =
Patterns::Tools::Convert<decltype(value_names)>::to_value(s, p);
for (const auto &name : value_names)
{
auto v = magic_enum::enum_cast<T>(name);
if (v.has_value())
value =
magic_enum::bitwise_operators::operator|(value, v.value());
}
return value;
}
};
> To view this discussion visit
https://groups.google.com/d/msgid/dealii/1fd93eda-8535-4709-bc8d-fafcf97ef1b5n%40googlegroups.com.