cereal::construct< T > Class Template Reference

Used to construct types with no default constructor. More...

`#include </home/shane/workspace/cereal/include/cereal/access.hpp>`

## Public Member Functions

template<class ... Args>
void | operator() (Args &&... args)
| Construct and initialize the type T with the given arguments. More...
T * | operator-> ()
| Get a reference to the initialized underlying object. More...
T * | ptr ()
| Returns a raw pointer to the initialized underlying object. More...

## 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

  T | The class type being serialized

## Member Function Documentation

## operator()()

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

  args | The arguments to the constructor for T

Exceptions

  Exception | If called more than once

## operator->()

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

## ptr()

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

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

- /home/shane/workspace/cereal/include/cereal/access.hpp

cereal::construct
Used to construct types with no default constructor.
Definition: access.hpp:164
cereal::serialize
void serialize(Archive &, std::less< T > &)
Saving for std::less.
Definition: functional.hpp:39