Template aliases are very convenient in simplifying types like typename F <T>::type
to just F <T>
, where T
and type
are types.
I would like to do the same for templates like F <T>::map
, i.e., simplify them to F <T>
, where T
and map
are template structs or aliases.
For instance, consider the following definitions:
template <bool B>
using expr = std::integral_constant <bool, B>;
template <bool B>
using _not = expr <!B>;
template <template <typename> class F>
struct neg_f
{
template <typename T>
using map = _not <F <T>{}>;
};
template <typename T>
pred = expr < /* ... T ... */ >; // e.g., pred = expr <true>;
template <template <typename> class F>
struct fun;
Now the following works:
fun <neg_f <pred>::map>
This would be much more convenient, but it fails:
template <template <typename> class F>
using neg = neg_f <F>::map;
fun <neg <pred> >
(It also fails with neg = neg_f <F>::template map
, even if map
is defined as a struct). It appears that the definition of neg
above would rather have to be like a "template template alias"
template <template <typename> class F>
template <typename T>
using neg = neg_f <F>::template map <T>;
but apparently there is no such thing.
So, is there any solution or should I stay with neg_f <pred>::map
?
<
makes everything extremely unpleasant to read, for some reasons. – Danulofftemplate<template<typename> class F>
extremely unpleasant;template< template< typename > class F >
as well. It's pretty standard using space before parentheses, e.g.if (x < 0)
, so spaces before<
look natural to me. – Christiansandneg_f
is supposed to negate a type predicate, that is,neg_f<F>::map
is another type predicate that, when applied to a typeT
, gives the complement of whateverF<T>
gives. I didn't explain because its definition is so simple and because it's just a example, it's not essential to the problem (I could equally use afoo
-like example). – Christiansand_not <F <T>{}>
:F
is a type predicate, i.e.F<T>
isstd::integral_constant<bool,B>
for someB
as shown by the definitions. Meaning thatF<T>{}
is an object of literal type that is implicitly converted tobool
, in turn used as non-type template parameter for_not
. I hope this helps. – Christiansand