rttr::policy::meth Struct Reference
The meth class groups all policies that can be used during registration of methods. More...
#include <policy.h>
Static Public Attributes | |
static const detail::discard_return | discard_return |
This policy should be used when the return value of a method should not be forwarded to the caller. More... | |
static const detail::return_as_ptr | return_ref_as_ptr |
This policy can be used when a method return a reference to an object and the caller should be able to access this object via the returned variant. More... | |
Detailed Description
The meth class groups all policies that can be used during registration of methods.
Member Data Documentation
|
static |
This policy should be used when the return value of a method should not be forwarded to the caller.
For the caller it looks like the method has no return value, the return type will be void.
See following example code:
using namespace rttr;
int my_func() { return 42; }
{
registration::method("my_func", &my_func)
(
);
}
int main()
{
return 0;
}
|
static |
This policy can be used when a method return a reference to an object and the caller should be able to access this object via the returned variant.
Reference cannot be copied directly in a variant, therefore it is possible transform the reference to a pointer.
See following example code:
std::string& get_text() { static std:string text("hello world"); return text; }
{
registration::method("get_text", &get_text)
(
);
}
int main()
{
method meth = type::get_global_method("get_text");
std::cout << meth.get_return_type().get_name(); // prints "std::string*"
variant var = meth.invoke(instance());
std::cout << var.is_type<std::string*>(); // prints "true"
return 0;
}
The documentation for this struct was generated from the following file: