pstore2
Public Member Functions | List of all members
pstore::serialize::sticky_assign< T > Class Template Reference

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_assignoperator= (Other const &rhs)
 Assign from a type that is implicitly convertible to T. More...
 
sticky_assignoperator= (sticky_assign const &)=delete
 
sticky_assignoperator= (sticky_assign &&)=delete
 
T const & get () const
 

Detailed Description

template<typename T>
class pstore::serialize::sticky_assign< T >

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 ();  

Constructor & Destructor Documentation

◆ sticky_assign()

template<typename T>
template<typename Other >
pstore::serialize::sticky_assign< T >::sticky_assign ( Other const &  t)
inlineexplicit

Construct from a type that is implicitly convertible to T.

This is considered equivalent to assignment.

Member Function Documentation

◆ operator=()

template<typename T>
template<typename Other >
sticky_assign& pstore::serialize::sticky_assign< T >::operator= ( Other const &  rhs)
inline

Assign from a type that is implicitly convertible to T.

This assignment will take place once only: any subsequent assignments will be ignored.


The documentation for this class was generated from the following file: