• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #ifndef BOOST_HISTOGRAM_DETAIL_TUPLE_SLICE_HPP
8 #define BOOST_HISTOGRAM_DETAIL_TUPLE_SLICE_HPP
9 
10 #include <boost/mp11/integer_sequence.hpp>
11 #include <tuple>
12 #include <type_traits>
13 
14 namespace boost {
15 namespace histogram {
16 namespace detail {
17 
18 template <std::size_t I, class T, std::size_t... K>
tuple_slice_impl(T && t,mp11::index_sequence<K...>)19 decltype(auto) tuple_slice_impl(T&& t, mp11::index_sequence<K...>) {
20   return std::forward_as_tuple(std::get<(I + K)>(std::forward<T>(t))...);
21 }
22 
23 template <std::size_t I, std::size_t N, class Tuple>
tuple_slice(Tuple && t)24 decltype(auto) tuple_slice(Tuple&& t) {
25   constexpr auto S = std::tuple_size<std::decay_t<Tuple>>::value;
26   static_assert(I + N <= S, "I, N must be a valid subset");
27   return tuple_slice_impl<I>(std::forward<Tuple>(t), mp11::make_index_sequence<N>{});
28 }
29 
30 } // namespace detail
31 } // namespace histogram
32 } // namespace boost
33 
34 #endif
35