Victor said:
'cant_write_me' here cannot be used because it's not a specialisation of
the original template. The name has to be unique or it has to be some
V
I know
I've tried a large number of approaches that use specializations. I've
gotten very creative. I think that there simply is no way to write
cant_write_me.
I ran across it because I was trying to write a facility to use like this:
template_arity_of< class-template-identifier >::value
I did in fact manage to solve that problem, but the solution is pretty
unloveable. I have to write
template_arity_of
<
MACRO( class-template-identifier )
that solution looks like:
#include <ostream>
#include <cstddef>
typedef char no;
struct yes{ no value[2]; };
template< template< typename > class >
yes test_1();
template< template< typename, typename > class >
no test_1();
template< template< typename > class >
no test_2();
template< template< typename, typename > class >
yes test_2();
template< size_t, size_t >
struct template_arity_of;
template< >
struct template_arity_of< sizeof( yes ), sizeof( no ) >
{
static const size_t value = 1;
};
template< >
struct template_arity_of< sizeof( no ), sizeof( yes ) >
{
static const size_t value = 2;
};
#define MACRO( template_class_id ) \
sizeof( test_1< template_class_id >() ),\
sizeof( test_2< template_class_id >() )
template< typename > struct arity_one;
template< typename, typename > struct arity_two;
int
main()
{
using namespace std;
cout << template_arity_of< MACRO( arity_one ) >::value << endl;
cout << template_arity_of< MACRO( arity_two ) >::value << endl;
}
There're two really vile problems with this solution.
First, if N is the largest arity that I test for, implementing this
solution requires 2*N*N + N bits of syntax.
Second, there's the macro. It's there for three reasons. First, a
straight use requires N bits of syntax. Second, those bits of syntax are
very likely to contain a bug. Third, it's pretty obvious that N will
grow and it would be bad to have to rewrite all the uses.
I'm looking into another variation of the sizeof trick (sometimes used
for a restricted typeof) which would let me implement a less hateful
kludge, but I'd much rather learn that there's some way to write
"cant_write_me" after all.