I was working with a templated class which takes a set of integers. The code was like,
template<unsigned... Idx>
struct work{ ... };
Then I realized, user may need to provide either a set of integers, or a range of integers. So, I changed the syntax little to support instantiation like,
work<indexes<1,3,2,4> > //instead of work<1,3,2,4>
work<span<1,4> > //same as work<1,2,3,4>
While, in C++ we have large number of operators, and can be used to formulate exotic expression templates (say boost::xpressive
, boost::lambda
, boost::spirit
etc) , possibilities for type manipulation is much less.
In a boostcon keynote by Sean Parent, he noted one still can not write pair<int>
to denote a pair of integers
. In my persinal library, I made a syntax like tuple<int[3]>
to denote a tuple of 3 integers, instead of writing a tuple with 3 int in the type arguments, noting that I do not write a raw array as tuple argument anywhere! (note: std::array<int,3>
is not same as the above, as std::array can not store references while tuple
can, say std::tuple<int&,int&,int&>
is possible)
So, I want to know what are the different kind of "type expressions" I can write?
So far I can think of object type, function type, reference type, with/without cv modifiers, pointers etc. e.g
template<class T>
struct tpl;
using t1 = tpl<int>;//simple type
//function (can have function pointer/reference also)
// e.g. void(*)(int,float) or void(&)(int,float)
using t2 = tpl<void(int,float)>;
//array can have pointer / reference also
//e.g. int(&)[4] or int (*)[4]
using t3 = tpl<int[4]>;
using t4 = tpl<int[]>;
using t5 = tpl<int const>;//with cv modifiers
using t6 = tpl<int*>;//with pointer
using t7 = tpl<int&>;//with reference (& or &&)
using t8 = tpl<tpl<int> >; //template itself
using t9 = tpl<void(...)>; //variadic functions
using t10 = tpl<R C::*>; //pointer to member
But I believe, many more are possible.
NOTE: This question is purely theoretical, I just want to know all kinds of syntax I can write inside <> as type argument, and not about the readability/morality aspect of it, or even how can I implement some of the examples I had given, like the work class.