Thanks for the comments, just had a question about one of them… Jonathan Wakely <jwak...@redhat.com> writes: > On 16/06/20 15:14 +0100, Richard Sandiford wrote: >>Martin Li?ka <mli...@suse.cz> writes: >>> On 6/16/20 10:50 AM, Richard Sandiford wrote: >>> Hmm, sounds like a nice abstraction but I see 2 problems with that: >>> >>> 1) How can I define a constructor of the iterator_pair when I need >>> something like: >>> iterator_pair<const_iterator> (region_begin, region_end)? >> >>Not sure if I'm answering the right question, sorry, but I meant >>something along the lines of: >> >> template<typename T> >> struct iterator_pair >> { >> public: >> iterator_pair (const T &begin, const T &end) >> : m_begin (begin), m_end (end) {} >> >> T begin () const { return m_begin; } >> T end () const { return m_end; } >> >> private: >> T m_begin; >> T m_end; >> }; > > You could also add an "object generator" for that type: > > template<typename T> > iterator_range<T> > make_iterator_range(T begin, T end) > { > return iterator_range<T>(begin, end); > } > > This deduces the type T from the function arguments, so will allow you > to write: > > return make_iterator_range(x, y); > > instead of: > > return iterator_range<const_iterator>(x, y); > > i.e. you don't need to say <const_iterator> because the compiler can > deduce it from the arguments.
In Martin's case the x and y arguments don't naturally have type const_iterator, so I guess this would become: return make_iterator_range (const_iterator (x), const_iterator (y)); Is that more idiomatic than: return iterator_range<const_iterator> (x, y); ? Richard