From f7eaa277d717c65d2688b6db05c1b3201e3bd15a Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Mon, 12 Aug 2024 15:25:57 -0600 Subject: [PATCH] Custom enums. --- tests/parameter_handler/pattern_tools_15.cc | 56 +++++++++++++++++++ ...ttern_tools_15.with_magic_enum=true.output | 5 ++ 2 files changed, 61 insertions(+) create mode 100644 tests/parameter_handler/pattern_tools_15.cc create mode 100644 tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output diff --git a/tests/parameter_handler/pattern_tools_15.cc b/tests/parameter_handler/pattern_tools_15.cc new file mode 100644 index 0000000000..9c77ba559e --- /dev/null +++ b/tests/parameter_handler/pattern_tools_15.cc @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2010 - 2022 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + +// Check Patterns::Tools::Convert for custom enum types + +#include + +#include + +#include "../tests.h" + +enum TestFlag +{ + red = 1, + green = 2, + blue = 4 +}; + +enum class TestFlagClass +{ + yellow = 1, + orange = 2, + white = 4 +}; + +template +using C = Patterns::Tools::Convert; + +int +main() +{ + initlog(); + { + TestFlag flags = red; + deallog << C::to_string(flags) << std::endl; + flags = C::to_value("green|blue"); + deallog << C::to_string(flags) << std::endl; + } + { + TestFlagClass flags = TestFlagClass::yellow; + deallog << C::to_string(flags) << std::endl; + flags = C::to_value("orange|white"); + deallog << C::to_string(flags) << std::endl; + } +} diff --git a/tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output b/tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output new file mode 100644 index 0000000000..5b15e1097c --- /dev/null +++ b/tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output @@ -0,0 +1,5 @@ + +DEAL::red +DEAL::green| blue +DEAL::yellow +DEAL::orange| white -- 2.39.5