For educational purposes (while reading book Modern C++ Design - A Alexandrescu) I want to write some helper to delete all types in parameter pack before type T.
For example delete_until_T<C,A,B,C,D>
must be opened like tuple<C,D>
or just <C,D>
.
As I understand it may be done in old enough recursive way and non recursive way with C++17.
In this piece of code i wanna do it in non recursive way using std::conditional
.
//https://stackoverflow.com/a/23863962/12575933 - based on this answer
#include <tuple>
#include <type_traits>
template<typename...Ts>
using tuple_cat_t = decltype(std::tuple_cat(std::declval<Ts>()...));
template<class T, class ... Ts>
using delete_untill_T = tuple_cat_t
<
typename std::conditional
<
std::is_same_v<T,Ts>||bool_func<>,
std::tuple<Ts>,
std::tuple<>
>::type...
> ;
The first question is how to make a variable or function or struct which value can be changed during this parameter pack opening and used in std::conditional
? I want to make bool_func<>
which returns false before std::is_same
returns true while opening, and after that returns false.
If it's possible, my second question is how to remove tuple and pass just parameters in parameter pack to template function.
Or may be there is another way to delete types before T? (recursive algorithm will do). Or with C++ 20 features?