prime/include/rstl/iterator.hpp

43 lines
1.0 KiB
C++
Raw Permalink Normal View History

2022-11-17 15:46:10 +00:00
#ifndef _RSTL_ITERATOR
#define _RSTL_ITERATOR
namespace rstl {
struct input_iterator_tag {};
struct output_iterator_tag {};
struct forward_iterator_tag : public input_iterator_tag {};
struct bidirectional_iterator_tag : public forward_iterator_tag {};
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
template < typename It >
typename It::difference_type __distance(It first, It last, forward_iterator_tag) {
typename It::difference_type result = 0;
It it = first;
while (it != last) {
++result;
++it;
}
return result;
}
template < typename It >
2022-11-27 23:26:24 +00:00
inline typename It::difference_type distance(It first, It last) {
2022-11-17 15:46:10 +00:00
return __distance(first, last, typename It::iterator_category());
}
template < typename It, typename S >
void __advance(It& it, S count, forward_iterator_tag) {
while (count > 0) {
++it;
}
}
template < typename It, typename S >
inline void advance(It& it, S count) {
return __advance(it, count, typename It::iterator_category());
}
2022-11-17 15:46:10 +00:00
} // namespace rstl
#endif // _RSTL_ITERATOR