]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #ifndef BOOST_DESCRIBE_ENUM_FROM_STRING_HPP_INCLUDED |
2 | #define BOOST_DESCRIBE_ENUM_FROM_STRING_HPP_INCLUDED | |
3 | ||
4 | // Copyright 2020, 2021 Peter Dimov | |
5 | // Distributed under the Boost Software License, Version 1.0. | |
6 | // https://www.boost.org/LICENSE_1_0.txt | |
7 | ||
8 | #include <boost/describe/detail/config.hpp> | |
9 | ||
10 | #if defined(BOOST_DESCRIBE_CXX14) | |
11 | ||
12 | #include <boost/describe/enumerators.hpp> | |
13 | #include <boost/mp11/algorithm.hpp> | |
14 | #include <cstring> | |
15 | ||
16 | namespace boost | |
17 | { | |
18 | namespace describe | |
19 | { | |
20 | ||
21 | template<class E, class De = describe_enumerators<E>> | |
22 | bool enum_from_string( char const* name, E& e ) noexcept | |
23 | { | |
24 | bool found = false; | |
25 | ||
26 | mp11::mp_for_each<De>([&](auto D){ | |
27 | ||
28 | if( !found && std::strcmp( D.name, name ) == 0 ) | |
29 | { | |
30 | found = true; | |
31 | e = D.value; | |
32 | } | |
33 | ||
34 | }); | |
35 | ||
36 | return found; | |
37 | } | |
38 | ||
39 | } // namespace describe | |
40 | } // namespace boost | |
41 | ||
42 | #endif // defined(BOOST_DESCRIBE_CXX14) | |
43 | ||
44 | #endif // #ifndef BOOST_DESCRIBE_ENUM_FROM_STRING_HPP_INCLUDED |