#include <utility_tag_traits.h>
Public Types | |
typedef void | has_tag |
Dummy typedef, required for SFINAE. | |
typedef T | tag_type |
The type of the tag value. | |
Public Attributes | |
tag_type | m_tag |
The tag value. |
Tagging mechanism using SFINAE (substitution-failure-is-not-an-error) principle.
Example of two classes, one without tags, other with tag member. Note that to provide support for the tag, one needs to add the typedef *and* the m_tag member variable. Optimized compilers should not generate code for if(has_tag(T)) conditionals where T doesn't support tags.
struct bar {}; struct foo { typedef void has_tag; int m_tag; foo() : m_tag(23) {} }; struct blah : public TagSupportedType<int> {};
int main() { bar a; foo b;
std::cout << "bar has tag: " << has_tag(a) << std::endl; std::cout << "foo has tag: " << has_tag(b) << std::endl;
if (has_tag(a)) return 1;
always 0 std::cout << "bar's tag value is " << tag_value(a) << std::endl;
if (tag_value(b)) return 1; std::cout << "foo's tag value is " << tag_value(b) << std::endl;
return 0; }
typedef void OpenTissue::utility::TagSupportedType< T >::has_tag |
Dummy typedef, required for SFINAE.
typedef T OpenTissue::utility::TagSupportedType< T >::tag_type |
The type of the tag value.
tag_type OpenTissue::utility::TagSupportedType< T >::m_tag |
The tag value.