is_supported_char.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // Copyright (c) 2022-2023 Alexander Grund
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_LOCALE_DETAIL_IS_SUPPORTED_CHAR_HPP_INCLUDED
  7. #define BOOST_LOCALE_DETAIL_IS_SUPPORTED_CHAR_HPP_INCLUDED
  8. #include <boost/locale/config.hpp>
  9. #include <type_traits>
  10. /// \cond INTERNAL
  11. namespace boost { namespace locale { namespace detail {
  12. /// Trait, returns true iff the argument is a supported character type
  13. template<typename Char>
  14. struct is_supported_char : std::false_type {};
  15. template<>
  16. struct is_supported_char<char> : std::true_type {};
  17. template<>
  18. struct is_supported_char<wchar_t> : std::true_type {};
  19. #ifdef __cpp_char8_t
  20. template<>
  21. struct is_supported_char<char8_t> : std::true_type {};
  22. #endif
  23. #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
  24. template<>
  25. struct is_supported_char<char16_t> : std::true_type {};
  26. #endif
  27. #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
  28. template<>
  29. struct is_supported_char<char32_t> : std::true_type {};
  30. #endif
  31. template<typename Char>
  32. using enable_if_is_supported_char = typename std::enable_if<is_supported_char<Char>::value>::type;
  33. }}} // namespace boost::locale::detail
  34. #define BOOST_LOCALE_ASSERT_IS_SUPPORTED(Char) \
  35. static_assert(boost::locale::detail::is_supported_char<Char>::value, "Unsupported Char type")
  36. /// \endcond
  37. #endif