Return template iterator based on argument class <p>I'm writing an algorithm function that uses iterators. This function should work with both normal and constant iterators, and importantly the class that these iterators come from is NOT a template, I know it in advance.</p> <p>Is there any way to enforce in the following definition that the iterators come from a specific class?</p> <pre><code>// This is an example, A could be any other class with exposed iterators. using A = std::vector&lt;int&gt;; // How to enforce that Iterator is an iterator from A? template &lt;typename Iterator&gt; Iterator foo(Iterator begin, Iterator end); ... A a; auto it = foo(a.begin(), a.end()); *it = 4; // Must compile // -------- const A a; auto it = foo(a.begin(), a.end()); *it = 4; // Must not compile // -------- B b; auto it = foo(b.begin(), b.end()); // Should not compile. </code></pre> <p>In this case, <code>foo</code> does not modify directly the supplied range, but allows for modification of the result iterator if the supplied range was modifiable in the first place. It would be nice if this could be done without replicating code.</p>