Public Member Functions |
| optional () OMG_NOEXCEPT |
| Create an unset optional object.
|
|
| optional (const T &value) |
| Create an optional object with a copy of a value.
|
|
| optional (T &&value) |
| <<C++11>> Create an optional object moving a value
|
|
| optional (bool condition, const T &value) |
| Create an optional member conditionally set or unset.
|
|
| optional (bool condition, T &&value) |
| <<C++11>> Creates an optional member conditionally set or unset by moving a value.
|
|
| ~optional () |
| Destroys the underlying object if it exists.
|
|
void | set (const T &value) |
| Assigns a copy of an object.
|
|
void | set (T &&value) |
| <<C++11>> Assigns an object by moving it
|
|
bool | is_set () const |
| Checks if this optional instance contains a valid object.
|
|
| operator bool () const |
| Returns is_set()
|
|
void | reset () |
| Destroys the underlying object and leaves this optional with an invalid (unset) value.
|
|
const T & | get () const |
| Retrieves the underlying object if it exists.
|
|
T & | get () |
| Retrieves the underlying object if it exists.
|
|
const T * | get_ptr () const |
| Returns &get() if the object is initialized or NULL otherwise.
|
|
T * | get_ptr () |
| Returns &get() if the object is initialized or NULL otherwise.
|
|
optional< T > & | operator= (const optional< T > &other) |
| Assignment operator.
|
|
optional< T > & | operator= (optional< T > &&other) OMG_NOEXCEPT |
| <<C++11>> Move-assignment operator
|
|
optional< T > & | operator= (const T &value) |
| Assign a (valid) value.
|
|
optional< T > & | operator= (T &&value) |
| Assign a (valid) value by moving an object.
|
|
Related Functions |
(Note that these are not member functions.)
|
template<typename T > |
bool | operator== (const optional< T > &a, const optional< T > &b) |
| Compares two optional values.
|
|
template<typename T > |
bool | operator!= (const optional< T > &a, const optional< T > &b) |
| Compares two optional values.
|
|
template<typename T > |
bool | operator== (const optional< T > &optional_value, const T &value) |
| Compares an optional member and a value of the underlying type.
|
|
template<typename T > |
bool | operator== (const T &value, const optional< T > &optional_value) |
| Compares an optional member and a value of the underlying type.
|
|
template<typename T > |
bool | operator!= (const optional< T > &optional_value, const T &value) |
| Compares an optional member and a value of the underlying type.
|
|
template<typename T > |
bool | operator!= (const T &value, const optional< T > &optional_value) |
| Compares an optional member and a value of the underlying type.
|
|
template<typename T > |
std::ostream & | operator<< (std::ostream &out, const optional< T > &optional) |
| Applies the operator<< to optional.get() or the string "NULL" if !optional.is_set()
|
|
template<typename T>
class dds::core::optional< T >
<<value-type>> Represents an object that may not contain a valid value
- Template Parameters
-
T | The type of the actual object this optional<T> wraps |
Members of an IDL type marked with the @Optional
tag map to this C++ type.
When an optional value has a valid value is_set() returns true and get() returns a reference to the actual object of type T. Otherwise is_set() returns false and get() throws dds::core::PreconditionNotMetError. To assing a value you can use the assignment operator or set().
An optional object has full value-type semantics; copying an optional value copies the underlying object if it exists.
This class is similar to boost::optional.
- See Also
- Working with IDL types