tuple_for_each_cx.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2015 Peter Dimov.
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. //
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. #if defined(_MSC_VER)
  8. #pragma warning( disable: 4244 ) // 'initializing': conversion from 'int' to 'char', possible loss of data
  9. #endif
  10. #include <boost/mp11/tuple.hpp>
  11. #include <boost/mp11/detail/config.hpp>
  12. // Technically std::tuple isn't constexpr enabled in C++11, but it works with libstdc++
  13. #if defined( BOOST_MP11_NO_CONSTEXPR ) || ( !defined( __GLIBCXX__ ) && __cplusplus < 201400L )
  14. int main() {}
  15. #else
  16. #include <tuple>
  17. #include <type_traits>
  18. struct assert_is_integral
  19. {
  20. template<class T> constexpr bool operator()( T ) const
  21. {
  22. static_assert( std::is_integral<T>::value, "T must be an integral type" );
  23. return true;
  24. }
  25. };
  26. int main()
  27. {
  28. {
  29. constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
  30. constexpr auto r = boost::mp11::tuple_for_each( tp, assert_is_integral() );
  31. (void)r;
  32. }
  33. #if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 9
  34. // "error: default initialization of an object of const type 'const std::tuple<>' without a user-provided default constructor"
  35. #else
  36. {
  37. constexpr std::tuple<> tp;
  38. constexpr auto r = boost::mp11::tuple_for_each( tp, 11 );
  39. static_assert( r == 11, "r == 11" );
  40. }
  41. #endif
  42. }
  43. #endif