template <class C> auto SubRange(C& c, int pos, int count) -> decltype(SubRange(c.begin() + pos, count)) { return SubRange(c.begin() + pos, count); } template <class C> auto SubRange(C&& c, int pos, int count) -> decltype(SubRange(c.begin() + pos, count)) { return SubRange(c.begin() + pos, count); }
template <class C> auto SubRange(const C& c, int pos, int count) -> decltype(SubRange(c.begin() + pos, count)) { return SubRange(c.begin() + pos, count); }
Function SubRange has two overloads below.
template <class C> auto SubRange(C& c, int pos, int count) -> decltype(SubRange(c.begin() + pos, count)) { return SubRange(c.begin() + pos, count); } template <class C> auto SubRange(C&& c, int pos, int count) -> decltype(SubRange(c.begin() + pos, count)) { return SubRange(c.begin() + pos, count); }
The second one doesn't actually move anything, so, it is just not needed, IMHO.
The first one can always be used instead. And it should look like below. IMHO.
template <class C> auto SubRange(const C& c, int pos, int count) -> decltype(SubRange(c.begin() + pos, count)) { return SubRange(c.begin() + pos, count); }
Method begin() is always const I believe ...
And you can drop this decltype in C++14 ...
Not true (not in U++ nor STL). That is basically a reason for those 2 overloads. E.g. try Sort with just const variant...
template <class I> SubRangeClass<I> SubRange(I l, I h) { return SubRangeClass<typename std::remove_const<I>::type>(l, h); } template <class I> SubRangeClass<I> SubRange(I l, int count) { return SubRangeClass<typename std::remove_const<I>::type>(l, count); }
mirek wrote on Mon, 08 January 2018 05:52
Not true (not in U++ nor STL). That is basically a reason for those 2 overloads. E.g. try Sort with just const variant...
The "C& c" variant is definitely not needed. The "C&& c" variant is an universal reference and it is a complete replacement of the "C& c" variant. I tried to compile TheIDE with "C& c" commented out and it compiles just fine.
And I'm still a little bit confused about what is IterSwap for. What is wrong with the regular Swap?