c++ - How can I implement a class which can be constructed with an input iterator? -


the std::vector class has convenient constructor allows input iterator parameter. implement similar pattern in own class, because class needs take in collection when instantiated, have iterator on collection encapsulation purposes. 1 way thought of template-ing whole class input iterator type, can't stl does, because vector templated type being iterated over. of course, 1 option templated generator function, i'd know how it's done compilers implement stl - somehow, inputiterator type typename specific constructor, if constructors can't templated.

(yes, have tried @ vector.tpp not understand it).

your class should have templated constructor (templated on iterator type):

class my_class {      template <typename inputiterator>     my_class(inputiterator first, inputiterator last) {         // ...     }      // ... }; 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -