Use variadic template for ObjectFactory::Set
Moved from bug 2780
Partially addresses #194 (closed)
Variadic templates allow to pass an arbitrary number of arguments to ObjectFactory::Set, so that helper functions (and CreateObjectWithAttributes<T>()) can be greatly simplified and allow arbitrary number of arguments. For instance:
template<typename T>
Ptr<T>
CreateObjectWithAttributes (std::string n1, const AttributeValue & v1,
std::string n2, const AttributeValue & v2,
std::string n3, const AttributeValue & v3,
std::string n4, const AttributeValue & v4,
std::string n5, const AttributeValue & v5,
std::string n6, const AttributeValue & v6,
std::string n7, const AttributeValue & v7,
std::string n8, const AttributeValue & v8,
std::string n9, const AttributeValue & v9)
{
ObjectFactory factory;
factory.SetTypeId (T::GetTypeId ());
factory.Set (n1, v1);
factory.Set (n2, v2);
factory.Set (n3, v3);
factory.Set (n4, v4);
factory.Set (n5, v5);
factory.Set (n6, v6);
factory.Set (n7, v7);
factory.Set (n8, v8);
factory.Set (n9, v9);
return factory.Create<T> ();
}
becomes
template<typename T, typename... Args>
Ptr<T>
CreateObjectWithAttributes (Args... args)
{
ObjectFactory factory;
factory.SetTypeId (T::GetTypeId ());
factory.Set (args...);
return factory.Create<T> ();
}
I did not implement the "recursive" approach (Set consumes two arguments and calls itself), but an approach where all the name-value pairs are used to initialize a map and then set by calling the DoSet member function (which is exactly the current Set member function).
In order to show how this can be used, this MR includes a commit that modifies the traffic-control helper.
I also prepared a C++14 version of the patch, where I could avoid defining index_sequence and make_index_sequence and reuse std::index_sequence and std::make_index_sequence. I will create a separate MR for switching to C++14, unless you want it to be included here.
Note that this MR does not depend on !147 (merged)