Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:35:26

0001 #ifndef BOOST_DESCRIBE_ENUM_FROM_STRING_HPP_INCLUDED
0002 #define BOOST_DESCRIBE_ENUM_FROM_STRING_HPP_INCLUDED
0003 
0004 // Copyright 2020, 2021 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt
0007 
0008 #include <boost/describe/detail/config.hpp>
0009 
0010 #if defined(BOOST_DESCRIBE_CXX14)
0011 
0012 #include <boost/describe/enumerators.hpp>
0013 #include <boost/mp11/algorithm.hpp>
0014 #include <cstring>
0015 #include <type_traits>
0016 
0017 #if defined(_MSC_VER) && _MSC_VER == 1900
0018 # pragma warning(push)
0019 # pragma warning(disable: 4100) // unreferenced formal parameter
0020 #endif
0021 
0022 namespace boost
0023 {
0024 namespace describe
0025 {
0026 
0027 template<class E, class De = describe_enumerators<E>>
0028 bool enum_from_string( char const* name, E& e ) noexcept
0029 {
0030     bool found = false;
0031 
0032     mp11::mp_for_each<De>([&](auto D){
0033 
0034         if( !found && std::strcmp( D.name, name ) == 0 )
0035         {
0036             found = true;
0037             e = D.value;
0038         }
0039 
0040     });
0041 
0042     return found;
0043 }
0044 
0045 template<class S, class E, class De = describe_enumerators<E>,
0046     class En = std::enable_if_t<
0047         std::is_same<typename S::value_type, char>::value &&
0048         std::is_same<typename S::traits_type::char_type, char>::value
0049     >
0050 >
0051 bool enum_from_string( S const& name, E& e ) noexcept
0052 {
0053     bool found = false;
0054 
0055     mp11::mp_for_each<De>([&](auto D){
0056 
0057         if( !found && name == D.name )
0058         {
0059             found = true;
0060             e = D.value;
0061         }
0062 
0063     });
0064 
0065     return found;
0066 }
0067 
0068 } // namespace describe
0069 } // namespace boost
0070 
0071 #if defined(_MSC_VER) && _MSC_VER == 1900
0072 # pragma warning(pop)
0073 #endif
0074 
0075 #endif // defined(BOOST_DESCRIBE_CXX14)
0076 
0077 #endif // #ifndef BOOST_DESCRIBE_ENUM_FROM_STRING_HPP_INCLUDED