mp_with_index_cx.cpp 759 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 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. #include <boost/mp11/detail/config.hpp>
  8. #if !defined( BOOST_MP11_HAS_CXX14_CONSTEXPR )
  9. int main() {}
  10. #else
  11. #include <boost/mp11/algorithm.hpp>
  12. #include <boost/core/lightweight_test.hpp>
  13. using boost::mp11::mp_size_t;
  14. using boost::mp11::mp_with_index;
  15. struct F
  16. {
  17. template<std::size_t I> constexpr std::size_t operator()( mp_size_t<I> ) const
  18. {
  19. return I;
  20. }
  21. };
  22. #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
  23. int main()
  24. {
  25. constexpr std::size_t i = mp_with_index<64>( 57, F{} );
  26. STATIC_ASSERT( i == 57 );
  27. }
  28. #endif