20#include <AUI/Common/SharedPtrTypes.h>
21#include <AUI/Common/AOptional.h>
22#include <AUI/Thread/AMutex.h>
23#include <AUI/Traits/concepts.h>
59 template<
typename AnyType>
60 operator AnyType()
noexcept {
61 if constexpr(!std::is_same_v<AnyType, bool>) {
62 AUI_ASSERTX(mValue !=
nullptr,
"value is used when null");
64 return AnyType(mValue);
68 T value()
const noexcept {
72 template<
typename AnyType>
73 bool operator==(
const AnyType& v)
const noexcept {
77 template<
typename AnyType>
78 bool operator!=(
const AnyType& v)
const noexcept {
87 void checkForNull()
const {
AUI_ASSERTX(value !=
nullptr,
"this value couldn't be null"); }
98 operator T()
const noexcept {
102 auto operator->()
const {
128 static_assert(!std::is_reference<T>::value,
"use undecorated type (without reference)");
129 static_assert(!std::is_pointer_v<T>,
"use undecorated type (without pointer)");
135 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
140 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
143 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
147 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
149 no_escape(
const _unique<T>& value): value(&*value) {
150 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
153 template<
typename DerivedFromT, std::enable_if_t<std::is_base_of_v<T, DerivedFromT> && !std::is_same_v<DerivedFromT, T>,
bool> = true>
155 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
158 template<
typename DerivedFromT, std::enable_if_t<std::is_base_of_v<T, DerivedFromT> && !std::is_same_v<DerivedFromT, T>,
bool> = true>
159 no_escape(
const _unique<DerivedFromT>& value): value(&*value) {
160 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
164 T*
ptr()
const noexcept {
168 T* operator->()
const noexcept {
172 T& operator*()
const noexcept {
181 template<
typename T =
void>
185 std::function<T()> initializer;
187 template<
typename Factory, std::enable_if_t<std::is_invocable_r_v<T, Factory>,
bool> = true>
188 lazy(
Factory&& initializer) noexcept : initializer(std::forward<Factory>(initializer)) {}
190 lazy(
const lazy<T>& other)
noexcept: value(other.value), initializer(other.initializer) {}
191 lazy(
lazy<T>&& other)
noexcept: value(std::move(other.value)), initializer(std::move(other.initializer)) {}
195 value = initializer();
199 const T& get()
const {
200 return const_cast<lazy<T>*
>(
this)->get();
206 operator const T&()
const {
213 const T& operator*()
const {
220 T
const * operator->()
const {
225 value = std::move(t);
228 lazy<T>& operator=(
const T& t) {
238 bool hasValue()
const noexcept {
239 return value.hasValue();
250 mutable bool value =
false;
251 std::function<void()> initializer;
253 template<
typename Factory, std::enable_if_t<std::is_invocable_r_v<
void, Factory>,
bool> = true>
254 lazy(
Factory&& initializer) noexcept : initializer(std::forward<Factory>(initializer)) {}
256 lazy(
const lazy<void>& other)
noexcept: value(other.value), initializer(other.initializer) {}
257 lazy(
lazy<void>&& other)
noexcept: value(other.value), initializer(std::move(other.initializer)) {}
272 const void operator*()
const {
282 bool hasValue()
const noexcept {
297 std::function<T()> initializer;
299 template<
typename Factory, std::enable_if_t<std::is_invocable_r_v<T, Factory>,
bool> = true>
300 atomic_lazy(
Factory&& initializer) : initializer(std::forward<Factory>(initializer)) {}
303 std::unique_lock lock(other.sync);
305 initializer = other.initializer;
308 std::unique_lock lock(other.sync);
309 value = std::move(other.value);
310 initializer = std::move(other.initializer);
315 std::unique_lock lock(sync);
317 value = initializer();
322 const T& get()
const {
329 operator const T&()
const {
336 const T& operator*()
const {
343 T
const * operator->()
const {
348 std::unique_lock lock(sync);
349 value = std::move(t);
354 std::unique_lock lock(sync);
360 std::unique_lock lock(sync);
365 bool hasValue()
const noexcept {
366 std::unique_lock lock(sync);
367 return value.hasValue();
371 namespace constraint {
387 operator T&()
const {
391 T& operator*()
const {
394 T* operator->()
const {
411 move_only(T&& rhs): value(std::move(rhs)) {
419 operator const T&()
const {
426 const T& operator*()
const {
429 const T* operator->()
const {
451 requires aui::convertible_to<
decltype(min), UnderlyingType> && aui::convertible_to<
decltype(max), UnderlyingType>
454 static constexpr auto MIN = min;
455 static constexpr auto MAX = max;
457 ranged_number(UnderlyingType value): value(glm::clamp(value,
static_cast<UnderlyingType
>(min),
static_cast<UnderlyingType
>(max))) {}
460 operator UnderlyingType()
const {
465 UnderlyingType value;
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Avoids copy of the wrapped value, pointing to a reference.
Definition: values.h:379
Wraps the object forbidding copy.
Definition: values.h:406
Concept shortcut to std::is_arithmetic_v.
Definition: concepts.h:144
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition: Assert.h:74
Basic syscall-based synchronization primitive.
Definition: AMutex.h:33
A value that initializes when accessed for the first time. Unlike aui::lazy, internal logic of aui::a...
Definition: values.h:293
A value that initializes when accessed for the first time.
Definition: values.h:248
A value that initializes when accessed for the first time.
Definition: values.h:182
Does not allow escaping, allowing to accept lvalue ref, rvalue ref, shared_ptr and etc without overhe...
Definition: values.h:127
Forbids copy of your class.
Definition: values.h:40
Definition: SharedPtrTypes.h:114
Clamps the possible values for a number to the specified range: [min;max].
Definition: values.h:452