I would like a C++ constructor/method to be able to take any container as argument.
In C# this would be easy by using IEnumerable, is there an equivalent in C++/STL ?
Anthony
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The C++ way to do this is with iterators. Just like all the
<algorithm>functions that take(it begin, it end, )as first two parameters.If you really want to go passing the container itself to the function, you have to use ‘template template’ parameters. This is due to the fact that C++ standard library containers are not only templated with the type of the contained type, but also with an allocator type, that have a default value and is therefore implicit and not known.