I am making a class which is a kind of container and I would like to make a constructor that can take a “first” and “last” iterator like std::vector and other standard containers. What would be the correct syntax ? (I want a template a function that can take any first/last iterator types available (like the standard library I think). Thank you very much !
As an example, I want something like that :
template<class ...> MyClass(... first, ... last)
But what are the … ?
Thank you very much.
Regarding the first answer :
I want a specific constructor that takes iterators as argument (because I have already constructors that take values and pointers as arguments)
EDIT :
Is something like this ok ?
template<class T1, class T2> MyClass(std::iterator<T1, T2> first, std::iterator<T1, T2> last)
I think that you can do what you want by taking advantage of the fact that
std::iterator‘s have a member namediterator_category. Combine this with SFINAE and you get something like the following:This prints: