A class template that represents a type-safe union.
More...
|
Global types, methods and objects that are somehow related
|
template<typename Alternative , typename... Alternatives> |
Alternative * | OFget (OFvariant< Alternatives... > *v) |
| Try to get a pointer to the given alternative from an OFvariant object. More...
|
|
template<typename Alternative , typename... Alternatives> |
const Alternative * | OFget (const OFvariant< Alternatives... > *v) |
| Try to get a pointer to the given alternative from an OFvariant object. More...
|
|
template<typename Result , typename Visitor , typename... Alternatives> |
Result | OFvisit (Visitor visitor, OFvariant< Alternatives... > &v) |
| Applies the given visitor to the given OFvariant object. More...
|
|
template<typename Result , typename Visitor , typename... Alternatives> |
Result | OFvisit (Visitor visitor, const OFvariant< Alternatives... > &v) |
| Applies the given visitor to the given OFvariant object. More...
|
|
template<typename... Alternatives>
class OFvariant< Alternatives >
A class template that represents a type-safe union.
#include "dcmtk/ofstd/ofvriant.h" for using this class
- Template Parameters
-
Alternatives | a set of types that may be stored in this variant. All types must be (possibly cv-qualified) object types. OFvariant is a custom implementation of a subset of C++17's std::variant, see http://en.cppreference.com/w/cpp/utility/variant for a description of std::variant. An instance of OFvariant at any given time holds a value of one of its alternative types. As with unions, if a variant holds a value of some object type T, the object representation of T is allocated directly within the object representation of the variant itself if possible. |
- Note
- If no suitable alignment specifiers were available for the target platform, OFvariant will use a fallback implementation that stores the alternative on the heap – as opposite to std::variant. The preferred way to access an OFvariant object is visitation utilizing OFvisit. If a certain alternative is expected to be held by the variant, OFget may be used to access it directly.
- See also
- OFvisit – Apply a visitor to an OFvariant object.
-
OFget – Get a pointer to the value stored in an OFvariant holding the selected alternative.
-
OFmonostate – A helper type for making OFvariant default constructible.
-
OFin_place –
Tools for in-place construction of objects, e.g. certain OFvariant alternatives.
◆ OFvariant() [1/4]
template<typename... Alternatives>
Constructs a variant holding a default constructed value of the first alternative.
- Precondition
- The first alternative must be default constructible.
- See also
- OFmonostate – A helper type for making OFvariant default constructible.
◆ OFvariant() [2/4]
template<typename... Alternatives>
Copy constructs a variant holding a copy of the value rhs holds.
- Parameters
-
rhs | a const reference to another object of equal type. |
- Precondition
- All alternatives must be copy constructible.
◆ OFvariant() [3/4]
template<typename... Alternatives>
Move constructs a variant by moving the value rhs holds.
- Parameters
-
rhs | an rvalue reference to another object of equal type. |
- Precondition
- All alternatives must be move constructible.
◆ OFvariant() [4/4]
template<typename... Alternatives>
template<typename T >
Constructs a variant holding the alternative that most closely matches the given argument.
- Template Parameters
-
T | the type of the argument, will be deduced automatically. |
- Parameters
-
t | an object of type T that will be converted to one of the alternatives. @precondition There must be at least one alternative that can be constructed from the given parameter t and there must be exactly one such alternative that takes precedence over the others. |
- Attention
- t will be perfectly forwarded if C++11 support is available, i.e. the alternative may be move constructed from
t
if possible. Support for perfect forwarding is NOT available without C++11 support, therefore the alternative will be copy constructed in this case, this means: the selected alternative must be copy constructible if pre C++11 compilers shall be supported. Usage Example:
◆ index()
template<typename... Alternatives>
size_t OFvariant< Alternatives >::index |
( |
| ) |
const |
Get the index of alternative that is currently being held.
- Returns
- the zero based index of that alternative that is currently being held by
*this
, i.e. 0
for the first alternative, 1
for the second, etc.
◆ operator=() [1/3]
template<typename... Alternatives>
Copy assigns the value rhs holds to *this.
- Parameters
-
rhs | a const reference to another object of equal type. |
- Precondition
- all alternatives must be copy constructible and copy assignable.
- Returns
*this
- Postcondition
- if
*this
and rhs
hold the same alternative, the value contained in rhs
is copy assigned to the value contained in *this
.
- if
*this
and rhs
hold different alternatives, the value contained in *this
is destroyed and a new one is copy constructed from the value contained in rhs
.
◆ operator=() [2/3]
template<typename... Alternatives>
Move assigns the value rhs holds to *this.
- Parameters
-
rhs | an rvalue reference to another object of equal type. |
- Precondition
- all alternatives must be move constructible and move assignable.
- Returns
*this
- Postcondition
- if
*this
and rhs
hold the same alternative, the value contained in rhs
is move assigned to the value contained in *this
.
- if
*this
and rhs
hold different alternatives, the value contained in *this
is destroyed and a new one is move constructed from the value contained in rhs
.
◆ operator=() [3/3]
template<typename... Alternatives>
template<typename T >
Converts the given argument to one of the alternatives and assigns it to *this.
- Template Parameters
-
T | the type of the argument, will be deduced automatically. |
- Parameters
-
t | an object of type T that will be converted to one of the alternatives for assignment. |
- Returns
*this
- Precondition
- There must be at least one alternative that can be constructed from the given parameter
t
and there must be exactly one such alternative that takes precedence over the others.
- Attention
t
will be perfectly forwarded if C++11 support is available, i.e. the alternative may be move constructed from t if possible. Support for perfect forwarding is NOT available without C++11 support, therefore the alternative will be copy constructed in this case, this means: the selected alternative must be copy constructible if pre C++11 compilers shall be supported. Usage Example:
v1 = 3
v2 = 3
v3 = "abc";
The documentation for this class was generated from the following file: