However, with a crafty trick and with some little inconvenience, it is possible to emulate is. The example below shows how to do it.
class namedFn { int _id; double _val; int _dim; public: namedFn() : _id(0), _val(1), _dim(2) {} namedFn& id(int p) { _id = p ; return *this; } namedFn& val(double p) { _val = p ; return *this; } namedFn& dim(int p) { _dim = p ; return *this; } run() { std::cout << "Here comes the function itself\n" << << "With parameters " << _id << ", " << _val << ", " << _dim << std::endl; } };
Then you can use it like this.
namedFn().id(3).val(2).run();
The trick is obvious, each "named parameter" changes one component of the underlying class, then gives back a reference to it. Finally, run()
executes the algorithm itself.
NamedFn
.
In fact, the final .run()
could be made unnecessary, because the algorithm could also be implemented in the destructor of namedFn
instead. This however would make it impossible to implement functions with return values, and would also cause serious problems when implementing named template parameters. Therefore, by convention, .run()
must be used explicitly to execute a function having named parameters everywhere in LEMON.
You will probably never need to know how it works, but if you really committed, have a look at lemon/graph_to_eps.h for an example.
See lemon::DijkstraDefaultTraits for an example how a traits class implementation looks like.
Dijkstra<>::SetPredMap<NullMap<Node,Arc> >::Create
It can also be used in conjunction with other named template parameters in arbitrary order.
Dijkstra<>::SetDistMap<MyMap>::SetPredMap<NullMap<Node,Arc> >::Create
The result will be an instantiated Dijkstra class, in which the DistMap and the PredMap is modified.