mp_with_index.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/algorithm.hpp>
  8. #include <boost/mp11/detail/config.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. #include <tuple>
  11. using boost::mp11::mp_size_t;
  12. using boost::mp11::mp_for_each;
  13. using boost::mp11::mp_with_index;
  14. using boost::mp11::mp_iota_c;
  15. struct F
  16. {
  17. std::size_t i_;
  18. explicit F( std::size_t i ): i_( i ) {}
  19. template<std::size_t I> bool operator()( mp_size_t<I> ) const
  20. {
  21. BOOST_TEST_EQ( I, i_ );
  22. return false;
  23. }
  24. };
  25. struct G
  26. {
  27. void operator()( mp_size_t<0> ) const
  28. {
  29. }
  30. template<std::size_t N> void operator()( mp_size_t<N> ) const
  31. {
  32. for( std::size_t i = 0; i < N; ++i )
  33. {
  34. mp_with_index<N>( i, F(i) );
  35. mp_with_index<mp_size_t<N>>( i, F(i) );
  36. }
  37. }
  38. };
  39. int main()
  40. {
  41. #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 )
  42. G()( mp_size_t<1>{} );
  43. G()( mp_size_t<2>{} );
  44. G()( mp_size_t<3>{} );
  45. G()( mp_size_t<4>{} );
  46. G()( mp_size_t<5>{} );
  47. G()( mp_size_t<6>{} );
  48. G()( mp_size_t<7>{} );
  49. G()( mp_size_t<8>{} );
  50. G()( mp_size_t<9>{} );
  51. G()( mp_size_t<10>{} );
  52. G()( mp_size_t<11>{} );
  53. G()( mp_size_t<12>{} );
  54. G()( mp_size_t<13>{} );
  55. G()( mp_size_t<14>{} );
  56. G()( mp_size_t<15>{} );
  57. G()( mp_size_t<16>{} );
  58. G()( mp_size_t<32+1>{} );
  59. G()( mp_size_t<48+2>{} );
  60. G()( mp_size_t<64+3>{} );
  61. G()( mp_size_t<96+4>{} );
  62. G()( mp_size_t<112+5>{} );
  63. G()( mp_size_t<128+6>{} );
  64. #else
  65. mp_for_each<mp_iota_c<134>>( G() );
  66. #endif
  67. return boost::report_errors();
  68. }