In the following code, I split a variadic template in two typeList's, the definition of typeList and putLeft are not important.
template<typename ...SL>
struct split {
static const size_t size = sizeof...(SL);
typedef typename putLeft<typeList<>,size/2, typeList<SL...>>::result firstHalf;
typedef typename putLeft<typeList<>,size/2, typeList<SL...>>::rest secondHalf;
};
what I want to know is when I use putLeft<typeList<>,size/2, typeList<SL...>>::result and putLeft<typeList<>,size/2, typeList<SL...>>::rest later, does the compiler manage the duplicate struct that is putLeft<typeList<>,size/2, typeList<SL...>>::result, or does it compute the struct again ?
Yes, the compiler will only instantiate
putLeft<typeList<>,size/2, typeList<SL...>>once, at the point where you need theresulttype name.However, it would probably be worth taking an alias to that so that you don't typo it on the second line:
It won't have any effect on what actually happens, but readers of your code will thank you.