I’m currently writing a template that operates differently based on the category of the input.
There are 3 cases I’m looking to add to my traits class.
A. The type has a typedef
type_category, use that.B. The type doesn’t have the typedef, use the type
regular_tag(most common case)C. My specializations,
std::list<T>uses the typespecial_tagfor anyT.
How would I manage this? It’s simple to do either A. and C. or B. and C. but I’m not sure how to get all 3.
EDIT
A example might make it easier to understand.
class Foo
{
typedef foo_tag type_category;
}
class Bar;
my_traits<Foo>::type(); // makes a foo_tag
my_traits<Bar>::type(); // makes a regular_tag
my_traits<std::list<Baz>>::type(); // makes a special_tag because I want special list proce
ssing.
The scaffolding could look like this:
We need the helper:
Now all we need is a type-trait to check for a member typedef:
Usage: