DCMTK
Version 3.6.2
OFFIS DICOM Toolkit
|
A class template that represents a type-safe union. More...
Public Member Functions | |
OFvariant () | |
Constructs a variant holding a default constructed value of the first alternative. More... | |
OFvariant (const OFvariant &rhs) | |
Copy constructs a variant holding a copy of the value rhs holds. More... | |
OFvariant (OFvariant &&rhs) | |
Move constructs a variant by moving the value rhs holds. More... | |
template<typename T > | |
OFvariant (T t) | |
Constructs a variant holding the alternative that most closely matches the given argument. More... | |
~OFvariant () | |
Destroys the value that the variant currently holds. | |
OFvariant & | operator= (const OFvariant &rhs) |
Copy assigns the value rhs holds to *this. More... | |
OFvariant & | operator= (OFvariant &&rhs) |
Move assigns the value rhs holds to *this. More... | |
template<typename T > | |
OFvariant & | operator= (T t) |
Converts the given argument to one of the alternatives and assigns it to *this. More... | |
size_t | index () const |
Get the index of alternative that is currently being held. More... | |
Related Definitions | |
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... | |
A class template that represents a type-safe union.
#include "dcmtk/ofstd/ofvriant.h" for using this class
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.
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.
Constructs a variant holding a default constructed value of the first alternative.
OFvariant< Alternatives >::OFvariant | ( | const OFvariant< Alternatives > & | rhs | ) |
Copy constructs a variant holding a copy of the value rhs holds.
rhs | a const reference to another object of equal type. |
OFvariant< Alternatives >::OFvariant | ( | OFvariant< Alternatives > && | rhs | ) |
Move constructs a variant by moving the value rhs holds.
rhs | an rvalue reference to another object of equal type. |
OFvariant< Alternatives >::OFvariant | ( | T | t | ) |
Constructs a variant holding the alternative that most closely matches the given argument.
T | the type of the argument, will be deduced automatically. |
t | an object of type T that will be converted to one of the alternatives. 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. |
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.size_t OFvariant< Alternatives >::index | ( | ) | const |
Get the index of alternative that is currently being held.
*this
, i.e. 0
for the first alternative, 1
for the second, etc. OFvariant& OFvariant< Alternatives >::operator= | ( | const OFvariant< Alternatives > & | rhs | ) |
Copy assigns the value rhs holds to *this.
rhs | a const reference to another object of equal type. |
*this
*this
and rhs
hold the same alternative, the value contained in rhs
is copy assigned to the value contained in *this
. *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
. OFvariant& OFvariant< Alternatives >::operator= | ( | OFvariant< Alternatives > && | rhs | ) |
Move assigns the value rhs holds to *this.
rhs | an rvalue reference to another object of equal type. |
*this
*this
and rhs
hold the same alternative, the value contained in rhs
is move assigned to the value contained in *this
. *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
. OFvariant& OFvariant< Alternatives >::operator= | ( | T | t | ) |
Converts the given argument to one of the alternatives and assigns it to *this.
T | the type of the argument, will be deduced automatically. |
t | an object of type T that will be converted to one of the alternatives for assignment. |
*this
t
and there must be exactly one such alternative that takes precedence over the others. 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.