I recently found Settings in the Boost library. Honestly, I did not understand the reasons why this is part of Boost. When you need to pass several parameters to a function, you can create a structure from them, for example:
struct Parameters { Parameters() : strParam("DEFAULT"), intParam(0) {} string strParam; int intParam; }; void foo(const Parameters & params) { } Parameters params; params.intParam = 42; foo(params);
It is very easy to write and understand. Now an example using the boost parameters:
BOOST_PARAMETER_NAME(param1) BOOST_PARAMETER_NAME(param2) BOOST_PARAMETER_FUNCTION( (void), // 1. parenthesized return type someCompexFunction, // 2. name of the function template tag, // 3. namespace of tag types (optional // optional parameters, with defaults (param1, *, 42) (param2, *, std::string("default")) ) ) { std::cout << param1 << param2; } someCompexFunction(param1_=42);
I think this is really difficult, and the advantage is not so important.
But now I see that some of the Boost (Asio) libraries use this technique. Is it recommended to use this library to pass many arguments?
Or maybe there is real benefit from using this library that I don't see? Do you recommend using this library in a project?
source share