Variant
.9.6_doc_md_pages_tutorial_variant
The variant class acts as return value container for properties and methods. This class allows to store data of any type and convert between these types transparently. It can hold one value at a time (using containers you can hold multiple types e.g. std::vector<int>
). Remark that the content is copied into the variant class. Even raw arrays (e.g. int[10]
) are copied. When you would like to avoid copies, use pointer types or wrap your type in a std::reference_wrapper<T>
A typical usage is the following example:
using namespace rttr;
variant var;
var = 23; // copy integer
var = "Hello World"; // var contains now a std::string (implicit conversion of string literals to std::string)
var = "42"; // contains a std::string
std::cout << var.to_int(); // convert std::string to integer and prints "42"
int my_array[100];
var = my_array; // copies the content of my_array into var
Definition: access_levels.h:34
int to_int(bool *ok=nullptr) const
Returns the containing variant as an int when the type is an integer.
The variant class allows to store data of any type and convert between these types transparently.
Definition: variant.h:198
Generated on Wed Aug 19 2020 05:50:48 for rttr - 0.9.6 by doxygen.