| 1 | // Copyright 2020 Peter Dimov |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/endian/detail/is_scoped_enum.hpp> |
| 6 | #include <boost/core/lightweight_test_trait.hpp> |
| 7 | #include <boost/config.hpp> |
| 8 | |
| 9 | enum E1 {}; |
| 10 | |
| 11 | #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) |
| 12 | |
| 13 | enum E2: long {}; |
| 14 | enum class E3 {}; |
| 15 | enum class E4: long {}; |
| 16 | |
| 17 | #endif |
| 18 | |
| 19 | struct X |
| 20 | { |
| 21 | operator int() const { return 0; } |
| 22 | }; |
| 23 | |
| 24 | struct Y; |
| 25 | |
| 26 | template<class T> void test_true() |
| 27 | { |
| 28 | using boost::endian::detail::is_scoped_enum; |
| 29 | |
| 30 | BOOST_TEST_TRAIT_TRUE((is_scoped_enum<T>)); |
| 31 | BOOST_TEST_TRAIT_TRUE((is_scoped_enum<T const>)); |
| 32 | BOOST_TEST_TRAIT_TRUE((is_scoped_enum<T volatile>)); |
| 33 | BOOST_TEST_TRAIT_TRUE((is_scoped_enum<T const volatile>)); |
| 34 | } |
| 35 | |
| 36 | template<class T> void test_false() |
| 37 | { |
| 38 | using boost::endian::detail::is_scoped_enum; |
| 39 | |
| 40 | BOOST_TEST_TRAIT_FALSE((is_scoped_enum<T>)); |
| 41 | BOOST_TEST_TRAIT_FALSE((is_scoped_enum<T const>)); |
| 42 | BOOST_TEST_TRAIT_FALSE((is_scoped_enum<T volatile>)); |
| 43 | BOOST_TEST_TRAIT_FALSE((is_scoped_enum<T const volatile>)); |
| 44 | } |
| 45 | |
| 46 | template<class T> void test_false_() |
| 47 | { |
| 48 | using boost::endian::detail::is_scoped_enum; |
| 49 | |
| 50 | BOOST_TEST_NOT((is_scoped_enum<T>::value)); |
| 51 | BOOST_TEST_NOT((is_scoped_enum<T const>::value)); |
| 52 | BOOST_TEST_NOT((is_scoped_enum<T volatile>::value)); |
| 53 | BOOST_TEST_NOT((is_scoped_enum<T const volatile>::value)); |
| 54 | } |
| 55 | |
| 56 | int main() |
| 57 | { |
| 58 | test_false<int>(); |
| 59 | test_false<bool>(); |
| 60 | test_false<X>(); |
| 61 | test_false_<Y>(); |
| 62 | test_false<void>(); |
| 63 | test_false<int[]>(); |
| 64 | test_false<int[1]>(); |
| 65 | |
| 66 | test_false<E1>(); |
| 67 | |
| 68 | #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) |
| 69 | |
| 70 | test_false<E2>(); |
| 71 | |
| 72 | test_true<E3>(); |
| 73 | test_true<E4>(); |
| 74 | |
| 75 | #endif |
| 76 | |
| 77 | return boost::report_errors(); |
| 78 | } |
| 79 |
