.TH "cereal::LoadAndConstruct< T >" 3 "Mon Oct 26 2026 02:55:37" "cereal" \" -*- nroff -*- .ad l .nh .SH NAME cereal::LoadAndConstruct< T > \- A class that allows cereal to load smart pointers to types that have no default constructor\&. .SH SYNOPSIS .br .PP .PP \fR#include \fP .SH "Detailed Description" .PP .SS "template .br struct cereal::LoadAndConstruct< T >"A class that allows cereal to load smart pointers to types that have no default constructor\&. If your class does not have a default constructor, cereal will not be able to load any smart pointers to it unless you overload \fBLoadAndConstruct\fP for your class, and provide an appropriate load_and_construct method\&. You can also choose to define a member static function instead of specializing this class\&. .PP The specialization of \fBLoadAndConstruct\fP must be placed within the cereal namespace: .PP .PP .nf struct MyType { MyType( int x ); // note: no default ctor int myX; // Define a serialize or load/save pair as you normally would template void serialize( Archive & ar ) { ar( myX ); } }; // Provide a specialization for LoadAndConstruct for your type namespace cereal { template <> struct LoadAndConstruct { // load_and_construct will be passed the archive that you will be loading // from as well as a construct object which you can use as if it were the // constructor for your type\&. cereal will handle all memory management for you\&. template static void load_and_construct( Archive & ar, cereal::construct & construct ) { int x; ar( x ); construct( x ); } // if you require versioning, simply add a const std::uint32_t as the final parameter, e\&.g\&.: // load_and_construct( Archive & ar, cereal::construct & construct, std::uint32_t const version ) }; } // end namespace cereal .fi .PP .PP Please note that just as in using external serialization functions, you cannot get access to non-public members of your class by befriending \fBcereal::access\fP\&. If you have the ability to modify the class you wish to serialize, it is recommended that you use member serialize functions and a static member load_and_construct function\&. .PP load_and_construct functions, regardless of whether they are static members of your class or whether you create one in the \fBLoadAndConstruct\fP specialization, have the following signature: .PP .PP .nf // generally Archive will be templated, but it can be specific if desired template static void load_and_construct( Archive & ar, cereal::construct & construct ); // with an optional last parameter specifying the version: const std::uint32_t version .fi .PP .PP Versioning behaves the same way as it does for standard serialization functions\&. .PP \fBTemplate Parameters\fP .RS 4 \fIT\fP The type to specialize for .RE .PP .SH "Author" .PP Generated automatically by Doxygen for cereal from the source code\&.