1#ifndef BOOST_DESCRIBE_ENUM_TO_STRING_HPP_INCLUDED
2#define BOOST_DESCRIBE_ENUM_TO_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
15#if defined(_MSC_VER) && _MSC_VER == 1900
16# pragma warning(push)
17# pragma warning(disable: 4100) // unreferenced formal parameter
18#endif
19
20namespace boost
21{
22namespace describe
23{
24
25template<class E, class De = describe_enumerators<E>>
26char const * enum_to_string( E e, char const* def ) noexcept
27{
28 char const * r = def;
29
30 mp11::mp_for_each<De>([&](auto D){
31
32 if( e == D.value ) r = D.name;
33
34 });
35
36 return r;
37}
38
39} // namespace describe
40} // namespace boost
41
42#if defined(_MSC_VER) && _MSC_VER == 1900
43# pragma warning(pop)
44#endif
45
46#endif // defined(BOOST_DESCRIBE_CXX14)
47
48#endif // #ifndef BOOST_DESCRIBE_ENUM_TO_STRING_HPP_INCLUDED
49

source code of boost/libs/describe/include/boost/describe/enum_to_string.hpp