mardi 30 août 2016

Can a template template be specialized for fundamental types like regular templates?

I have written the following code to infix a templated class:

template<template<typename...> class C, typename A, typename B>
struct infix_t { typedef C<A,B> type; }
template<template<typename...> class C, class A>
constexpr infix_t<C,A> operator<(A, infix_t<C>) { return {}; }
template<template<typename...> class C, typename A, typename B>
constexpr C<A,B> operator>(infix_t<C,A>, B) { return {}; }

This allows me to write a <same_as> b where same_as has type infix_t<std::is_same>. However, if the type of A or B is a fundamental type, I get template template argument has different template parameters...; if I try to redeclare infix_t to accept fundamental types, I get template argument ... must be a class template or alias template. I thought that templates over typenames could accept fundamentals anyway. Is this because it's a template template, and the rules are different, or am I just approaching this wrong?

Aucun commentaire:

Enregistrer un commentaire