| cereal::construct< T >(3) | Library Functions Manual | cereal::construct< T >(3) |
NAME
cereal::construct< T > - Used to construct types with no default constructor.
SYNOPSIS
#include </home/build/include/cereal/access.hpp>
Public Member Functions
template<class ... Args> void operator() (Args
&&... args)
Construct and initialize the type T with the given arguments. T *
operator-> ()
Get a reference to the initialized underlying object. T * ptr ()
Returns a raw pointer to the initialized underlying object.
Friends
template<class Ar, class TT> struct
::cereal::memory_detail::LoadAndConstructLoadWrapper
template<class Ar, class TT> struct
::cereal::boost_variant_detail::LoadAndConstructLoadWrapper
Detailed Description
template<class T>
class cereal::construct< T >"Used to construct types with no default constructor.
When serializing a type that has no default constructor, cereal will attempt to call either the class static function load_and_construct or the appropriate template specialization of LoadAndConstruct. cereal will pass that function a reference to the archive as well as a reference to a construct object which should be used to perform the allocation once data has been appropriately loaded.
struct MyType
{
// note the lack of default constructor
MyType( int xx, int yy );
int x, y;
double notInConstructor;
template <class Archive>
void serialize( Archive & ar )
{
ar( x, y );
ar( notInConstructor );
}
template <class Archive>
static void load_and_construct( Archive & ar, cereal::construct<MyType> & construct )
{
int x, y;
ar( x, y );
// use construct object to initialize with loaded data
construct( x, y );
// access to member variables and functions via -> operator
ar( construct->notInConstructor );
// could also do the above section by:
double z;
ar( z );
construct->notInConstructor = z;
}
};
Template Parameters
Member Function Documentation
template<class T> template<class ... Args> void cereal::construct< T >::operator() (Args &&... args) [inline]
Construct and initialize the type T with the given arguments. This will forward all arguments to the underlying type T, calling an appropriate constructor.
Calling this function more than once will result in an exception being thrown.
Parameters
Exceptions
template<class T> T * cereal::construct< T >::operator-> () [inline]
Get a reference to the initialized underlying object. This must be called after the object has been initialized.
Returns
Exceptions
template<class T> T * cereal::construct< T >::ptr () [inline]
Returns a raw pointer to the initialized underlying object. This is mainly intended for use with passing an instance of a constructed object to cereal::base_class.
It is strongly recommended to avoid using this function in any other circumstance.
Returns
Author
Generated automatically by Doxygen for cereal from the source code.
| Mon Oct 26 2026 02:55:37 | cereal |