tags:

views:

38

answers:

1

I'm currently reading the Boost.Program_options tutorial.

Here is some of the code they introduce:

// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
    ("help", "produce help message")
    ("compression", po::value<int>(), "set compression level")
;

I understand the purpose behind this code, however the syntax confuses me. Are the indented lines arguments to a function? What is with the brackets?

+1  A: 

I suppose desc.get_options() returns an object of a class that defines operator() which in turn returns the same object. So the indented lines are calls to this operator with arguments in brackets.

Looking at boost/program_options/options_description.hpp you can see that the class in question is options_description_easy_init which indeed has several operator()'s such as:

    options_description_easy_init&
    operator()(const char* name,
               const char* description);
vitaut
This is typically referred to as a functor.
Sam Miller
@Sam Miller: Right, a functor or a function object.
vitaut