8#ifndef HPP_ALIB_CONTAINERS_SHARED_VAL
9#define HPP_ALIB_CONTAINERS_SHARED_VAL 1
19namespace alib {
namespace containers {
64template<
typename T,
typename TAllocator= HeapAllocator>
82 template<
typename... TArgs,
83 typename TEnableIf= TAllocator,
ATMP_IF(std::is_default_constructible<TEnableIf>::value)>
85 :
custom(std::forward<TArgs>(args)...)
108 template<
typename... TArgs>
110 :
custom(std::forward<TArgs>(args)...)
168 :
members(other.members) { other.members=
nullptr; }
179 if (
this == &other || this->members == other.members)
187 if((
members= other.members) !=
nullptr)
209 other.members=
nullptr;
224 template<
typename... TArgs>
227 template<
typename... TArgs,
228 typename TEnableIf= TAllocator,
229 ATMP_IF(!std::is_default_constructible<TEnableIf>::value) >
230 SharedVal( TAllocator& allocator, TArgs&&... args )
232 std::forward<TArgs>(args)...) ) {}
249 template<
typename... TArgs>
255 template <
typename... TArgs,
typename TEnableIf= TAllocator,
256 ATMP_IF( std::is_default_constructible_v<TEnableIf>
257 && !std::is_constructible_v< SharedVal ALIB_COMMA TArgs... >
258 && (
sizeof...(TArgs) > 0)
259 && std::is_constructible_v<T ALIB_COMMA TArgs...>
283 return members->GetAllocator();
320 operator bool() const noexcept {
return members !=
nullptr; }
338template<
typename T,
typename TAllocator= lang::HeapAllocator>
AllocatorType & GetAllocator() const
TAllocator AllocatorType
Exposes the allocator as given with template parameter TAllocator.
SharedVal & operator=(SharedVal &&other) noexcept
bool Unique() const noexcept
ATMP_IF_T_F(std::is_default_constructible< TAllocator >::value, FieldMembersNoTA, FieldMembersWithAllocator) FieldMembers
SharedVal() noexcept
Default Constructor. Leaves this object nulled.
static constexpr size_t SizeOfAllocation()
T StoredType
Exposes the stored type specified with template parameter T.
void operator=(std::nullptr_t)
Assignment of nullptr. Same as SetNulled.
SharedVal(std::nullptr_t) noexcept
bool operator==(std::nullptr_t) const noexcept
bool IsNulled() const noexcept
SharedVal & operator=(const SharedVal &other) noexcept
unsigned int UseCount() const noexcept
FieldMembers * members
The stored data.
SharedVal(TAllocator &allocator, TArgs &&... args)
bool operator!=(std::nullptr_t) const noexcept
SharedVal(TArgs &&... args)
SharedVal(const SharedVal &other) noexcept
T & getR() const noexcept
T * getP() const noexcept
SharedVal(SharedVal &&other) noexcept
#define ATMP_IF_T_F( Cond, T, F)
#define ALIB_ASSERT_ERROR(cond,...)
static ALIB_FORCE_INLINE void Destruct(T &object)
Fields if TAllocator is default constructible (e.g., HeapAllocator).
FieldMembersNoTA(TArgs &&... args)
std::atomic< unsigned int > refCount
The reference counter used to implement the std::shared_ptr behavior.
static constexpr TAllocator GetAllocator() noexcept
T custom
The instance of the custom type.
Fields if TAllocator is not default constructible (not HeapAllocator).
TAllocator & allocator
The allocator used.
FieldMembersWithAllocator(TAllocator &pAllocator, TArgs &&... args)
std::atomic< unsigned int > refCount
The reference counter used to implement the std::shared_ptr behavior.
T custom
The instance of the custom type.
TAllocator & GetAllocator() const