pilfer
Indicate that an object t
may be pilfered from.
Synopsis
Defined in header <boost/json/pilfer.hpp>.
template<
class T>
typename std::conditional< std::is_nothrow_constructible< typename std::remove_reference< T >::type, pilfered< typename std::remove_reference< T >::type > >::value &&! std::is_nothrow_constructible< typename std::remove_reference< T >::type, detail_pilfer::not_pilfered< typename std::remove_reference< T >::type > >::value, pilfered< typename std::remove_reference< T >::type >, typename std::remove_reference< T >::type && >::type
pilfer(
T&& t) noexcept;
Description
A pilfer operation is the construction of a new object of type T
from an existing object t
. After the construction, the only valid operation on the pilfered-from object is destruction. This permits optimizations beyond those available for a move-construction, as the pilfered-from object is not required to be in a "usable" state.
This is used similarly to std::move
.
Example
A pilfer constructor accepts a single argument of type pilfered
and throws nothing:
struct T
{
T( pilfered<T> ) noexcept;
};
Pilfer construction is performed using pilfer
:
{
T t1; // default construction
T t2( pilfer( t1 ) ); // pilfer-construct from t1
// At this point, t1 may only be destroyed
}
See Also
Convenience header <boost/json.hpp>