Classes | Typedefs | Functions | Variables

Traits for types with a tag. More...

Classes

struct  util::TaggedType< T, Tag >
 A type with a specified tag. More...
 
struct  util::add_tag< T, Tag >
 
struct  util::remove_tag< Tagged >
 Trait holding the type contained in a TaggedType (or the type itself). More...
 
struct  util::remove_tag< TaggedType< T, Tag > >
 
struct  util::TagN<... >
 Tag class parametrized by a sequence of numbers. More...
 
struct  util::TagExtractor< Tagged >
 Extracts the tag from a type. More...
 

Typedefs

template<typename T , typename Tag >
using util::add_tag_t = typename add_tag< T, Tag >::type
 
template<typename Tagged >
using util::remove_tag_t = typename remove_tag< Tagged >::type
 Direct access to the type contained in remove_tag. More...
 
template<typename Tagged >
using util::tag_of = TagExtractor< Tagged >
 Trait holding the tag of Tagged as type. More...
 
template<typename Tagged >
using util::tag_of_t = typename tag_of< Tagged >::type
 Direct access to the type in tag_of. More...
 
template<typename SrcTuple >
using util::extract_tags = extract_to_tuple_type< SrcTuple, TagExtractor >
 Returns a tuple with all the tags from SrcTuple. More...
 
template<typename SrcTuple >
using util::extract_tags_t = typename extract_tags< SrcTuple >::type
 Direct access to the type in extract_tags. More...
 
template<typename Tag , typename Tuple >
using util::index_of_tag = index_of_extracted_type< TagExtractor, Tag, Tuple >
 Trait holding the index of the element of Tuple with tag Tag. More...
 
template<typename Tag , typename Tuple >
using util::type_with_tag = type_with_extracted_type< TagExtractor, Tag, Tuple >
 Trait holding the type of the element of Tuple with tag Tag. More...
 
template<typename Tag , typename Tuple >
using util::type_with_tag_t = typename type_with_tag< Tag, Tuple >::type
 Direct access to the value in type_with_tag. More...
 
template<typename Tag , typename Tuple >
using util::has_tag = has_extracted_type< TagExtractor, Tag, Tuple >
 Trait informing if there are elements in Tuple with tag Tag. More...
 
template<typename Tag , typename Tuple >
using util::count_tags = count_extracted_types< TagExtractor, Tag, Tuple >
 Trait counting the elements in Tuple with tag Tag. More...
 
template<typename Tuple >
using util::has_duplicate_tags = has_duplicate_extracted_types< TagExtractor, Tuple >
 Trait reporting if multiple elements in Tuple have the same tag. More...
 

Functions

template<typename Tag , typename T >
auto util::makeTagged (T &obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tag , typename T >
auto util::makeTagged (T const &obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tag , typename T >
auto util::makeTagged (T const &&obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tag , typename T >
auto util::makeTagged (T &&obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tagged >
auto util::removeTag (Tagged &tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tagged >
auto util::removeTag (Tagged const &tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tagged >
auto util::removeTag (Tagged const &&tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tagged >
auto util::removeTag (Tagged &&tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tag , typename Tuple >
auto util::getByTag (Tuple const &data) -> decltype(auto)
 Returns the object with the specified tag. More...
 

Variables

template<typename Tag , typename Tuple >
constexpr std::size_t util::index_of_tag_v = index_of_tag<Tag, Tuple>()
 Direct access to the value in index_of_tag. More...
 
template<typename Tag , typename Tuple >
constexpr bool util::has_tag_v = has_tag<Tag, Tuple>()
 Direct access to the value in has_tag. More...
 
template<typename Tag , typename Tuple >
constexpr unsigned int util::count_tags_v = count_tags<Tag, Tuple>()
 Direct access to the value in count_tags. More...
 
template<typename Tuple >
constexpr bool util::has_duplicate_tags_v = has_duplicate_tags<Tuple>()
 Direct access to the value in has_duplicate_tags. More...
 

Detailed Description

Traits for types with a tag.

Tag-related traits operate on "tagged" types. A tagged type is a type which contains a tag type definition, and that type is the tag type.

In the examples, the types used are defined as:

struct TagA {};
struct TagB {};
struct TagC {};
struct TagD {};
using DoubleTaggedB = util::add_tag_t<std::vector<double>, TagB>;
using StringTaggedC = util::add_tag_t<std::string, TagC>;
using ComplexTaggedA = util::add_tag_t<std::complex<float>, TagA>;
using Tuple_t = std::tuple<IntTaggedA, DoubleTaggedB, StringTaggedC>;
using DuplTuple_t = std::tuple<IntTaggedA, DoubleTaggedB, ComplexTaggedA>;

Note that DuplTuple_t has two elements with the same tag (TagA).

Note
All the traits and function here will generate a compilation error if any of the elements is not tagged.

Typedef Documentation

template<typename T , typename Tag >
using util::add_tag_t = typedef typename add_tag<T, Tag>::type

Direct access to the type contained in add_tag.

See also
TaggedType

Definition at line 617 of file TupleLookupByTag.h.

template<typename Tag , typename Tuple >
using util::count_tags = typedef count_extracted_types<TagExtractor, Tag, Tuple>

Trait counting the elements in Tuple with tag Tag.

Template Parameters
Tagthe sought tag
Tuplethe tuple-like type holding the elements to check
See also
index_of_tag, count_tags_v, has_duplicate_tags, has_tag

Given a tuple-like type Tuple, this traits returns the number of element types tagged with Tag.

For example (see above for the definitions):

constexpr unsigned int nTagA = util::count_tags<TagA, Tuple_t >();
constexpr unsigned int nTagB = util::count_tags<TagB, Tuple_t >();
constexpr unsigned int nTagC = util::count_tags<TagC, Tuple_t >();
constexpr unsigned int nTagD = util::count_tags<TagD, Tuple_t >();
constexpr unsigned int nTagAdupl = util::count_tags<TagA, DuplTuple_t>();
constexpr unsigned int nTagBdupl = util::count_tags<TagB, DuplTuple_t>();
constexpr unsigned int nTagCdupl = util::count_tags<TagC, DuplTuple_t>();
constexpr unsigned int nTagDdupl = util::count_tags<TagD, DuplTuple_t>();

nTagA, nTagB and nTagC, will be 1 and nTagD will be 0. Likewise, nTagAdupl will be 1, nTagBdupl will be 2, while nTagCdupl and nTagDdupl will be 0.

Definition at line 885 of file TupleLookupByTag.h.

template<typename SrcTuple >
using util::extract_tags = typedef extract_to_tuple_type<SrcTuple, TagExtractor>

Returns a tuple with all the tags from SrcTuple.

Definition at line 744 of file TupleLookupByTag.h.

template<typename SrcTuple >
using util::extract_tags_t = typedef typename extract_tags<SrcTuple>::type

Direct access to the type in extract_tags.

Definition at line 748 of file TupleLookupByTag.h.

template<typename Tuple >
using util::has_duplicate_tags = typedef has_duplicate_extracted_types<TagExtractor, Tuple>

Trait reporting if multiple elements in Tuple have the same tag.

Template Parameters
Tuplethe tuple-like type holding the elements to check
See also
index_of_tag, count_tags, has_duplicate_tags_v, has_tag

Given a tuple-like type Tuple, this traits returns whether any of the tags in the elements appears more than once.

For example (see above for the definitions):

constexpr bool hasDuplTags = util::has_duplicate_tags<Tuple_t >();
constexpr bool hasDuplTagsDupl = util::has_duplicate_tags<DuplTuple_t>();

hasDuplTags, will be false and hasDuplTagsDupl will be true.

Definition at line 908 of file TupleLookupByTag.h.

template<typename Tag , typename Tuple >
using util::has_tag = typedef has_extracted_type<TagExtractor, Tag, Tuple>

Trait informing if there are elements in Tuple with tag Tag.

Template Parameters
Tagthe sought tag
Tuplethe tuple-like type holding the elements to check
See also
index_of_tag, count_tags, has_duplicate_tags, has_tag_v

Given a tuple-like type Tuple, this traits returns whether there is at least one element type tagged with Tag.

For example (see above for the definitions):

constexpr bool hasTagA = util::index_of_tag<TagA, Tuple_t >();
constexpr bool hasTagB = util::index_of_tag<TagB, Tuple_t >();
constexpr bool hasTagC = util::index_of_tag<TagC, Tuple_t >();
constexpr bool hasTagD = util::index_of_tag<TagD, Tuple_t >();
constexpr bool hasTagAdupl = util::index_of_tag<TagA, DuplTuple_t>();
constexpr bool hasTagBdupl = util::index_of_tag<TagB, DuplTuple_t>();
constexpr bool hasTagCdupl = util::index_of_tag<TagC, DuplTuple_t>();
constexpr bool hasTagDdupl = util::index_of_tag<TagD, DuplTuple_t>();

hasTagA, hasTagB and hasTagC, will be true and hasTagD will be false. Likewise, hasTagAdupl and hasTagBdupl will be true, while hasTagCdupl and hasTagDdupl will be false.

Definition at line 853 of file TupleLookupByTag.h.

template<typename Tag , typename Tuple >
using util::index_of_tag = typedef index_of_extracted_type<TagExtractor, Tag, Tuple>

Trait holding the index of the element of Tuple with tag Tag.

Template Parameters
Tagthe sought tag
Tuplethe tuple-like type holding the elements to check
See also
index_of_tag_v, count_tags, has_duplicate_tags, has_tag

Given a tuple-like type Tuple, this traits returns the index of the one element type tagged with Tag. If the target type is not present, or if it is present more than once, a compilation error will ensue.

For example (see above for the definitions):

constexpr std::size_t TagAindex = util::index_of_tag<TagA, Tuple_t>();
constexpr std::size_t TagBindex = util::index_of_tag<TagB, Tuple_t>();
constexpr std::size_t TagBduplIndex

TagAindex will hold value 0, pointing to the container in Tuple_t of type IntTaggedA, while TagBindex will be 1 and TagBduplIndex will be also 1. Instead, the expression util::index_of_tag<TagD, Tuple_t>() would not compile because no element in Tuple_t is tagged with TagD, and the expression util::index_of_tag<TagA, DuplTuple_t>() would not compile because two elements of DuplTuple_t are tagged TagA.

Note
Currently there is no equivalent trait to ask for the index of the second or following type, allowing for duplicate tags; this can be implemented on request.

Definition at line 782 of file TupleLookupByTag.h.

template<typename Tagged >
using util::remove_tag_t = typedef typename remove_tag<Tagged>::type

Direct access to the type contained in remove_tag.

Definition at line 630 of file TupleLookupByTag.h.

template<typename Tagged >
using util::tag_of = typedef TagExtractor<Tagged>

Trait holding the tag of Tagged as type.

Definition at line 735 of file TupleLookupByTag.h.

template<typename Tagged >
using util::tag_of_t = typedef typename tag_of<Tagged>::type

Direct access to the type in tag_of.

Definition at line 739 of file TupleLookupByTag.h.

template<typename Tag , typename Tuple >
using util::type_with_tag = typedef type_with_extracted_type<TagExtractor, Tag, Tuple>

Trait holding the type of the element of Tuple with tag Tag.

Template Parameters
Tagthe sought tag
Tuplethe tuple-like type holding the elements to check
See also
type_with_tag_t, index_of_tag, count_tags, has_duplicate_tags, has_tag

Given a tuple-like type Tuple, this traits returns the one element type tagged with Tag. If the target type is not present, or if it is present more than once, a compilation error will ensue.

For example (see above for the definitions):

TagA_t will be IntTaggedA, the type in Tuple_t with TagA, while TagB_t will be DoubleTaggedB and TagBdupl_t will be also DoubleTaggedB. Instead, the type util::type_with_tag<TagD, Tuple_t> would not compile because no element in Tuple_t is tagged with TagD, and the type util::type_with_tag<TagA, DuplTuple_t>() would not compile because two elements of DuplTuple_t are tagged TagA.

Note
Currently there is no equivalent trait to ask for the second or following type, allowing for duplicate tags; this can be implemented on request.

Definition at line 820 of file TupleLookupByTag.h.

template<typename Tag , typename Tuple >
using util::type_with_tag_t = typedef typename type_with_tag<Tag, Tuple>::type

Direct access to the value in type_with_tag.

Definition at line 825 of file TupleLookupByTag.h.

Function Documentation

template<typename Tag , typename Tuple >
auto util::getByTag ( Tuple const &  data) -> decltype(auto)

Returns the object with the specified tag.

Template Parameters
Tagthe sought tag
Tuplethe tuple-like type holding the data
See also
index_of_tag, count_tags, has_duplicate_tags, has_tag

This function operates in a fashion similar to std::get(), where instead of specifying the index or type of the object to retrieve, the tag is specified.

For example (see above for the definitions):

Tuple_t data(
{ 0, 1, 2 }, // std::vector<int> assigned to TagA
{ 0.5, 1.5 }, // std::vector<double> assigned to TagB
"middle point" // std::string assigned to TagC
);
decltype(auto) TagBdata = util::getByTag<TagB>(data);

TagBdata will be a reference to a std::vector<double> in data, currently with values { 0.5, 1.5 }". The attempt to useutil::getByTag()on an argument with duplicate tags (likeDuplTuple_t`) will ensue a compilation error.

Definition at line 940 of file TupleLookupByTag.h.

941  { return getByExtractedType<TagExtractor, Tag>(data); }
template<typename Tag , typename T >
auto util::makeTagged ( T &  obj) -> decltype(auto)

"Converts" obj to an object with tag Tag.

Template Parameters
Tagtag to be added to the object
Ttype of the object to be tagged (implicitly deduced)
Parameters
obj(l-value) reference to the object to be tagged
Returns
a reference to obj, reinterpreted as tagged
See also
TaggedType, add_tag

The returned object is the same as obj, reinterpreted as a different type derived from T and tagged with Tag.

Definition at line 645 of file TupleLookupByTag.h.

646  { return static_cast<add_tag_t<T, Tag>&>(obj); }
template<typename Tag , typename T >
auto util::makeTagged ( T const &  obj) -> decltype(auto)

"Converts" obj to an object with tag Tag.

Template Parameters
Tagtag to be added to the object
Ttype of the object to be tagged (implicitly deduced)
Parameters
obj(l-value) constant reference to the object to be tagged
Returns
a reference to obj, reinterpreted as tagged
See also
TaggedType, add_tag

The returned object is the same as obj, reinterpreted as a different type derived from T and tagged with Tag.

Definition at line 660 of file TupleLookupByTag.h.

661  { return static_cast<add_tag_t<T const, Tag> const&>(obj); }
template<typename Tag , typename T >
auto util::makeTagged ( T const &&  obj) -> decltype(auto)

"Converts" obj to an object with tag Tag.

Template Parameters
Tagtag to be added to the object
Ttype of the object to be tagged (implicitly deduced)
Parameters
obj(r-value) reference to the object to be tagged
Returns
a reference to obj, reinterpreted as tagged
See also
TaggedType, add_tag

The returned object is an object of a new type, derived from T , with data copied from obj, and tagged with Tag. The argument object may be a temporary.

Definition at line 676 of file TupleLookupByTag.h.

677  { return add_tag_t<T, Tag>(obj); /* copy, since it's constant */ }
template<typename Tag , typename T >
auto util::makeTagged ( T &&  obj) -> decltype(auto)

"Converts" obj to an object with tag Tag.

Template Parameters
Tagtag to be added to the object
Ttype of the object to be tagged (implicitly deduced)
Parameters
objthe object to be tagged
Returns
a reference to obj, reinterpreted as tagged
See also
TaggedType, add_tag

The returned object is the same as obj, reinterpreted as a different type derived from T and tagged with Tag. The returned object is a temporary of the new type, whose content is moved (std::move()) from the argument object obj.

Definition at line 693 of file TupleLookupByTag.h.

694  { return add_tag_t<T, Tag>(std::move(obj)); }
def move(depos, offset)
Definition: depos.py:107
template<typename Tagged >
auto util::removeTag ( Tagged &  tagged) -> decltype(auto)

"Converts" a tagged type back to its original type.

Definition at line 698 of file TupleLookupByTag.h.

699  { return static_cast<remove_tag_t<Tagged>&>(tagged); }
template<typename Tagged >
auto util::removeTag ( Tagged const &  tagged) -> decltype(auto)

"Converts" a tagged type back to its original type.

Definition at line 703 of file TupleLookupByTag.h.

704  { return static_cast<remove_tag_t<Tagged> const&>(tagged); }
template<typename Tagged >
auto util::removeTag ( Tagged const &&  tagged) -> decltype(auto)

"Converts" a tagged type back to its original type.

Definition at line 708 of file TupleLookupByTag.h.

709  { return static_cast<remove_tag_t<Tagged> const&&>(tagged); }
template<typename Tagged >
auto util::removeTag ( Tagged &&  tagged) -> decltype(auto)

"Converts" a tagged type back to its original type.

Definition at line 713 of file TupleLookupByTag.h.

714  { return static_cast<remove_tag_t<Tagged>&&>(tagged); }

Variable Documentation

template<typename Tag , typename Tuple >
constexpr unsigned int util::count_tags_v = count_tags<Tag, Tuple>()

Direct access to the value in count_tags.

Definition at line 889 of file TupleLookupByTag.h.

template<typename Tuple >
constexpr bool util::has_duplicate_tags_v = has_duplicate_tags<Tuple>()

Direct access to the value in has_duplicate_tags.

Definition at line 912 of file TupleLookupByTag.h.

template<typename Tag , typename Tuple >
constexpr bool util::has_tag_v = has_tag<Tag, Tuple>()

Direct access to the value in has_tag.

Definition at line 857 of file TupleLookupByTag.h.

template<typename Tag , typename Tuple >
constexpr std::size_t util::index_of_tag_v = index_of_tag<Tag, Tuple>()

Direct access to the value in index_of_tag.

Definition at line 787 of file TupleLookupByTag.h.