cereal::construct&lt; T &gt;(3) Library Functions Manual cereal::construct&lt; T &gt;(3)

# [NAME](#NAME)

cereal::construct&lt; T &gt; - Used to construct types with no default constructor.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;/home/build/include/cereal/access.hpp&gt;

## [Public Member Functions](#Public_Member_Functions)

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

## [Friends](#Friends)

template&lt;class Ar, class TT&gt; struct **::cereal::memory\_detail::LoadAndConstructLoadWrapper**  
template&lt;class Ar, class TT&gt; struct **::cereal::boost\_variant\_detail::LoadAndConstructLoadWrapper**

# [Detailed Description](#Detailed_Description)

## [template&lt;class T&gt;](#template_class_T_)

class cereal::construct&lt; T &gt;"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](#Member_Function_Documentation)

## [template&lt;class T&gt; template&lt;class ... Args&gt; void **cereal::construct**&lt; T &gt;::operator() (Args &&... args) \[inline\]](#template_class_T__template_class_)

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&lt;class T&gt; T * **cereal::construct**&lt; T &gt;::operator-&gt; () \[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&lt;class T&gt; T * **cereal::construct**&lt; T &gt;::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

# [Author](#Author)

Generated automatically by Doxygen for cereal from the source code.

Sat Aug 29 2026 00:42:30 cereal

---

Document: cereal_construct(3) from cereal 1.3.2-r5 (Chainguard OS)
Source: https://github.com/USCiLab/cereal
