1 /* Copyright (C) 2016 Murray Cumming
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/
17 #ifndef SIGC_TUPLE_UTILS_TUPLE_END_H
18 #define SIGC_TUPLE_UTILS_TUPLE_END_H
20 #include <sigc++/tuple-utils/tuple_cdr.h>
28 template <typename T, std::size_t remove_from_start>
29 struct tuple_end_impl {
32 decltype(auto) // typename tuple_type_end<T, size - remove_from_start>::type
34 static_assert(remove_from_start > 0, "remove_from_start must be more than zero.");
36 using cdr = typename tuple_type_cdr<std::decay_t<T>>::type;
37 return tuple_end_impl<cdr, remove_from_start - 1>::tuple_end(
38 tuple_cdr(std::forward<T>(t)));
43 struct tuple_end_impl<T, 1> {
48 return tuple_cdr(std::forward<T>(t));
53 struct tuple_end_impl<T, 0> {
58 return std::forward<T>(t);
65 * Get the tuple with the last @a len items of the original.
67 template <std::size_t len, typename T>
69 decltype(auto) // typename tuple_type_end<T, len>::type
71 //We use std::decay_t<> because tuple_size is not defined for references.
72 constexpr auto size = std::tuple_size<std::decay_t<T>>::value;
73 static_assert(len <= size, "The tuple size must be less than or equal to the length.");
74 constexpr auto size_start = size - len;
75 return detail::tuple_end_impl<T, size_start>::tuple_end(std::forward<T>(t));
78 } // namespace internal
82 #endif //SIGC_TUPLE_UTILS_TUPLE_END_H