I'm trying to return everything except the last element in an std::tuple, if there are only two elements in the tuple, return the first one. Since std::tuple has a lot of compile-time facilities the dual-return type should be do-able. Here's what I have so far:
// Behavior
// init(std::make_tuple(1,2)) = 1
// init(std::make_tuple(1,2,3)) = (1,2)
// First case
template<class T1, class T2>
inline static T1 init(Tuple<T1, T2> t) {
return std::get<0>(t);
}
// Second case
template<class ...Args, class S = std::make_index_sequence<sizeof...(Args) - 1>>
inline static decltype(auto) init(Tuple<Args...> t) {
return std::apply([](const auto &item...) {
return std::tuple_cat(std::make_tuple(std::get<S>) ... std::tuple<>);
}, t);
}
It would be great if I could do this in a c++17 friendly way. I'm getting the following error with the above implementation:
./tuple.cpp:36:55: error: pack expansion does not contain any unexpanded parameter packs
return std::tuple_cat(std::make_tuple(std::get) ... std::tuple<>);~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
1 error generated.