Skip to content

Instantly share code, notes, and snippets.

@picanumber
Last active November 27, 2016 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picanumber/852be541e540981ebf400bc2e8816fbc to your computer and use it in GitHub Desktop.
Save picanumber/852be541e540981ebf400bc2e8816fbc to your computer and use it in GitHub Desktop.
namespace detail
{
template <std::size_t Ofst, class Tuple, std::size_t... I>
constexpr auto slice_impl(Tuple&& t, std::index_sequence<I...>)
{
return std::forward_as_tuple(
std::get<I + Ofst>(std::forward<Tuple>(t))...);
}
}
template <std::size_t I1, std::size_t I2, class Cont>
constexpr auto tuple_slice(Cont&& t)
{
static_assert(I2 >= I1, "invalid slice");
static_assert(std::tuple_size<std::decay_t<Cont>>::value >= I2,
"slice index out of bounds");
return detail::slice_impl<I1>(std::forward<Cont>(t),
std::make_index_sequence<I2 - I1>{});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment