underlying_type.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <boost/core/underlying_type.hpp>
  15. #include <boost/core/scoped_enum.hpp>
  16. #include <boost/core/lightweight_test_trait.hpp>
  17. #include <boost/core/is_same.hpp>
  18. #include <boost/config.hpp>
  19. BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(emulated_enum, unsigned char)
  20. {
  21. value0,
  22. value1,
  23. value2
  24. }
  25. BOOST_SCOPED_ENUM_DECLARE_END(emulated_enum)
  26. #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  27. enum class native_enum : unsigned short
  28. {
  29. value0,
  30. value1,
  31. value2
  32. };
  33. #endif
  34. #if defined(BOOST_NO_UNDERLYING_TYPE)
  35. namespace boost {
  36. template< >
  37. struct underlying_type< emulated_enum >
  38. {
  39. typedef unsigned char type;
  40. };
  41. #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  42. template< >
  43. struct underlying_type< native_enum >
  44. {
  45. typedef unsigned short type;
  46. };
  47. #endif
  48. } // namespace boost
  49. #endif
  50. int main(int, char*[])
  51. {
  52. BOOST_TEST_TRAIT_TRUE((boost::core::is_same< boost::underlying_type< emulated_enum >::type, unsigned char >));
  53. #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
  54. BOOST_TEST_TRAIT_TRUE((boost::core::is_same< boost::underlying_type< native_enum >::type, unsigned short >));
  55. #endif
  56. return boost::report_errors();
  57. }