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)");
134 no_escape(T& value): value(&value) {
135 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
139 no_escape(T&& value): value(&value) {
140 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
142 no_escape(T* value): value(value) {
143 AUI_ASSERTX(no_escape::value !=
nullptr,
"the argument could not be null");
146 no_escape(
const _<T>& value): value(&*value) {
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 {
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 {
224 lazy<T>& operator=(T&& t) {
225 value = std::move(t);
228 lazy<T>& operator=(
const T& t) {
242 bool hasValue()
const noexcept {
243 return value.hasValue();
254 mutable bool value =
false;
255 std::function<void()> initializer;
257 template<
typename Factory, std::enable_if_t<std::is_invocable_r_v<
void, Factory>,
bool> = true>
258 lazy(
Factory&& initializer) noexcept : initializer(std::forward<Factory>(initializer)) {}
260 lazy(
const lazy<void>& other)
noexcept: value(other.value), initializer(other.initializer) {}
261 lazy(lazy<void>&& other)
noexcept: value(other.value), initializer(std::move(other.initializer)) {}
270 return const_cast<lazy<void>*
>(
this)->get();
276 const void operator*()
const {
286 bool hasValue()
const noexcept {
301 std::function<T()> initializer;
303 template<
typename Factory, std::enable_if_t<std::is_invocable_r_v<T, Factory>,
bool> = true>
304 atomic_lazy(
Factory&& initializer) : initializer(std::forward<Factory>(initializer)) {}
306 atomic_lazy(
const atomic_lazy<T>& other) {
307 std::unique_lock lock(other.sync);
309 initializer = other.initializer;
311 atomic_lazy(atomic_lazy<T>&& other)
noexcept {
312 std::unique_lock lock(other.sync);
313 value = std::move(other.value);
314 initializer = std::move(other.initializer);
319 std::unique_lock lock(sync);
321 value = initializer();
326 const T& get()
const {
327 return const_cast<atomic_lazy<T>*
>(
this)->get();
333 operator const T&()
const {
340 const T& operator*()
const {
347 T
const * operator->()
const {
351 atomic_lazy<T>& operator=(T&& t) {
352 std::unique_lock lock(sync);
353 value = std::move(t);
357 atomic_lazy<T>& operator=(
const T& t) {
358 std::unique_lock lock(sync);
364 std::unique_lock lock(sync);
369 bool hasValue()
const noexcept {
370 std::unique_lock lock(sync);
371 return value.hasValue();
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition Assert.h:74