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
◆ discard_return
|
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()
{
method meth = type::get_global_method("my_func");
std::cout << meth.get_return_type().get_name(); // prints "void"
variant var = meth.invoke(instance());
std::cout << var.is_type<void>(); // prints "true"
return 0;
}
static bind< detail::meth, detail::invalid_type, F, detail::public_access > method(string_view name, F f)
Register a method to this class.
static method get_global_method(string_view name) noexcept
Returns a global method with the name name.
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::discard_return discard_return
This policy should be used when the return value of a method should not be forwarded to the caller.
Definition: policy.h:116
◆ return_ref_as_ptr
|
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;
}
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 t...
Definition: policy.h:86
The documentation for this struct was generated from the following file:
Generated on Sun Apr 12 2020 23:39:54 for rttr - 0.9.6 by doxygen.