|
CGRA-ME
|
#include <memory>#include <mutex>Go to the source code of this file.
Classes | |
| struct | LazyPointer< Gen, Value_ > |
| struct | LazyPointer< Gen, Value_ > |
| struct | AlwaysFalse |
| struct | AlwaysTrue |
| struct | DoNothing |
Functions | |
| template<typename Gen , typename Value = std::remove_cv_t<std::remove_reference_t<decltype(std::declval<Gen>()())>> | |
| auto | lazy_pointer (Gen &&g) |
| template<typename T > | |
| auto | returnsIfEqualTo (T t) |
| auto lazy_pointer | ( | Gen && | g | ) |
Construct a 'lazy pointer' – won't call g until operator* or operator-> is used, and it will only call it once. Be very careful around capture lifetimes. Otherwise, this class behaves like a std::unique_ptr that propagates const to it's stored object.
Ex. struct S { int i; }; auto l1 = lazy_pointer([]() -> S { std::cout << "l1 computed! "; return {4}; }); std::cout << l1->i << l1->i << '
'; // prints "l1 computed! 44"; auto l3 = lazy_pointer([]{ std::cout << "l3 computed! "; return 5; }); std::cout << *l3 << *l3 << '
'; // prints "l3 comptuted! 55"
Note: using a plain function pointer for the generator will result in a compile error about not being able to declare a mutable function pointer. To fix this, simply wrap your function pointer in a lambda.
Definition at line 42 of file Functional.h.
| auto returnsIfEqualTo | ( | T | t | ) |
Makes a unary function object that will return true if the argument is equal to t. (ie. the result of operator==) A copy of t is made and stored in the function object.
Definition at line 108 of file Functional.h.
1.8.17