11#ifndef INCLUDED_BDLB_NULLABLEALLOCATEDVALUE_CPP03
12#define INCLUDED_BDLB_NULLABLEALLOCATEDVALUE_CPP03
63#ifdef COMPILING_BDLB_NULLABLEALLOCATEDVALUE_H
88class NullableAllocatedValue {
90 enum { k_HAS_VALUE = 0 };
94 NullableAllocatedValue_PointerBitsPair<bslma::Allocator, 1> d_allocator;
101# ifndef BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT
108 typedef BloombergLP::bsls::UnspecifiedBool<NullableAllocatedValue>
110 typedef typename UnspecifiedBoolUtil::BoolType UnspecifiedBool;
126 const TYPE *getAddress() const;
140 void setRemoteAddress(TYPE *newPtr);
167 bslma::UsesBslmaAllocator);
169 bslmf::IsBitwiseMoveable);
171 bdlb::HasPrintMethod);
240#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
243#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
244#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT 5
246#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A
247#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
249#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 0
253#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 1
254 template <
class ARGS_1>
258#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 2
259 template <
class ARGS_1,
265#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 3
266 template <
class ARGS_1,
274#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 4
275 template <
class ARGS_1,
285#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 5
286 template <
class ARGS_1,
299# if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
300#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 0
301 template <
class INIT_LIST_TYPE>
302 TYPE&
emplace(std::initializer_list<INIT_LIST_TYPE> il);
305#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 1
306 template <
class INIT_LIST_TYPE,
class ARGS_1>
307 TYPE&
emplace(std::initializer_list<INIT_LIST_TYPE> il,
311#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 2
312 template <
class INIT_LIST_TYPE,
class ARGS_1,
314 TYPE&
emplace(std::initializer_list<INIT_LIST_TYPE> il,
319#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 3
320 template <
class INIT_LIST_TYPE,
class ARGS_1,
323 TYPE&
emplace(std::initializer_list<INIT_LIST_TYPE> il,
329#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 4
330 template <
class INIT_LIST_TYPE,
class ARGS_1,
334 TYPE&
emplace(std::initializer_list<INIT_LIST_TYPE> il,
341#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_A >= 5
342 template <
class INIT_LIST_TYPE,
class ARGS_1,
347 TYPE&
emplace(std::initializer_list<INIT_LIST_TYPE> il,
360 template <
class... ARGS>
363# if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
364 template <
class INIT_LIST_TYPE,
class... ARGS>
365 TYPE&
emplace(std::initializer_list<INIT_LIST_TYPE> il,
382 template <
class STREAM>
419 template <
class STREAM>
447#ifndef BDE_OMIT_INTERNAL_DEPRECATED
458 template <
class ANY_TYPE>
459 TYPE
value_or(
const ANY_TYPE& default_value)
const;
472# ifdef BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT
479 operator UnspecifiedBool() const BSLS_NOTHROW_SPEC
481 return UnspecifiedBoolUtil::makeValue(
has_value());
499 bsl::ostream&
print(bsl::ostream& stream,
501 int spacesPerLevel = 4)
const;
506 const TYPE&
value()
const;
515 "Use 'has_value() ? &value() : address' instead")
516 const TYPE *addressOr(const TYPE *address) const;
518#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
521#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
522#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT 5
524#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B
525#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
528#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B >= 0
530 "Use 'emplace' instead")
531 TYPE& makeValueInplace();
534#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B >= 1
535 template <
class ARGS_1>
537 "Use 'emplace' instead")
541#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B >= 2
542 template <
class ARGS_1,
545 "Use 'emplace' instead")
550#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B >= 3
551 template <
class ARGS_1,
555 "Use 'emplace' instead")
561#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B >= 4
562 template <
class ARGS_1,
567 "Use 'emplace' instead")
574#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_B >= 5
575 template <
class ARGS_1,
581 "Use 'emplace' instead")
593 template <
class... ARGS>
595 "Use 'emplace' instead")
605 "Use 'value_or' instead")
606 TYPE valueOr(const TYPE& otherValue) const;
613 const TYPE *valueOrNull() const;
624template <class LHS_TYPE, class RHS_TYPE>
634template <class LHS_TYPE, class RHS_TYPE>
636 const RHS_TYPE& rhs);
637template <class LHS_TYPE, class RHS_TYPE>
638bool operator==(const LHS_TYPE& lhs,
647template <class LHS_TYPE, class RHS_TYPE>
657template <class LHS_TYPE, class RHS_TYPE>
659 const RHS_TYPE& rhs);
660template <class LHS_TYPE, class RHS_TYPE>
661bool operator!=(const LHS_TYPE& lhs,
670template <class LHS_TYPE, class RHS_TYPE>
677template <class LHS_TYPE, class RHS_TYPE>
679 const RHS_TYPE& rhs);
684template <class LHS_TYPE, class RHS_TYPE>
685bool operator<(const LHS_TYPE& lhs,
695template <class LHS_TYPE, class RHS_TYPE>
703template <class LHS_TYPE, class RHS_TYPE>
705 const RHS_TYPE& rhs);
711template <class LHS_TYPE, class RHS_TYPE>
712bool operator<=(const LHS_TYPE& lhs,
722template <class LHS_TYPE, class RHS_TYPE>
730template <class LHS_TYPE, class RHS_TYPE>
732 const RHS_TYPE& rhs);
738template <class LHS_TYPE, class RHS_TYPE>
739bool operator>(const LHS_TYPE& lhs,
748template <class LHS_TYPE, class RHS_TYPE>
756template <class LHS_TYPE, class RHS_TYPE>
758 const RHS_TYPE& rhs);
764template <class LHS_TYPE, class RHS_TYPE>
765bool operator>=(const LHS_TYPE& lhs,
777bsl::ostream& operator<<(
bsl::ostream& stream,
857template <class LHS_TYPE, class RHS_TYPE>
859 const
bsl::optional<RHS_TYPE>& rhs);
860template <class LHS_TYPE, class RHS_TYPE>
861bool operator==(const
bsl::optional<LHS_TYPE>& lhs,
867template <class LHS_TYPE, class RHS_TYPE>
869 const
bsl::optional<RHS_TYPE>& rhs);
870template <class LHS_TYPE, class RHS_TYPE>
871bool operator!=(const
bsl::optional<LHS_TYPE>& lhs,
878template <class LHS_TYPE, class RHS_TYPE>
880 const
bsl::optional<RHS_TYPE>& rhs);
886template <class LHS_TYPE, class RHS_TYPE>
887bool operator<(const
bsl::optional<LHS_TYPE>& lhs,
894template <class LHS_TYPE, class RHS_TYPE>
896 const
bsl::optional<RHS_TYPE>& rhs);
902template <class LHS_TYPE, class RHS_TYPE>
903bool operator>(const
bsl::optional<LHS_TYPE>& lhs,
910template <class LHS_TYPE, class RHS_TYPE>
912 const
bsl::optional<RHS_TYPE>& rhs);
918template <class LHS_TYPE, class RHS_TYPE>
919bool operator<=(const
bsl::optional<LHS_TYPE>& lhs,
926template <class LHS_TYPE, class RHS_TYPE>
928 const
bsl::optional<RHS_TYPE>& rhs);
934template <class LHS_TYPE, class RHS_TYPE>
935bool operator>=(const
bsl::optional<LHS_TYPE>& lhs,
944template <class HASHALG, class TYPE>
966: d_allocator(
bslma::Default::defaultAllocator())
968 d_storage.d_pointer_p = 0;
973NullableAllocatedValue<TYPE>
977 d_storage.d_pointer_p = 0;
982NullableAllocatedValue<TYPE>::NullableAllocatedValue(
const bsl::nullopt_t&)
983: d_allocator(
bslma::Default::defaultAllocator())
985 d_storage.d_pointer_p = 0;
990NullableAllocatedValue<TYPE>
993: d_allocator(allocator.mechanism())
995 d_storage.d_pointer_p = 0;
1000NullableAllocatedValue<TYPE>
1001::NullableAllocatedValue(
const NullableAllocatedValue<TYPE>& original)
1002: d_allocator(
bslma::Default::defaultAllocator())
1004 if (original.has_value()) {
1008 d_storage.d_pointer_p = 0;
1012template <
class TYPE>
1014NullableAllocatedValue<TYPE>
1015::NullableAllocatedValue(
const NullableAllocatedValue<TYPE>& original,
1017: d_allocator(allocator.mechanism())
1019 if (original.has_value()) {
1023 d_storage.d_pointer_p = 0;
1027template <
class TYPE>
1029NullableAllocatedValue<TYPE>::NullableAllocatedValue(
const TYPE& value)
1030: d_allocator(
bslma::Default::defaultAllocator())
1035template <
class TYPE>
1037NullableAllocatedValue<TYPE>::NullableAllocatedValue(
1040: d_allocator(allocator.mechanism())
1045template <
class TYPE>
1047NullableAllocatedValue<TYPE>::~NullableAllocatedValue()
1053template <
class TYPE>
1058 return (
sizeof(TYPE) <=
sizeof(TYPE *)) &&
1065template <
class TYPE>
1067NullableAllocatedValue<TYPE>&
1068NullableAllocatedValue<TYPE>::operator=(
1069 const NullableAllocatedValue<TYPE>& rhs)
1071 if (rhs.has_value()) {
1081template <
class TYPE>
1083NullableAllocatedValue<TYPE>&
1090template <
class TYPE>
1092NullableAllocatedValue<TYPE>&
1093NullableAllocatedValue<TYPE>::operator=(
const TYPE& rhs)
1099template <
class TYPE>
1100template <
class STREAM>
1101STREAM& NullableAllocatedValue<TYPE>::bdexStreamIn(STREAM& stream,
int version)
1105 char isNullFlag = 0;
1107 stream.getInt8(isNullFlag);
1122template <
class TYPE>
1124TYPE& NullableAllocatedValue<TYPE>::makeValue(
const TYPE& val)
1137 TYPE *tmpPtr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1142 setRemoteAddress(tmpPtr);
1149template <
class TYPE>
1151TYPE& NullableAllocatedValue<TYPE>::makeValue()
1170 TYPE *tmpPtr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1175 setRemoteAddress(tmpPtr);
1183template <
class TYPE>
1185void NullableAllocatedValue<TYPE>::reset()
1188 TYPE *p = getAddress();
1194 clearHasValueFlag();
1198template <
class TYPE>
1199void NullableAllocatedValue<TYPE>::swap(NullableAllocatedValue& other)
1206 if (
isNull() && other.isNull()) {
1218template <
class TYPE>
1220TYPE& NullableAllocatedValue<TYPE>::value()
1223 return *getAddress();
1226template <
class TYPE>
1228TYPE *NullableAllocatedValue<TYPE>::operator->()
1231 return getAddress();
1234template <
class TYPE>
1236TYPE& NullableAllocatedValue<TYPE>::operator*()
1242#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
1245#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
1246#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT 5
1248#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C
1249#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
1251#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 0
1252template <
class TYPE>
1254TYPE& NullableAllocatedValue<TYPE>::emplace(
1258 TYPE *ptr = getAddress();
1262 clearHasValueFlag();
1264 else if (!isLocal()) {
1265 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1266 setRemoteAddress(ptr);
1270 BloombergLP::bslma::ConstructionUtil::construct(
1276 BloombergLP::bslma::ConstructionUtil::construct(
1286#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 1
1287template <
class TYPE>
1288template <
class ARGS_1>
1290TYPE& NullableAllocatedValue<TYPE>::emplace(
1294 TYPE *ptr = getAddress();
1298 clearHasValueFlag();
1300 else if (!isLocal()) {
1301 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1302 setRemoteAddress(ptr);
1306 BloombergLP::bslma::ConstructionUtil::construct(
1313 BloombergLP::bslma::ConstructionUtil::construct(
1324#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 2
1325template <
class TYPE>
1326template <
class ARGS_1,
1329TYPE& NullableAllocatedValue<TYPE>::emplace(
1334 TYPE *ptr = getAddress();
1338 clearHasValueFlag();
1340 else if (!isLocal()) {
1341 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1342 setRemoteAddress(ptr);
1346 BloombergLP::bslma::ConstructionUtil::construct(
1354 BloombergLP::bslma::ConstructionUtil::construct(
1366#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 3
1367template <
class TYPE>
1368template <
class ARGS_1,
1372TYPE& NullableAllocatedValue<TYPE>::emplace(
1378 TYPE *ptr = getAddress();
1382 clearHasValueFlag();
1384 else if (!isLocal()) {
1385 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1386 setRemoteAddress(ptr);
1390 BloombergLP::bslma::ConstructionUtil::construct(
1399 BloombergLP::bslma::ConstructionUtil::construct(
1412#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 4
1413template <
class TYPE>
1414template <
class ARGS_1,
1419TYPE& NullableAllocatedValue<TYPE>::emplace(
1426 TYPE *ptr = getAddress();
1430 clearHasValueFlag();
1432 else if (!isLocal()) {
1433 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1434 setRemoteAddress(ptr);
1438 BloombergLP::bslma::ConstructionUtil::construct(
1448 BloombergLP::bslma::ConstructionUtil::construct(
1462#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 5
1463template <
class TYPE>
1464template <
class ARGS_1,
1470TYPE& NullableAllocatedValue<TYPE>::emplace(
1478 TYPE *ptr = getAddress();
1482 clearHasValueFlag();
1484 else if (!isLocal()) {
1485 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1486 setRemoteAddress(ptr);
1490 BloombergLP::bslma::ConstructionUtil::construct(
1501 BloombergLP::bslma::ConstructionUtil::construct(
1517# if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1518#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 0
1519template <
class TYPE>
1520template <
class INIT_LIST_TYPE>
1521TYPE& NullableAllocatedValue<TYPE>::emplace(
1522 std::initializer_list<INIT_LIST_TYPE> il)
1525 TYPE *ptr = getAddress();
1529 clearHasValueFlag();
1531 else if (!isLocal()) {
1532 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1533 setRemoteAddress(ptr);
1537 BloombergLP::bslma::ConstructionUtil::construct(
1544 BloombergLP::bslma::ConstructionUtil::construct(
1555#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 1
1556template <
class TYPE>
1557template <
class INIT_LIST_TYPE,
class ARGS_1>
1558TYPE& NullableAllocatedValue<TYPE>::emplace(
1559 std::initializer_list<INIT_LIST_TYPE> il,
1563 TYPE *ptr = getAddress();
1567 clearHasValueFlag();
1569 else if (!isLocal()) {
1570 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1571 setRemoteAddress(ptr);
1575 BloombergLP::bslma::ConstructionUtil::construct(
1583 BloombergLP::bslma::ConstructionUtil::construct(
1595#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 2
1596template <
class TYPE>
1597template <
class INIT_LIST_TYPE,
class ARGS_1,
1599TYPE& NullableAllocatedValue<TYPE>::emplace(
1600 std::initializer_list<INIT_LIST_TYPE> il,
1605 TYPE *ptr = getAddress();
1609 clearHasValueFlag();
1611 else if (!isLocal()) {
1612 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1613 setRemoteAddress(ptr);
1617 BloombergLP::bslma::ConstructionUtil::construct(
1626 BloombergLP::bslma::ConstructionUtil::construct(
1639#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 3
1640template <
class TYPE>
1641template <
class INIT_LIST_TYPE,
class ARGS_1,
1644TYPE& NullableAllocatedValue<TYPE>::emplace(
1645 std::initializer_list<INIT_LIST_TYPE> il,
1651 TYPE *ptr = getAddress();
1655 clearHasValueFlag();
1657 else if (!isLocal()) {
1658 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1659 setRemoteAddress(ptr);
1663 BloombergLP::bslma::ConstructionUtil::construct(
1673 BloombergLP::bslma::ConstructionUtil::construct(
1687#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 4
1688template <
class TYPE>
1689template <
class INIT_LIST_TYPE,
class ARGS_1,
1693TYPE& NullableAllocatedValue<TYPE>::emplace(
1694 std::initializer_list<INIT_LIST_TYPE> il,
1701 TYPE *ptr = getAddress();
1705 clearHasValueFlag();
1707 else if (!isLocal()) {
1708 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1709 setRemoteAddress(ptr);
1713 BloombergLP::bslma::ConstructionUtil::construct(
1724 BloombergLP::bslma::ConstructionUtil::construct(
1739#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_C >= 5
1740template <
class TYPE>
1741template <
class INIT_LIST_TYPE,
class ARGS_1,
1746TYPE& NullableAllocatedValue<TYPE>::emplace(
1747 std::initializer_list<INIT_LIST_TYPE> il,
1755 TYPE *ptr = getAddress();
1759 clearHasValueFlag();
1761 else if (!isLocal()) {
1762 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1763 setRemoteAddress(ptr);
1767 BloombergLP::bslma::ConstructionUtil::construct(
1779 BloombergLP::bslma::ConstructionUtil::construct(
1799template <
class TYPE>
1800template <
class... ARGS>
1802TYPE& NullableAllocatedValue<TYPE>::emplace(
1806 TYPE *ptr = getAddress();
1810 clearHasValueFlag();
1812 else if (!isLocal()) {
1813 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1814 setRemoteAddress(ptr);
1818 BloombergLP::bslma::ConstructionUtil::construct(
1825 BloombergLP::bslma::ConstructionUtil::construct(
1835# if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1836template <
class TYPE>
1837template <
class INIT_LIST_TYPE,
class... ARGS>
1838TYPE& NullableAllocatedValue<TYPE>::emplace(
1839 std::initializer_list<INIT_LIST_TYPE> il,
1843 TYPE *ptr = getAddress();
1847 clearHasValueFlag();
1849 else if (!isLocal()) {
1850 ptr =
reinterpret_cast<TYPE *
>(alloc->
allocate(
sizeof(TYPE)));
1851 setRemoteAddress(ptr);
1855 BloombergLP::bslma::ConstructionUtil::construct(
1863 BloombergLP::bslma::ConstructionUtil::construct(
1878template <
class TYPE>
1880TYPE *NullableAllocatedValue<TYPE>::getAddress() {
1882 return reinterpret_cast<TYPE *
>(
1883 static_cast<void *
>(d_storage.d_buffer));
1886 return d_storage.d_pointer_p;
1890template <
class TYPE>
1892const TYPE *NullableAllocatedValue<TYPE>::getAddress()
const {
1894 return reinterpret_cast<const TYPE *
>(
1895 static_cast<const void *
>(d_storage.d_buffer));
1898 return d_storage.d_pointer_p;
1903template <
class TYPE>
1907 d_allocator.clearFlag(k_HAS_VALUE);
1910template <
class TYPE>
1914 d_allocator.setFlag(k_HAS_VALUE);
1917template <
class TYPE>
1919void NullableAllocatedValue<TYPE>::setRemoteAddress(TYPE *newPtr) {
1921 d_storage.d_pointer_p = newPtr;
1924template <
class TYPE>
1926void NullableAllocatedValue<TYPE>::swapLocal(NullableAllocatedValue& other)
1934 else if (other.isNull()) {
1935 other.makeValue(value());
1943template <
class TYPE>
1945void NullableAllocatedValue<TYPE>::swapRemote(NullableAllocatedValue& other)
1949 &other.d_storage.d_pointer_p);
1953template <
class TYPE>
1954template <
class STREAM>
1955STREAM& NullableAllocatedValue<TYPE>::bdexStreamOut(STREAM& stream,
1960 stream.putInt8(has_value() ? 0 : 1);
1969template <
class TYPE>
1977template <
class TYPE>
1981 return d_allocator.readFlag(k_HAS_VALUE);
1984template <
class TYPE>
1988 return !has_value();
1991# ifdef BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT
1992template <
class TYPE>
1999template <
class TYPE>
2001int NullableAllocatedValue<TYPE>::maxSupportedBdexVersion(
2002 int versionSelector)
const
2014#ifndef BDE_OMIT_INTERNAL_DEPRECATED
2015template <
class TYPE>
2017int NullableAllocatedValue<TYPE>::maxSupportedBdexVersion()
const
2023template <
class TYPE>
2024template <
class ANY_TYPE>
2026NullableAllocatedValue<TYPE>::value_or(
const ANY_TYPE& default_value)
const
2028 return has_value() ? value() : static_cast<TYPE>(default_value);
2031template <
class TYPE>
2033const TYPE *NullableAllocatedValue<TYPE>::operator->()
const
2039template <
class TYPE>
2041const TYPE& NullableAllocatedValue<TYPE>::operator*()
const
2049template <
class TYPE>
2053 return d_allocator.getPointer();
2056template <
class TYPE>
2058bsl::ostream& NullableAllocatedValue<TYPE>::print(
2059 bsl::ostream& stream,
2061 int spacesPerLevel)
const
2073template <
class TYPE>
2075const TYPE& NullableAllocatedValue<TYPE>::value()
const
2077#ifndef BDE_OMIT_INTERNAL_DEPRECATED
2087 return *getAddress();
2092template <
class TYPE>
2094const TYPE *NullableAllocatedValue<TYPE>::addressOr(
const TYPE *address)
const
2096 return has_value() ? &value() : address;
2099#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
2102#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
2103#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT 5
2105#ifndef BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D
2106#define BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT
2108#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D >= 0
2109template <
class TYPE>
2111TYPE& NullableAllocatedValue<TYPE>::makeValueInplace(
2118#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D >= 1
2119template <
class TYPE>
2120template <
class ARGS_1>
2122TYPE& NullableAllocatedValue<TYPE>::makeValueInplace(
2129#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D >= 2
2130template <
class TYPE>
2131template <
class ARGS_1,
2134TYPE& NullableAllocatedValue<TYPE>::makeValueInplace(
2143#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D >= 3
2144template <
class TYPE>
2145template <
class ARGS_1,
2149TYPE& NullableAllocatedValue<TYPE>::makeValueInplace(
2160#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D >= 4
2161template <
class TYPE>
2162template <
class ARGS_1,
2167TYPE& NullableAllocatedValue<TYPE>::makeValueInplace(
2180#if BDLB_NULLABLEALLOCATEDVALUE_VARIADIC_LIMIT_D >= 5
2181template <
class TYPE>
2182template <
class ARGS_1,
2188TYPE& NullableAllocatedValue<TYPE>::makeValueInplace(
2206template <
class TYPE>
2207template <
class... ARGS>
2209TYPE& NullableAllocatedValue<TYPE>::makeValueInplace(
2217template <
class TYPE>
2219TYPE NullableAllocatedValue<TYPE>::valueOr(
const TYPE& otherValue)
const
2221 return has_value() ? value() : otherValue;
2224template <
class TYPE>
2226const TYPE *NullableAllocatedValue<TYPE>::valueOrNull()
const {
2227 return has_value() ? &value() : NULL;
2233template <
class LHS_TYPE,
class RHS_TYPE>
2236 const NullableAllocatedValue<RHS_TYPE>& rhs)
2239 return rhs.isNull();
2242 return rhs.isNull() ? false : lhs.value() == rhs.value();
2245template <
class LHS_TYPE,
class RHS_TYPE>
2248 const RHS_TYPE& rhs)
2250 return lhs.isNull() ? false : lhs.value() == rhs;
2253template <
class LHS_TYPE,
class RHS_TYPE>
2256 const NullableAllocatedValue<RHS_TYPE>& rhs)
2258 return rhs.isNull() ? false : lhs == rhs.value();
2261template <
class LHS_TYPE,
class RHS_TYPE>
2264 const NullableAllocatedValue<RHS_TYPE>& rhs)
2267 return !rhs.isNull();
2270 return rhs.isNull() ? true : lhs.value() != rhs.value();
2273template <
class LHS_TYPE,
class RHS_TYPE>
2276 const RHS_TYPE& rhs)
2278 return lhs.isNull() ? true : lhs.value() != rhs;
2281template <
class LHS_TYPE,
class RHS_TYPE>
2284 const NullableAllocatedValue<RHS_TYPE>& rhs)
2286 return rhs.isNull() ? true : lhs != rhs.value();
2289template <
class LHS_TYPE,
class RHS_TYPE>
2292 const NullableAllocatedValue<RHS_TYPE>& rhs)
2298 return lhs.isNull() ? true : lhs.value() < rhs.value();
2301template <
class LHS_TYPE,
class RHS_TYPE>
2304 const RHS_TYPE& rhs)
2306 return lhs.isNull() ? true : lhs.value() < rhs;
2309template <
class LHS_TYPE,
class RHS_TYPE>
2312 const NullableAllocatedValue<RHS_TYPE>& rhs)
2314 return rhs.isNull() ? false : lhs < rhs.value();
2317template <
class LHS_TYPE,
class RHS_TYPE>
2320 const NullableAllocatedValue<RHS_TYPE>& rhs)
2326 return rhs.isNull() ? false : lhs.value() <= rhs.value();
2329template <
class LHS_TYPE,
class RHS_TYPE>
2332 const RHS_TYPE& rhs)
2334 return lhs.isNull() ? true : lhs.value() <= rhs;
2337template <
class LHS_TYPE,
class RHS_TYPE>
2340 const NullableAllocatedValue<RHS_TYPE>& rhs)
2342 return rhs.isNull() ? false : lhs <= rhs.value();
2345template <
class LHS_TYPE,
class RHS_TYPE>
2348 const NullableAllocatedValue<RHS_TYPE>& rhs)
2354 return rhs.isNull() ? true : lhs.value() > rhs.value();
2357template <
class LHS_TYPE,
class RHS_TYPE>
2360 const RHS_TYPE& rhs)
2362 return lhs.isNull() ? false : lhs.value() > rhs;
2365template <
class LHS_TYPE,
class RHS_TYPE>
2368 const NullableAllocatedValue<RHS_TYPE>& rhs)
2370 return rhs.isNull() ? true : lhs > rhs.value();
2373template <
class LHS_TYPE,
class RHS_TYPE>
2376 const NullableAllocatedValue<RHS_TYPE>& rhs)
2382 return lhs.isNull() ? false : lhs.value() >= rhs.value();
2385template <
class LHS_TYPE,
class RHS_TYPE>
2388 const RHS_TYPE& rhs)
2390 return lhs.isNull() ? false : lhs.value() >= rhs;
2393template <
class LHS_TYPE,
class RHS_TYPE>
2396 const NullableAllocatedValue<RHS_TYPE>& rhs)
2398 return rhs.isNull() ? true : lhs >= rhs.value();
2401template <
class TYPE>
2404 const NullableAllocatedValue<TYPE>&
object)
2406 return object.print(stream, 0, -1);
2413template <
class TYPE>
2418 return !lhs.has_value();
2421template <
class TYPE>
2427 return !rhs.has_value();
2430template <
class TYPE>
2434 return lhs.has_value();
2437template <
class TYPE>
2443 return rhs.has_value();
2446template <
class TYPE>
2454template <
class TYPE>
2460 return rhs.has_value();
2463template <
class TYPE>
2468 return lhs.has_value();
2471template <
class TYPE>
2479template <
class TYPE>
2484 return !lhs.has_value();
2487template <
class TYPE>
2496template <
class TYPE>
2504template <
class TYPE>
2510 return !rhs.has_value();
2517template <
class LHS_TYPE,
class RHS_TYPE>
2522 if (lhs.has_value() != rhs.has_value())
2524 return lhs.has_value () ? lhs.value() == rhs.value () :
true;
2527template <
class LHS_TYPE,
class RHS_TYPE>
2530 const NullableAllocatedValue<RHS_TYPE>& rhs)
2532 if (lhs.has_value() != rhs.has_value())
2534 return lhs.has_value () ? lhs.value() == rhs.value () :
true;
2537template <
class LHS_TYPE,
class RHS_TYPE>
2542 if (lhs.has_value() != rhs.has_value())
2544 return lhs.has_value () ? lhs.value() != rhs.value () :
false;
2547template <
class LHS_TYPE,
class RHS_TYPE>
2550 const NullableAllocatedValue<RHS_TYPE>& rhs)
2552 if (lhs.has_value() != rhs.has_value())
2554 return lhs.has_value () ? lhs.value() != rhs.value () :
false;
2557template <
class LHS_TYPE,
class RHS_TYPE>
2562 if (lhs.has_value() != rhs.has_value())
2563 return rhs.has_value();
2564 return lhs.has_value () ? lhs.value() < rhs.value () :
false;
2567template <
class LHS_TYPE,
class RHS_TYPE>
2570 const NullableAllocatedValue<RHS_TYPE>& rhs)
2572 if (lhs.has_value() != rhs.has_value())
2573 return rhs.has_value();
2574 return lhs.has_value () ? lhs.value() < rhs.value () :
false;
2578template <
class LHS_TYPE,
class RHS_TYPE>
2583 if (lhs.has_value() != rhs.has_value())
2584 return lhs.has_value();
2585 return lhs.has_value () ? lhs.value() > rhs.value () :
false;
2588template <
class LHS_TYPE,
class RHS_TYPE>
2591 const NullableAllocatedValue<RHS_TYPE>& rhs)
2593 if (lhs.has_value() != rhs.has_value())
2594 return lhs.has_value();
2595 return lhs.has_value () ? lhs.value() > rhs.value () :
false;
2598template <
class LHS_TYPE,
class RHS_TYPE>
2603 if (lhs.has_value() != rhs.has_value())
2604 return rhs.has_value();
2605 return lhs.has_value () ? lhs.value() <= rhs.value () :
true;
2608template <
class LHS_TYPE,
class RHS_TYPE>
2611 const NullableAllocatedValue<RHS_TYPE>& rhs)
2613 if (lhs.has_value() != rhs.has_value())
2614 return rhs.has_value();
2615 return lhs.has_value () ? lhs.value() <= rhs.value () :
true;
2618template <
class LHS_TYPE,
class RHS_TYPE>
2623 if (lhs.has_value() != rhs.has_value())
2624 return lhs.has_value();
2625 return lhs.has_value () ? lhs.value() >= rhs.value () :
true;
2628template <
class LHS_TYPE,
class RHS_TYPE>
2631 const NullableAllocatedValue<RHS_TYPE>& rhs)
2633 if (lhs.has_value() != rhs.has_value())
2634 return lhs.has_value();
2635 return lhs.has_value () ? lhs.value() >= rhs.value () :
true;
2640template <
class HASHALG,
class TYPE>
2642 const NullableAllocatedValue<TYPE>& input)
2644 using ::BloombergLP::bslh::hashAppend;
2646 if (!input.isNull()) {
2655template <
class TYPE>
2656void bdlb::swap(NullableAllocatedValue<TYPE>& a,
2657 NullableAllocatedValue<TYPE>& b)
2659 if (a.allocator() == b.allocator()) {
2665 NullableAllocatedValue<TYPE> futureA(b, a.allocator());
2666 NullableAllocatedValue<TYPE> futureB(a, b.allocator());
2675# error Not valid except when included from bdlb_nullableallocatedvalue.h
#define BSLMF_NESTED_TRAIT_DECLARATION(t_TYPE, t_TRAIT)
Definition bslmf_nestedtraitdeclaration.h:231
char d_buffer[sizeof(TYPE *)]
Definition bdlb_nullableallocatedvalue.h:183
TYPE * d_pointer_p
Definition bdlb_nullableallocatedvalue.h:182
void reset()
Definition bdlb_nullableallocatedvalue.h:1104
TYPE ValueType
Definition bdlb_nullableallocatedvalue.h:249
TYPE value_or(const ANY_TYPE &default_value) const
Definition bdlb_nullableallocatedvalue.h:1396
bool has_value() const BSLS_KEYWORD_NOEXCEPT
Definition bdlb_nullableallocatedvalue.h:1349
TYPE & emplace(BSLS_COMPILERFEATURES_FORWARD_REF(ARGS)...)
NullableAllocatedValue()
Definition bdlb_nullableallocatedvalue.h:884
bsl::allocator< char > get_allocator() const
Definition bdlb_nullableallocatedvalue.h:1341
TYPE & makeValue()
Definition bdlb_nullableallocatedvalue.h:1070
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlb_nullableallocatedvalue.h:1020
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition bdlb_nullableallocatedvalue.h:1428
TYPE * operator->()
Definition bdlb_nullableallocatedvalue.h:1147
bool isNull() const BSLS_KEYWORD_NOEXCEPT
Definition bdlb_nullableallocatedvalue.h:1356
void swap(NullableAllocatedValue &other)
Definition bdlb_nullableallocatedvalue.h:1118
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlb_nullableallocatedvalue.h:1325
TYPE & value()
Definition bdlb_nullableallocatedvalue.h:1139
int maxSupportedBdexVersion() const
Definition bdlb_nullableallocatedvalue.h:1387
TYPE & operator*()
Definition bdlb_nullableallocatedvalue.h:1155
bslma::Allocator * allocator() const
Return the allocator used by this object to supply memory.
Definition bdlb_nullableallocatedvalue.h:1421
Definition bslma_bslallocator.h:580
void deallocate(TYPE *p, std::size_t n=1)
Definition bslma_bslallocator.h:1039
Definition bslstl_optional.h:1861
static void swap(T *a, T *b)
Definition bslalg_swaputil.h:194
Definition bslma_allocator.h:457
virtual void * allocate(size_type size)=0
Definition bslma_deallocatorproctor.h:312
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2012
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_DEPRECATE_FEATURE(UOR, FEATURE, MESSAGE)
Definition bsls_deprecatefeature.h:319
#define BSLS_KEYWORD_EXPLICIT
Definition bsls_keyword.h:641
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
STREAM & bdexStreamOut(STREAM &stream, const DayCountConvention::Enum &value, int version)
int maxSupportedBdexVersion(const DayCountConvention::Enum *, int versionSelector)
STREAM & bdexStreamIn(STREAM &stream, DayCountConvention::Enum &variable, int version)
bool isNull(const TYPE &object)
void makeValue(TYPE *object)
void reset(TYPE *object)
Reset the value of the specified object to its default value.
bsl::ostream & print(bsl::ostream &stream, const TYPE &object, int level=0, int spacesPerLevel=4)
Definition bdlb_printmethods.h:719
Definition bdlb_algorithmworkaroundutil.h:74
bool operator!=(const BigEndianInt16 &lhs, const BigEndianInt16 &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const BigEndianInt16 &integer)
bool operator>=(const Guid &lhs, const Guid &rhs)
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const BigEndianInt16 &object)
void swap(NullableAllocatedValue< TYPE > &a, NullableAllocatedValue< TYPE > &b)
bool operator<=(const Guid &lhs, const Guid &rhs)
bool operator>(const Guid &lhs, const Guid &rhs)
bool operator<(const Guid &lhs, const Guid &rhs)
bool operator==(const BigEndianInt16 &lhs, const BigEndianInt16 &rhs)
Definition bdlb_printmethods.h:283
Definition balxml_encoderoptions.h:68
Definition bdlbb_blob.h:576
STREAM & bdexStreamIn(STREAM &stream, VALUE_TYPE &variable)
Definition bslx_instreamfunctions.h:1247
STREAM & bdexStreamOut(STREAM &stream, const TYPE &value)
Definition bslx_outstreamfunctions.h:992
int maxSupportedBdexVersion(const TYPE *, int versionSelector)
Definition bslx_versionfunctions.h:519
Definition bslstl_optional.h:467
static void defaultConstruct(TARGET_TYPE *address, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1559
static void copyConstruct(TARGET_TYPE *address, const TARGET_TYPE &original, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1599
Definition bslmf_isbitwisemoveable.h:718
Definition bsls_alignmentfromtype.h:376