1 /*
2  *             Copyright Andrey Semashev 2014.
3  * Distributed under the Boost Software License, Version 1.0.
4  *    (See accompanying file LICENSE_1_0.txt or copy at
5  *          http://www.boost.org/LICENSE_1_0.txt)
6  */
7 /*!
8  * \file   underlying_type.cpp
9  * \author Andrey Semashev
10  * \date   06.06.2014
11  *
12  * \brief  This test checks that underlying_type trait works.
13  */
14 
15 #include <boost/core/underlying_type.hpp>
16 #include <boost/core/scoped_enum.hpp>
17 #include <boost/core/lightweight_test_trait.hpp>
18 #include <boost/core/is_same.hpp>
19 #include <boost/config.hpp>
20 
BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(emulated_enum,unsigned char)21 BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(emulated_enum, unsigned char)
22 {
23     value0,
24     value1,
25     value2
26 }
27 BOOST_SCOPED_ENUM_DECLARE_END(emulated_enum)
28 
29 #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
30 
31 enum class native_enum : unsigned short
32 {
33     value0,
34     value1,
35     value2
36 };
37 
38 #endif
39 
40 #if defined(BOOST_NO_UNDERLYING_TYPE)
41 namespace boost {
42 
43 template< >
44 struct underlying_type< emulated_enum >
45 {
46     typedef unsigned char type;
47 };
48 
49 #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
50 template< >
51 struct underlying_type< native_enum >
52 {
53     typedef unsigned short type;
54 };
55 #endif
56 
57 } // namespace boost
58 #endif
59 
main(int,char * [])60 int main(int, char*[])
61 {
62     BOOST_TEST_TRAIT_TRUE((boost::core::is_same< boost::underlying_type< emulated_enum >::type, unsigned char >));
63 #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
64     BOOST_TEST_TRAIT_TRUE((boost::core::is_same< boost::underlying_type< native_enum >::type, unsigned short >));
65 #endif
66 
67     return boost::report_errors();
68 }
69