NCBI C++ ToolKit
Public Member Functions | Private Attributes | List of all members
CNullable< TValue, TNullToValue > Class Template Reference

Search Toolkit Book for CNullable

Template class allowing to store a value or null (unassigned) state. More...

#include <corelib/ncbimisc.hpp>

+ Inheritance diagram for CNullable< TValue, TNullToValue >:

Public Member Functions

 CNullable (ENull=null)
 Create an empty nullable. More...
 
 CNullable (TValue value)
 Initialize nullable with a specific value. More...
 
bool IsNull (void) const
 Check if the object is unassigned. More...
 
 operator TValue (void) const
 Get nullable value. More...
 
const TValue & GetValue (void) const
 Get a const reference to the current value. More...
 
TValue & SetValue (void)
 Get a non-const reference to the value. More...
 
CNullableoperator= (TValue value)
 Assign a value to the nullable. More...
 
CNullableoperator= (ENull)
 Reset nullable to unassigned state. More...
 

Private Attributes

bool m_IsNull
 
TValue m_Value
 

Detailed Description

template<class TValue, class TNullToValue = SThrowOnNull<TValue>>
class CNullable< TValue, TNullToValue >

Template class allowing to store a value or null (unassigned) state.

TNullToValue functor can be used to perform an action when the value is requested from a null object. By default CCoreException is thrown. To perform other actions (e.g. provide a default value) the functor must define 'TValue operator()(void) const' method.

Deprecated:
: Use std::optional<> instead.
Examples
/home/coremake/doxygen/cxx/include/corelib/ncbimisc.hpp.

Definition at line 672 of file ncbimisc.hpp.


The documentation for this class was generated from the following file:
Modified on Wed Apr 17 13:10:45 2024 by modify_doxy.py rev. 669887