is_byte_container.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2015 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_IS_BYTE_CONTAINER_HPP
  6. #define BOOST_IS_BYTE_CONTAINER_HPP
  7. #include <iterator>
  8. #include <type_traits>
  9. namespace boost { namespace multiprecision { namespace detail {
  10. template <class T>
  11. struct has_member_const_iterator
  12. {
  13. template <class U>
  14. static double check(U*, typename U::const_iterator* = nullptr);
  15. static char check(...);
  16. static T* get();
  17. static constexpr bool value = sizeof(check(get())) == sizeof(double);
  18. };
  19. template <class C, class Iterator>
  20. struct is_byte_container_imp_2
  21. {
  22. using container_value_type = typename std::remove_cv<typename std::iterator_traits<typename C::const_iterator>::value_type>::type;
  23. static constexpr bool value = boost::multiprecision::detail::is_integral<container_value_type>::value && (sizeof(container_value_type) == 1);
  24. };
  25. template <class C>
  26. struct is_byte_container_imp_2<C, void> : public std::false_type
  27. {};
  28. template <class C, bool b>
  29. struct is_byte_container_imp : public is_byte_container_imp_2<C, typename C::const_iterator>
  30. {
  31. };
  32. template <class C>
  33. struct is_byte_container_imp<C, false> : public std::false_type
  34. {};
  35. template <class C>
  36. struct is_byte_container : public is_byte_container_imp<C, has_member_const_iterator<C>::value>
  37. {};
  38. }}} // namespace boost::multiprecision::detail
  39. #endif // BOOST_IS_BYTE_CONTAINER_HPP