I have a class that contains a vector:
class Foo {
typdef std::vector<int> Vec;
Vec m_kids;
void addKids(Vec::const_iterator begin,
Vec::const_iterator end) {
m_kids.insert(m_kids.end(), begin, end);
}
};
Is there any way to allow the following concise function calls? (Maybe by changing the addKids function above?)
int main() {
Foo foo;
foo.addKids(23,51,681); // these...
foo.addKids(3,6,1,4,88,2,4,-2,101); // ...would be nice?!
}
I suspect you can do it with C++0x vector initializer lists? But unfortunately, I cannot use C++0x. I can use Boost, though, if that helps.
You can do this:
For that you’ve to overloaded
<<and,operators, as:Once you implement this, then you can also write:
Even this,
Or mix both as:
All are same!
But mixing doesn’t look good. My preference is the very first one!