OS Manuals

cereal_construct(3)

cereal::construct< T > - Used to construct types with no default constructor.

cereal::construct< T >(3) Library Functions Manual cereal::construct< T >(3)

cereal::construct< T > - Used to construct types with no default constructor.

#include </home/build/include/cereal/access.hpp>


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.


template<class Ar, class TT> struct ::cereal::memory_detail::LoadAndConstructLoadWrapper
template<class Ar, class TT> struct ::cereal::boost_variant_detail::LoadAndConstructLoadWrapper

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

T The class type being serialized

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

args The arguments to the constructor for T

Exceptions

Exception If called more than once

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

A reference to the initialized object

Exceptions

Exception If called before initialization

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

A raw pointer to the initialized type

Generated automatically by Doxygen for cereal from the source code.

Sat Aug 29 2026 00:42:30 cereal

cereal 1.3.2-r5 · enterprise-packages · ingested 2026-10-02