is_byte_container.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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* = 0);
  15. static char check(...);
  16. static T* get();
  17. static constexpr bool value = sizeof(check(get())) == sizeof(double);
  18. };
  19. template <class C, bool b>
  20. struct is_byte_container_imp
  21. {
  22. // Note: Don't use C::value_type as this is a rather widespread typedef, even for non-range types
  23. using container_value_type = typename std::remove_cv<typename std::iterator_traits<typename C::const_iterator>::value_type>::type;
  24. static constexpr const bool value = boost::multiprecision::detail::is_integral<container_value_type>::value && (sizeof(container_value_type) == 1);
  25. };
  26. template <class C>
  27. struct is_byte_container_imp<C, false> : public boost::false_type
  28. {};
  29. template <class C>
  30. struct is_byte_container : public is_byte_container_imp<C, has_member_const_iterator<C>::value>
  31. {};
  32. }}} // namespace boost::multiprecision::detail
  33. #endif // BOOST_IS_BYTE_CONTAINER_HPP