rttr::policy::ctor Struct Reference

The ctor class groups all policies that can be used during registration of constructors. More...

#include <policy.h>

Static Public Attributes

static const detail::as_object as_object
 The as_object policy will create an instance of a class with automatic storage.
 
static const detail::as_raw_pointer as_raw_ptr
 The as_raw_ptr policy will create an instance of a class as raw pointer.
 
static const detail::as_std_shared_ptr as_std_shared_ptr
 The as_std_shared_ptr policy will create an instance of a class through std::make_shared<T>.
 

Detailed Description

The ctor class groups all policies that can be used during registration of constructors.

Member Data Documentation

◆ as_object

const detail::as_object rttr::policy::ctor::as_object
static

The as_object policy will create an instance of a class with automatic storage.

Objects with automatic storage duration are automatically destroyed when the block in which they are created exits. Which is in our case the variant. However, that means also you don't have to deal with pointers or wrappers. In order to use this creation policy, the object must be copy constructible.

See following example code:

using namespace rttr;
struct Foo
{
};
{
(
);
}
int main()
{
variant var = type::get<Foo>().create(); // creates a new instance of 'Foo' and moves the content into variant 'var'
std::cout << var.is_type<Foo>(); // prints "true"
variant var2 = var; // creates a new instance of 'Foo', through copy construction
return 0; // the memory of the two 'Foo' instances is freed automatically
}
The array_range class provides a view into an underlying data structure with lower and upper limits.
Definition array_range.h:64
The class_ is used to register classes to RTTR.
Definition registration.h:130
bind< detail::ctor, Class_Type, acc_level, Visitor_List, Args... > constructor(acc_level level=acc_level())
Register a constructor for this class type with or without arguments.
The variant class allows to store data of any type and convert between these types transparently.
Definition variant.h:199
Definition access_levels.h:34
#define RTTR_REGISTRATION
Use this macro to automatically register your reflection information to RTTR before main is called.
Definition registration.h:745
static const detail::as_object as_object
The as_object policy will create an instance of a class with automatic storage.
Definition policy.h:306

◆ as_raw_ptr

const detail::as_raw_pointer rttr::policy::ctor::as_raw_ptr
static

The as_raw_ptr policy will create an instance of a class as raw pointer.

That means the object is created with a new-expression and its lifetime lasts until it is destroyed using a delete-expression. In order to invoke the delete expression use the corresponding destructor.

See following example code:

using namespace rttr;
struct Foo
{
};
{
(
);
}
int main()
{
variant var = type::get<Foo>().create();
std::cout << var.is_type<Foo*>(); // prints "true"
var.get_type().destroy(var); // free's the memory with 'delete'
std::cout << var.is_valid(); // prints "false"
return 0;
}
static const detail::as_raw_pointer as_raw_ptr
The as_raw_ptr policy will create an instance of a class as raw pointer.
Definition policy.h:235

◆ as_std_shared_ptr

const detail::as_std_shared_ptr rttr::policy::ctor::as_std_shared_ptr
static

The as_std_shared_ptr policy will create an instance of a class through std::make_shared<T>.

That means the object is wrapped into a std::shared_ptr<T>. The wrapped object is destroyed and its memory deallocated when either of the following happens:

  • the last remaining variant owning the shared_ptr is destroyed
  • the last remaining variant owning the shared_ptr is assigned another data or variant

The object is destroyed using the default deleter of std::shared_ptr.

See following example code:

using namespace rttr;
struct Foo
{
};
{
(
);
}
int main()
{
variant var = type::get<Foo>().create();
std::cout << var.is_type<std::shared_ptr<Foo>>(); // prints "true"
return 0; // the memory for contained 'Foo' instance is freed automatically,
} // because the var object is gone out of scope
static const detail::as_std_shared_ptr as_std_shared_ptr
The as_std_shared_ptr policy will create an instance of a class through std::make_shared<T>.
Definition policy.h:271

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