Discussion:
Is it possible somehow to cast one iterator category for another iterator category of an iterator?
(too old to reply)
'Vlad from Moscow' via ISO C++ Standard - Discussion
2018-11-07 14:04:33 UTC
Permalink
Let's assume that there are two template functions

template <typename InputIterator>
void f( InputIterator first, InputIterator last )

requires std::is_same_v<typename std::iterator_traits<InputIterator>::
iterator_category, std::input_iterator_tag>;



and

template <typename ForwardIterator>
void f( ForwardIterator first, ForwardIterator last )

requires std::is_same_v<typename std::iterator_traits<ForwardIterator>::
iterator_category, std::forward_iterator_tag>;


And inside the body of the second function there is present the duplicated
code of the whole body of the first function.

Is it possible to call somehow the first function from the body of the
second function?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
T. C.
2018-11-08 22:33:06 UTC
Permalink
Well, you can design a demoting wrapper. But it seems that the actual
problem is with the constraint.
Post by 'Vlad from Moscow' via ISO C++ Standard - Discussion
Let's assume that there are two template functions
template <typename InputIterator>
void f( InputIterator first, InputIterator last )
iterator_category, std::input_iterator_tag>;
and
template <typename ForwardIterator>
void f( ForwardIterator first, ForwardIterator last )
requires std::is_same_v<typename std::iterator_traits<ForwardIterator
::iterator_category, std::forward_iterator_tag>;
And inside the body of the second function there is present the duplicated
code of the whole body of the first function.
Is it possible to call somehow the first function from the body of the
second function?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
b***@gmail.com
2018-11-12 14:36:09 UTC
Permalink
Post by T. C.
Well, you can design a demoting wrapper. But it seems that the actual
problem is with the constraint.
+1. You don't want to write a constraint that your iterator is EXACTLY this
particular category.

The One Ranges proposal was just voted to be adopted into C++20 last week,
and you can see what its iterator concepts look like
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0896r3.pdf is the
latest public draft). For example, the ForwardIterator concept requires
DerivedFrom<ITER_CONCEPT(I), forward_iterator_tag>, not
Same<ITER_CONCEPT(I), forward_iterator_tag>. You'd want to write:

template <InputIterator It>
void f(It, It);

template <ForwardIterator It>
void f(It, It); // this one refines the earlier one

If my iterator is *just* an input iterator, the first one gets called. If
it's also a forward iterator, the second one. You don't want to prevent me
from calling f with two pointers, for instance.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Continue reading on narkive:
Loading...