tuple_slice.hpp 1019 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2015-2019 Hans Dembinski
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_HISTOGRAM_DETAIL_TUPLE_SLICE_HPP
  7. #define BOOST_HISTOGRAM_DETAIL_TUPLE_SLICE_HPP
  8. #include <boost/mp11/integer_sequence.hpp>
  9. #include <tuple>
  10. #include <type_traits>
  11. namespace boost {
  12. namespace histogram {
  13. namespace detail {
  14. template <std::size_t I, class T, std::size_t... K>
  15. decltype(auto) tuple_slice_impl(T&& t, mp11::index_sequence<K...>) {
  16. return std::forward_as_tuple(std::get<(I + K)>(std::forward<T>(t))...);
  17. }
  18. template <std::size_t I, std::size_t N, class Tuple>
  19. decltype(auto) tuple_slice(Tuple&& t) {
  20. constexpr auto S = std::tuple_size<std::decay_t<Tuple>>::value;
  21. static_assert(I + N <= S, "I, N must be a valid subset");
  22. return tuple_slice_impl<I>(std::forward<Tuple>(t), mp11::make_index_sequence<N>{});
  23. }
  24. } // namespace detail
  25. } // namespace histogram
  26. } // namespace boost
  27. #endif