53template<
typename T,
typename TAllocator= HeapAllocator>
72 template<
typename... TArgs,
typename TRequires= TAllocator>
73 requires std::default_initializable<TRequires>
75 :
custom(std::forward<TArgs>(args)...)
98 template<
typename... TArgs>
100 :
custom(std::forward<TArgs>(args)...)
113 using FieldMembers = std::conditional_t< std::is_default_constructible<TAllocator>::value,
158 :
members(other.members) { other.members=
nullptr; }
169 if (
this == &other || this->members == other.members)
177 if((
members= other.members) !=
nullptr)
199 other.members=
nullptr;
214 template<
typename... TArgs,
typename TRequires= TAllocator>
215 requires (!std::default_initializable<TRequires>)
217 :
members( allocator().
template New<FieldMembers>( allocator,
218 std::forward<TArgs>(args)...) ) {}
239 template <
typename... TArgs,
typename TRequires= TAllocator>
240 requires( std::default_initializable<TRequires>
241 && (
sizeof...(TArgs) > 0)
242 && (
sizeof...(TArgs) != 1
243 || !std::same_as<std::decay_t<std::tuple_element_t<0, std::tuple<TArgs...>>>,
245 && std::is_constructible_v<T, TArgs...> )
247 :
members( TAllocator()().
template New<FieldMembers>(std::forward<TArgs>(args)...) ) {}
267 return members->GetAllocator();
304 operator bool() const noexcept {
return members !=
nullptr; }
322template<
typename T,
typename TAllocator= lang::HeapAllocator>
void operator=(std::nullptr_t)
Assignment of nullptr. Same as SetNulled.
SharedVal(std::nullptr_t) noexcept
SharedVal() noexcept
Default Constructor. Leaves this object nulled.
SharedVal(TArgs &&... args)
SharedVal & operator=(const SharedVal &other) noexcept
SharedVal(TAllocator &allocator, TArgs &&... args)
T StoredType
Exposes the stored type specified with template parameter T.
T & getR() const noexcept
T * getP() const noexcept
bool Unique() const noexcept
static constexpr size_t SizeOfAllocation()
bool IsNulled() const noexcept
std::conditional_t< std::is_default_constructible< TAllocator >::value, FieldMembersNoTA, FieldMembersWithAllocator > FieldMembers
AllocatorType & GetAllocator() const
bool operator==(std::nullptr_t) const noexcept
SharedVal(const SharedVal &other) noexcept
SharedVal & operator=(SharedVal &&other) noexcept
unsigned int UseCount() const noexcept
SharedVal(SharedVal &&other) noexcept
bool operator!=(std::nullptr_t) const noexcept
TAllocator AllocatorType
Exposes the allocator as given with template parameter TAllocator.
#define ALIB_ASSERT_ERROR(cond, domain,...)
containers::SharedVal< T, TAllocator > SharedVal
Type alias in namespace alib.
Fields if TAllocator is default-constructible (e.g., HeapAllocator).
static constexpr TAllocator GetAllocator() noexcept
T custom
The instance of the custom type.
std::atomic< unsigned int > refCount
The reference counter used to implement the std::shared_ptr behavior.
FieldMembersNoTA(TArgs &&... args)
Fields if TAllocator is not default-constructible (not HeapAllocator).
TAllocator & allocator
The allocator used.
FieldMembersWithAllocator(TAllocator &pAllocator, TArgs &&... args)
TAllocator & GetAllocator() const
T custom
The instance of the custom type.
std::atomic< unsigned int > refCount
The reference counter used to implement the std::shared_ptr behavior.