Re: filling vectors in the parameter list
{
vector<string> v(3);
v.push_back("str1");
v.push_back("str2");
v.push_back("str3");
foo(v);
}
Yes I think this is the easiest but number 3 can change then I can
supply that as a parameter but the problem is that how will I get
number of push_backs.
If you find this too verbose you can write a vector_filler<> class
template to fill a vector via an overloaded << operator (like streams do.)
template <typename T, typename A = std::allocator<T> >
class vector_filler
{
std::vector<T, A> v;
public:
const std::vector<T, A>& vec() const{return v;}
std::vector<T,A>& vec(){return v;}
template <typename U>
vector_filler&
operator<<(const U& u){v.push_back(u);}
};
vector_filler<string> vf;
vf << "str1" << "str2" << "str3";
foo(vf.vec());
I will examine this one, this is sth more professional
vector<string> v = {"str1", "str2", "str3"};
foo(v);
Or
foo({"str1", "str2", "str3"});
I hope it is true.
I also hope for that.
Regards