Parameter Names

.9.6_doc_md_pages_tutorial_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)
(
parameter_names("window name", "width", "height")
);
}

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

detail::parameter_names< detail::decay_t< TArgs >... > parameter_names(TArgs &&...args)
The parameter_names function should be used add human-readable names of the parameters,...
Definition: access_levels.h:34
static bind< detail::meth, detail::invalid_type, F, detail::public_access > method(string_view name, F f)
Register a method to this class.
#define RTTR_REGISTRATION
Use this macro to automatically register your reflection information to RTTR before main is called.
Definition: registration.h:745