Upon calling std::contional<bool, T1, T2> both the types T1 and T2 get instantiated as soon as its called, irrespective of the value of the bool, does there exist an implementation (or some pointers to implement it) where only the relevant type is instantiated.
Following code for example is impossible to write using std::conditional. We can't even use SFINAE over structs (get in the example).
struct Term {};
template <int N, typename T, typename ...Ts>
struct PairList
{
static constexpr int i = N;
using type = T;
using tail = PairList<N + 1, Ts...>;
};
template <int N, typename T>
struct PairList<N, T>
{
static constexpr int i = N;
using type = T;
using tail = Term;
};
template <int N, typename pairList>
struct get
{
static constexpr auto good = (N == pairList::i);
using T = typename std::conditional<
good,
typename pairList::type,
typename get<N, typename pairList::tail>::T>::type; // The second parameter might not be defined
};