Public Types | Public Attributes

OpenTissue::utility::TagSupportedType< T > Struct Template Reference

#include <utility_tag_traits.h>

Inheritance diagram for OpenTissue::utility::TagSupportedType< T >:
NodeTraits< math_types > TetrahedronTraits

List of all members.

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.

Detailed Description

template<typename T>
struct OpenTissue::utility::TagSupportedType< T >

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; }


Member Typedef Documentation

template<typename T>
typedef void OpenTissue::utility::TagSupportedType< T >::has_tag

Dummy typedef, required for SFINAE.

template<typename T>
typedef T OpenTissue::utility::TagSupportedType< T >::tag_type

The type of the tag value.


Member Data Documentation

The tag value.


The documentation for this struct was generated from the following file: