Parameter Names
As additional meta information it is possible to provide the names of arguments for methods or constructors. This information is then accessible via an object of type parameter_info.
Please take a look at following example:
using namespace rttr;
void set_window_geometry(const char* name, int w, int h) {...}
{
registration::method("set_window_geometry", &set_window_geometry)
(
);
}
The names has to a string literal (i.e. const char*) and provided via the function: parameter_names(). Place the call in the ()
operator of the returned bind object.
- Remarks
- It is not possible to provide just one name, when you use this function, you have to provide names for all arguments.
The function has following synopsis:
template<typename...TArgs>
detail::parameter_names<detail::decay_t<TArgs>...> parameter_names(TArgs&&...args)
The names can be retrieved via the parameter_info class. Take a look at the following example:
int main()
{
method meth = type::get_global_method("set_window_geometry");
std::vector<parameter_info> param_list = meth.get_parameter_infos();
for (const auto& info : param_list)
{
// print all names of the parameter types and its position in the paramter list
std::cout << " name: '" << info.get_type().get_name() << "'\n"
<< "index: " << info.get_index()
<< std::endl;
}
}
Output:
name: 'window name' index: 0 name: 'width' index: 1 name: 'height' index: 2