diff --git a/include/boost/endian/detail/is_scoped_enum.hpp b/include/boost/endian/detail/is_scoped_enum.hpp new file mode 100644 index 0000000..8109980 --- /dev/null +++ b/include/boost/endian/detail/is_scoped_enum.hpp @@ -0,0 +1,35 @@ +#ifndef BOOST_ENDIAN_DETAIL_IS_SCOPED_ENUM_HPP_INCLUDED +#define BOOST_ENDIAN_DETAIL_IS_SCOPED_ENUM_HPP_INCLUDED + +// Copyright 2020 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +namespace boost +{ +namespace endian +{ +namespace detail +{ + +template struct negation: boost::integral_constant {}; + +template struct is_scoped_enum: + boost::conditional< + boost::is_enum::value, + negation>, + boost::false_type + >::type +{ +}; + +} // namespace detail +} // namespace endian +} // namespace boost + +#endif // BOOST_ENDIAN_DETAIL_IS_SCOPED_ENUM_HPP_INCLUDED diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6771114..fd71770 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -96,3 +96,5 @@ run-ni endian_hpp_test.cpp ; run order_test.cpp ; run endian_reverse_test2.cpp ; + +run is_scoped_enum_test.cpp ; diff --git a/test/is_scoped_enum_test.cpp b/test/is_scoped_enum_test.cpp new file mode 100644 index 0000000..e7a70a2 --- /dev/null +++ b/test/is_scoped_enum_test.cpp @@ -0,0 +1,68 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +enum E1 {}; + +#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) + +enum E2: long {}; +enum class E3 {}; +enum class E4: long {}; + +#endif + +struct X +{ + operator int() const { return 0; } +}; + +struct Y; + +template void test_true() +{ + using boost::endian::detail::is_scoped_enum; + + BOOST_TEST_TRAIT_TRUE((is_scoped_enum)); + BOOST_TEST_TRAIT_TRUE((is_scoped_enum)); + BOOST_TEST_TRAIT_TRUE((is_scoped_enum)); + BOOST_TEST_TRAIT_TRUE((is_scoped_enum)); +} + +template void test_false() +{ + using boost::endian::detail::is_scoped_enum; + + BOOST_TEST_TRAIT_FALSE((is_scoped_enum)); + BOOST_TEST_TRAIT_FALSE((is_scoped_enum)); + BOOST_TEST_TRAIT_FALSE((is_scoped_enum)); + BOOST_TEST_TRAIT_FALSE((is_scoped_enum)); +} + +int main() +{ + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + + test_false(); + +#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) + + test_false(); + + test_true(); + test_true(); + +#endif + + return boost::report_errors(); +}