|
pstore2
|
A helper class which remembers the first time that it is assigned to. More...
#include <common.hpp>
Public Member Functions | |
| sticky_assign (sticky_assign< T > const &rhs) | |
| Construct from a sticky_assign<T>. This is considered equivalent to assignment. | |
| template<typename Other > | |
| sticky_assign (Other const &t) | |
| Construct from a type that is implicitly convertible to T. More... | |
| sticky_assign (sticky_assign &&)=delete | |
| template<typename Other > | |
| sticky_assign & | operator= (Other const &rhs) |
| Assign from a type that is implicitly convertible to T. More... | |
| sticky_assign & | operator= (sticky_assign const &)=delete |
| sticky_assign & | operator= (sticky_assign &&)=delete |
| T const & | get () const |
A helper class which remembers the first time that it is assigned to.
This class is intended to be used to simplify loops of the general form:
result_type result;
bool is_first = true;
for (auto & v : range) {
auto r = ... produce a value ...
if (is_first) {
result = r;
}
is_first = false;
}
return result;
This rather error prone snippet of code can be replaced with:
sticky_type <result_type> r;
for (auto & v : range) {
r = ... produce a value ...
}
return r.get ();
|
inlineexplicit |
Construct from a type that is implicitly convertible to T.
This is considered equivalent to assignment.
|
inline |
Assign from a type that is implicitly convertible to T.
This assignment will take place once only: any subsequent assignments will be ignored.
1.8.13