/* Copyright (C) 2016 Murray Cumming
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see .
*/
#ifndef SIGC_TUPLE_UTILS_TUPLE_START_H
#define SIGC_TUPLE_UTILS_TUPLE_START_H
#include
#include
namespace sigc::internal
{
namespace detail
{
template
struct tuple_type_start_impl;
template
struct tuple_type_start_impl>
{
using type = std::tuple::type...>;
};
} // detail namespace
/**
* Get the type of a tuple with just the first @len items.
*/
template
struct tuple_type_start : detail::tuple_type_start_impl>
{
};
namespace detail
{
template
struct tuple_start_impl;
template
struct tuple_start_impl>
{
static constexpr decltype(auto) tuple_start(T&& t)
{
constexpr auto size = std::tuple_size>::value;
constexpr auto len = sizeof...(I);
static_assert(len <= size, "The tuple size must be greater than or equal to the length.");
using start = typename tuple_type_start, len>::type;
return start(std::get(std::forward(t))...);
}
};
} // detail namespace
/**
* Get the tuple with the last @a len items of the original.
*/
template
constexpr decltype(auto) // typename tuple_type_end::type
tuple_start(T&& t)
{
// We use std::decay_t<> because tuple_size is not defined for references.
constexpr auto size = std::tuple_size>::value;
static_assert(len <= size, "The tuple size must be greater than or equal to the length.");
return detail::tuple_start_impl>::tuple_start(
std::forward(t));
}
} // namespace sigc::internal;
#endif // SIGC_TUPLE_UTILS_TUPLE_START_H