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() { printf("Here is the function itself."); } };
The usage is the following.
We have to define a class, let's call it namedFn
. Let us assume that we would like to use a parameter, called X
. In the namedFn
class we have to define an _X
attribute, and a function X
. The function expects a parameter with the type of _X
, and sets the value of _X
. After setting the value the function returns the class itself. The class also have to have a function, called for example run()
, we have to implement here the original function itself. The constructor of the class have to give all the attributes like _X
the default values of them.
If we instantiate this class, the default values will be set for the attributes (originally the parameters), initially. If we call function X
, we get a class with the modified parameter value of X
. Therefore we can modify any parameter-value, independently from the order. To run the algorithm we have to call the run()
function at the end of the row.
Example:
namedFn().id(3).val(2).run();
NamedFn
.
In fact, the final .run()
could be made unnecessary if the actual function code were put in the destructor instead. This however would make hard to implement functions with return values, and would also make the implementation of named template parameters very problematic. Therefore, by convention, .run()
must be used to explicitly execute function having named parameters in Lemon.
Dijkstra<>::SetPredNodeMap<NullMap<Node,Node> >::Create
It can also be used in conjunction with other named template parameters in arbitrary order.
Dijkstra<>::SetDistMap<MyMap>::SetPredMap<NullMap<Node,Edge> >::Create
The result will be an instantiated Dijkstra class, in which the DistMap and the PredMap is modified.