index_sequence.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // (C) Copyright Gennadiy Rozental 2001.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. /// @file
  8. /// Defines c++14 index_sequence implementation
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_DATA_INDEX_SEQUENCE_HPP
  11. #define BOOST_TEST_DATA_INDEX_SEQUENCE_HPP
  12. // Boost.Test
  13. #include <boost/test/data/config.hpp>
  14. #include <boost/test/detail/suppress_warnings.hpp>
  15. //____________________________________________________________________________//
  16. namespace boost {
  17. namespace unit_test {
  18. namespace data {
  19. // ************************************************************************** //
  20. // ************** data::index_sequence ************** //
  21. // ************************************************************************** //
  22. template <std::size_t... Ns>
  23. struct index_sequence {};
  24. template<typename IS1, typename IS2>
  25. struct merge_index_sequence;
  26. template <std::size_t... Ns1, std::size_t... Ns2>
  27. struct merge_index_sequence<index_sequence<Ns1...>, index_sequence<Ns2...>> {
  28. typedef index_sequence<Ns1..., Ns2...> type;
  29. };
  30. template <std::size_t B, std::size_t E, typename Enabler = void>
  31. struct make_index_sequence {
  32. typedef typename merge_index_sequence<typename make_index_sequence<B,(B+E)/2>::type,
  33. typename make_index_sequence<(B+E)/2,E>::type>::type type;
  34. };
  35. template <std::size_t B, std::size_t E>
  36. struct make_index_sequence<B,E,typename std::enable_if<E==B+1,void>::type> {
  37. typedef index_sequence<B> type;
  38. };
  39. template <>
  40. struct make_index_sequence<0, 0> {
  41. typedef index_sequence<> type;
  42. };
  43. template <typename... T>
  44. using index_sequence_for = typename make_index_sequence<0, sizeof...(T)>::type;
  45. } // namespace data
  46. } // namespace unit_test
  47. } // namespace boost
  48. #include <boost/test/detail/enable_warnings.hpp>
  49. #endif // BOOST_TEST_DATA_INDEX_SEQUENCE_HPP