BloombergLP::bdlb::NullableValue

This template class extends the set of values of its value-semantic TYPE parameter to include the notion of a "null" value. If TYPE is fully value-semantic, then the augmented type NullableValue<TYPE> will be as well. In addition to supporting all homogeneous value-semantic operations, conversions between comparable underlying value types is also supported. Two nullable objects with different underlying types compare equal if their underlying types are comparable and either (1) both objects are null or (2) the non-null values compare equal. A null nullable object is considered ordered before any non-null nullable object. Attempts to copy construct, copy assign, or compare incompatible values types will fail to compile. The NullableValue template cannot be instantiated on an incomplete type, a type that overloads unary operator&, or bsl::nullopt_t.

Synopsis

Declared in <bdlb_nullablevalue.h>

template<class TYPE>
class NullableValue
    : public bsl::optional<TYPE>

Base Classes

NameDescription
bsl::optional<TYPE>

Type Aliases

NameDescription
Base Base class of this type.
ValueType ValueType is an alias for the underlying TYPE upon which this template class is instantiated, and represents the type of the managed object.
allocator_type The type of allocator used by this object. If TYPE is not allocator aware, allocator_type is a private non-allocator type that effectively removes the allocator-specific constructors from consideration during overload resolution.
value_type value_type is an alias for the underlying TYPE upon which this template class is instantiated, and represents the type of the managed object. The name is chosen so it is compatible with the std::optional implementation.

Member Functions

NameDescription
NullableValue [constructor]Constructors
operator= Assignment operators
addressOr Return an address providing non-modifiable access to the underlying object of a (template parameter) TYPE if this object is non-null, and the specified address otherwise.
and_then and_then overloads
bdexStreamIn Assign to this object the value read from the specified input stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, this object is unaltered and stream is invalidated, but otherwise unmodified. If version is supported but stream becomes invalid during this operation, this object has an undefined, but valid, state. Note that no version is read from stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
bdexStreamOut Write the value of this object, using the specified version format, to the specified output stream, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, stream is invalidated, but otherwise unmodified. Note that version is not written to stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
emplace emplace overloads
get_allocator Return allocator used for construction of value_type.
has_value Return false if this object is disengaged, and true otherwise.
isNull Return true if this object is null, and false otherwise.
makeValue makeValue overloads
makeValueInplace Assign to this nullable object the value of the (template parameter) TYPE created in place using the specified args. Return a reference providing modifiable access to the created (value) object. The object is also accessible via the value method. If this nullable object already contains an object (false == isNull()), that object is destroyed before the new object is created. If TYPE has the trait bslma::UsesBslmaAllocator (TYPE is allocator-enabled) the allocator specified at the construction of this nullable object is used to supply memory to the value object. Attempts to explicitly specify via args another allocator to supply memory to the created (value) object are disallowed by the compiler. Note that if the constructor of TYPE throws an exception this object is left in the null state.
maxSupportedBdexVersion maxSupportedBdexVersion overloads
operator* Dereference operators
operator-> Member access operators
or_else or_else overloads
print Format this object to the specified output stream at the (absolute value of) the optionally specified indentation level and return a reference to stream. If level is specified, optionally specify spacesPerLevel, the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). If stream is not valid on entry, this operation has no effect.
reset Reset this object to the default constructed state (i.e., to a disengaged state).
swap Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee if the template parameter t_TYPE provides that guarantee and the result of the hasValue method for the two objects being swapped is the same. The behavior is undefined unless this object was created with the same allocator as other.
transform transform overloads
value value overloads
valueOr valueOr overloads
valueOrNull Return an address providing non-modifiable access to the underlying object of a (template parameter) TYPE if this object is non-null, and 0 otherwise.
value_or value_or overloads
operator BloombergLP::bslmf::NestedTraitDeclaration<NullableValue, HasPrintMethod> NullableValue always provides a print method.
operator BloombergLP::bslmf::NestedTraitDeclaration<NullableValue, IsBitwiseCopyable, bslmf::IsBitwiseCopyable<TYPE>::value> NullableValue is bitwise copyable when TYPE is bitwise copyable.
operator BloombergLP::bslmf::NestedTraitDeclaration<NullableValue, IsBitwiseMoveable, bslmf::IsBitwiseMoveable<TYPE>::value> NullableValue is bitwise moveable when TYPE is bitwise moveable.
operator BloombergLP::bslmf::NestedTraitDeclaration<NullableValue, UsesBslmaAllocator, bslma::UsesBslmaAllocator<TYPE>::value> NullableValue uses a bslma::Allocator when TYPE does.
operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, IsBitwiseCopyable, BloombergLP::bslmf::IsBitwiseCopyable<t_TYPE>::value> Nested trait declaration for bslmf::IsBitwiseCopyable.
operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, IsBitwiseMoveable, BloombergLP::bslmf::IsBitwiseMoveable<t_TYPE>::value> Nested trait declaration for bslmf::IsBitwiseMoveable.
operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, UsesAllocatorArgT> Nested trait declaration for bslmf::UsesAllocatorArgT.
operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, UsesBslmaAllocator> Nested trait declaration for bslma::UsesBslmaAllocator.
operator BloombergLP::bslmf::NestedTraitDeclaration<optional, IsBitwiseCopyable, BloombergLP::bslmf::IsBitwiseCopyable<t_TYPE>::value> Nested trait declaration for bslmf::IsBitwiseCopyable.
operator BloombergLP::bslmf::NestedTraitDeclaration<optional, IsBitwiseMoveable, BloombergLP::bslmf::IsBitwiseMoveable<t_TYPE>::value> Nested trait declaration for bslmf::IsBitwiseMoveable.
operator BloombergLP::bslmf::NestedTraitDeclaration<optional, UsesAllocatorArgT, BloombergLP::bslma::UsesBslmaAllocator<t_TYPE>::value> Nested trait declaration for bslmf::UsesAllocatorArgT.
operator BloombergLP::bslmf::NestedTraitDeclaration<optional, UsesBslmaAllocator, BloombergLP::bslma::UsesBslmaAllocator<t_TYPE>::value> Nested trait declaration for bslma::UsesBslmaAllocator.
operator bool Return false if this object is disengaged, and true otherwise.

Protected Type Aliases

NameDescription
AllocType This typedef is an alias to allocator_type.

Protected Member Functions

NameDescription
assignOrEmplace If *this holds an object, assign to that object the value of the specified rhs, converted to t_TYPE. Otherwise, construct a held object from rhs, converted to t_TYPE. The allocators of *this and rhs remain unchanged.
dereferenceRaw dereferenceRaw overloads

Friends

NameDescription
BloombergLP::bdlb::NullableValueThis template class extends the set of values of its value-semantic TYPE parameter to include the notion of a "null" value. If TYPE is fully value-semantic, then the augmented type NullableValue<TYPE> will be as well. In addition to supporting all homogeneous value-semantic operations, conversions between comparable underlying value types is also supported. Two nullable objects with different underlying types compare equal if their underlying types are comparable and either (1) both objects are null or (2) the non-null values compare equal. A null nullable object is considered ordered before any non-null nullable object. Attempts to copy construct, copy assign, or compare incompatible values types will fail to compile. The NullableValue template cannot be instantiated on an incomplete type, a type that overloads unary operator&, or bsl::nullopt_t.

Non-Member Functions

NameDescription
nullableValue_acceptsBslOptionalComponent-private constraint helper for bsl::optional conversion.
operator!=Return true if the specified nullable objects do not have the same value.
operator!=Return true if the specified lhs and rhs objects do not have the same value, and false otherwise. A nullable object and a value of some type do not have the same value if either the nullable object is null, or its underlying value does not compare equal to the other value. Note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator!=Return true if the specified nullable object and std::optional do not have the same value.
operator!=Return true if the specified lhs and rhs nullable objects do not have the same value, and false otherwise. Two nullable objects do not have the same value if one is null and the other is non-null, or if both are non-null and the values of their underlying objects do not compare equal. Note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator!=Return true if the specified nullable objects do not have the same value.
operator!=Return true if the specified nullable objects do not have the same value.
operator<Return true if the specified lhs nullable object is ordered before the specified rhs, and false otherwise. lhs is ordered before rhs if lhs is null or lhs.value() is ordered before rhs.
operator<Return true if lhs is ordered before rhs, and false otherwise.
operator<Return true if lhs is ordered before rhs, and false otherwise.
operator<Return true if lhs is ordered before rhs, and false otherwise.
operator<Return true if the specified lhs nullable object is ordered before the specified rhs nullable object, and false otherwise. lhs is ordered before rhs if lhs is null and rhs is non-null or if both are non-null and lhs.value() is ordered before rhs.value(). Note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator<If neither of the specified lhs and rhs contain a value, return false. If lhs contains a value, and rhs does not, return false. If lhs does not contains a value, rhs does, return true. Otherwise, return lhs.value < rhs.value().
operator<=Return true if the specified lhs nullable object is ordered before the specified rhs or lhs and rhs have the same value, and false otherwise. (See operator< and operator==.)
operator<=If neither of the specified lhs and rhs contain a value, return true. If lhs contains a value, and rhs does not, return false. If lhs does not contains a value, rhs does, return true. Otherwise, return lhs.value <= rhs.value().
operator<=Return true if lhs is ordered before rhs or they are equal.
operator<=Return true if lhs is ordered before rhs or they are equal.
operator<=Return true if lhs is ordered before rhs or they are equal.
operator<=Return true if the specified lhs nullable object is ordered before the specified rhs nullable object or lhs and rhs have the same value, and false otherwise. (See operator< and operator==.) Note that this operator returns *lhs <= *rhs when both operands are of NullableValue type and have a value. Also note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator<=>Perform a three-way comparison of the specified lhs and the specified rhs objects by using the comparison operators of t_LHS and t_RHS; return the result of that comparison.
operator<=>Perform a three-way comparison of the specified nullable objects.
operator<=>Perform a three-way comparison of the specified value and one of type bsl::nullopt_t; return the result of that comparison.
operator<=>Perform a three-way comparison of the specified nullable objects.
operator<=>Perform a three-way comparison of the specified nullable object and value.
operator==Return true if the specified value is null, and false otherwise.
operator==Return true if the specified nullable objects have the same value.
operator==Return true if the specified nullable objects have the same value, and false otherwise.
operator==Return true if the specified nullable objects have the same value.
operator==Return true if the specified lhs and rhs nullable objects have the same value, and false otherwise. Two nullable objects have the same value if both are null, or if both are non-null and the values of their underlying objects compare equal. Note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator==Return true if the specified lhs and rhs objects have the same value, and false otherwise. A nullable object and a value of some type have the same value if the nullable object is non-null and its underlying value compares equal to the other value. Note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator==Return true if the specified nullable objects have the same value, and false otherwise.
operator>Return true if lhs is ordered after rhs, and false otherwise.
operator>Return true if lhs is ordered after rhs, and false otherwise.
operator>Return true if lhs is ordered after rhs, and false otherwise.
operator>If neither of the specified lhs and rhs contain a value, return false. If lhs contains a value, and rhs does not, return true. If lhs does not contains a value, rhs does, return false. Otherwise, return lhs.value > rhs.value().
operator>Return true if the specified lhs nullable object is ordered after the specified rhs, and false otherwise. lhs is ordered after rhs if lhs is not null and lhs.value() is ordered after rhs.
operator>Return true if the specified lhs nullable object is ordered after the specified rhs nullable object, and false otherwise. lhs is ordered after rhs if lhs is non-null and rhs is null or if both are non-null and lhs.value() is ordered after rhs.value(). Note that this operator returns *lhs > *rhs when both operands are of NullableValue type and both have values. Also note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator>=If neither of the specified lhs and rhs contain a value, return true. If lhs contains a value, and rhs does not, return true. If lhs does not contains a value, rhs does, return false. Otherwise, return lhs.value >= rhs.value().
operator>=Return true if the specified lhs nullable object is ordered after the specified rhs nullable object or lhs and rhs have the same value, and false otherwise. (See operator> and operator==.) Note that this operator returns *lhs >= *rhs when both operands are of NullableValue type and have a value. Also note that this function will fail to compile if LHS_TYPE and RHS_TYPE are not compatible.
operator>=Return true if the specified lhs nullable object is ordered after the specified rhs or lhs and rhs have the same value, and false otherwise. (See operator> and operator==.)
operator>=Return true if lhs is ordered after rhs or they are equal.
operator>=Return true if lhs is ordered after rhs or they are equal.
operator>=Return true if lhs is ordered after rhs or they are equal.
swapExchange the values of the specified lhs and rhs objects when TYPE does not use a bslma::Allocator.
swapExchange the values of the specified rhs and lhs objects. This function provides the no-throw exception-safety guarantee if the (template parameter) TYPE provides that guarantee, the two objects were created with the same allocator (if applicable), and the result of the isNull method for the two objects is the same; otherwise this function provides the basic guarantee.
::bsl::PrintToWrite the specified value to the specified *stream, surrounded by double quotes.
::bsl::operator!=Return true if the specified lhs and rhs optional objects do not have the same value, and false otherwise. Two optional objects do not have the same value if one is disengaged and the other is engaged, or if both are engaged and the values of their underlying objects do not compare equal. This function can be called in constant expressions only if neither t_LHS_TYPE nor t_RHS_TYPE is allocator-aware.
::bsl::operator!=Return true if the specified lhs and rhs optional objects do not have the same value, and false otherwise. Two optional objects do not have the same value if one is disengaged and the other is engaged, or if both are engaged and the values of their underlying objects do not compare equal. Note that this function will fail to compile if t_LHS_TYPE and t_RHS_TYPE are not compatible. These functions can be called in constant expressions only if the bsl::optional's value type is not allocator-aware.
::bsl::operator!=Return true if the specified lhs and rhs objects do not have the same value, and false otherwise. An optional object and a value of some type do not have the same value if either the optional object is disengaged, or its underlying value does not compare equal to the other value. These function can be called in constant expressions only if the optional's value type is not allocator-aware.
::bsl::operator<Return true if the specified lhs optional object is ordered before the specified rhs, and false otherwise. lhs is ordered before rhs if lhs is disengaged or lhs.value() is ordered before rhs. This function can be called in constant expressions only if t_LHS_TYPE is not allocator-aware.
::bsl::operator<Return true if the specified lhs optional object is ordered before the specified rhs optional object, and false otherwise. lhs is ordered before rhs if lhs is disengaged and rhs is engaged or if both are engaged and lhs.value() is ordered before rhs.value(). Note that this function will fail to compile if t_LHS_TYPE and t_RHS_TYPE are not compatible. These functions can be called in constant expressions only if the bsl::optional's value type is not allocator-aware.
::bsl::operator<Return true if the specified lhs optional object is ordered before the specified rhs optional object, and false otherwise. lhs is ordered before rhs if lhs is disengaged and rhs is engaged or if both are engaged and lhs.value() is ordered before rhs.value(). This function can be called in constant expressions only if neither t_LHS_TYPE nor t_RHS_TYPE is allocator-aware.
::bsl::operator<=Return true if the specified lhs optional object is ordered before the specified rhs or lhs and rhs have the same value, and false otherwise. (See operator< and operator==.) This function can be called in constant expressions only if t_LHS_TYPE is not allocator-aware.
::bsl::operator<=Return true if the specified lhs is ordered before the specified rhs optional object or lhs and rhs have the same value, and false otherwise. (See operator< and operator==.) Note that this function will fail to compile if t_LHS_TYPE and t_RHS_TYPE are not compatible. These functions can be called in constant expressions only if the bsl::optional's value type is not allocator-aware.
::bsl::operator<=Return true if the specified lhs optional object is ordered before the specified rhs optional object or if lhs and rhs have the same value, and false otherwise. (See operator< and operator==.) This function can be called in constant expressions only if neither t_LHS_TYPE nor t_RHS_TYPE is allocator-aware.
::bsl::operator<=>Perform a three-way comparison of the specified lhs and the specified rhs objects by using the comparison operators of t_LHS and t_RHS; return the result of that comparison. This function can be called in constant expressions only if neither t_LHS nor t_RHS is allocator-aware.
::bsl::operator<=>Perform a three-way comparison of the specified lhs and the specified rhs objects by using the comparison operators of t_LHS and t_RHS; return the result of that comparison. This function can be called in constant expressions only if t_LHS is not allocator-aware.
::bsl::operator<=>Perform a three-way comparison of the specified lhs and the specified rhs objects by using the comparison operators of t_LHS and t_RHS; return the result of that comparison. This function can be called in constant expressions only if t_LHS is not allocator-aware.
::bsl::operator<=>Perform a three-way comparison of the specified value and nullopt; return the result of that comparison. This function can be called in constant expressions only if t_TYPE is not allocator-aware.
::bsl::operator==Return true if the specified lhs and rhs objects have the same value, and false otherwise. An optional object and a value of some type have the same value if the optional object is engaged and its underlying value compares equal to the other value. These functions can be called in constant expressions only if the optional's value type is not allocator-aware.
::bsl::operator==Return true if the specified lhs and rhs optional objects have the same value, and false otherwise. Two optional objects have the same value if both are disengaged, or if both are engaged and the values of their underlying objects compare equal. This function can be called in constant expressions only if neither t_LHS_TYPE nor t_RHS_TYPE is allocator-aware.
::bsl::operator==Compare a std::optional with a bsl::optional for equality.
::bsl::operator==Return true if the specified value is disengaged, and false otherwise. This function can be called in constant expressions only if t_TYPE is not allocator-aware.
::bsl::operator>Return true if the specified lhs optional object is ordered after the specified rhs, and false otherwise. lhs is ordered after rhs if lhs is engaged and lhs.value() is ordered after rhs. This function can be called in constant expressions only if t_LHS_TYPE is not allocator-aware.
::bsl::operator>Return true if the specified lhs optional object is ordered after the specified rhs optional object, and false otherwise. lhs is ordered after rhs if lhs is engaged and rhs is disengaged or if both are engaged and lhs.value() is ordered after rhs.value(). Note that this function will fail to compile if t_LHS_TYPE and t_RHS_TYPE are not compatible. These functions can be called in constant expressions only if the bsl::optional's value type is not allocator-aware.
::bsl::operator>Return true if the specified lhs optional object is ordered after the specified rhs optional object, and false otherwise. lhs is ordered after rhs if lhs is engaged and rhs is disengaged or if both are engaged and lhs.value() is ordered after rhs.value(). This function can be called in constant expressions only if neither t_LHS_TYPE nor t_RHS_TYPE is allocator-aware.
::bsl::operator>=Return true if the specified lhs optional object is ordered after the specified rhs optional object or if lhs and rhs have the same value, and false otherwise. (See operator> and operator==.) This function can be called in constant expressions only if neither t_LHS_TYPE nor t_RHS_TYPE is allocator-aware.
::bsl::operator>=Return true if the specified lhs optional object is ordered after the specified rhs or if lhs and rhs have the same value, and false otherwise. (See operator> and operator==.) This function can be called in constant expressions only if t_LHS_TYPE is not allocator-aware.
::bsl::operator>=Return true if the specified lhs optional object is ordered after the specified rhs optional object or lhs and rhs have the same value, and false otherwise. (See operator> and operator==.) Note that this function will fail to compile if t_LHS_TYPE and t_RHS_TYPE are not compatible. These functions can be called in constant expressions only if the bsl::optional's value type is not allocator-aware.
::bsl::swapEfficiently exchange the values of the specified lhs and rhs objects. This method provides the no-throw exception-safety guarantee if the template parameter t_TYPE provides that guarantee and the result of the hasValue method for lhs and rhs is the same. This function can be called in constant expressions only if t_TYPE is not allocator-aware.
::bsl::swapEfficiently exchange the values of the specified lhs and rhs objects. This method provides the no-throw exception-safety guarantee if the template parameter t_TYPE provides that guarantee, lhs and rhs have equal allocators, and lhs.hasValue() == rhs.hasValue().
::bsl::swapEfficiently exchange the values of the specified lhs and rhs objects. This method provides the no-throw exception-safety guarantee if the template parameter t_TYPE provides that guarantee and the result of the hasValue method for lhs and rhs is the same.
::BloombergLP::bdlat_NullableValueFunctions::bdlat_nullableValueAccessValueDefault customization-point implementation of accessValue for bdlb::NullableValue.
::BloombergLP::bdlat_NullableValueFunctions::bdlat_nullableValueIsNullDefault customization-point implementation of isNull for bdlb::NullableValue.
::BloombergLP::bdlat_NullableValueFunctions::bdlat_nullableValueMakeValueDefault customization-point implementation of makeValue for bdlb::NullableValue.
::BloombergLP::bdlat_NullableValueFunctions::bdlat_nullableValueManipulateValueDefault customization-point implementation of manipulateValue for bdlb::NullableValue.
::BloombergLP::bslstl::optional_acceptsBslOptionalComponent-private constraint helper for Optional_DerivedFromBslOptional.