2012-04-13 11:28:37 +10:00
|
|
|
/*
|
2015-04-13 18:05:28 +10:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-04-13 11:28:37 +10:00
|
|
|
*
|
2015-04-13 18:05:28 +10:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2012-04-13 11:28:37 +10:00
|
|
|
*
|
2012-04-23 13:06:41 +10:00
|
|
|
* Copyright 2010-2012 Danny Robson <danny@nerdcruft.net>
|
2012-04-13 11:28:37 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __UTIL_ITERATOR_HPP
|
|
|
|
#define __UTIL_ITERATOR_HPP
|
|
|
|
|
2012-05-25 15:19:07 +10:00
|
|
|
#include "types/traits.hpp"
|
2012-04-13 11:28:37 +10:00
|
|
|
|
|
|
|
|
|
|
|
template <typename Base>
|
|
|
|
class referencing_iterator {
|
|
|
|
protected:
|
|
|
|
typedef typename std::enable_if<
|
|
|
|
is_dereferencable<
|
|
|
|
typename Base::value_type
|
|
|
|
>::value,
|
|
|
|
typename Base::value_type
|
|
|
|
>::type base_value_type;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef typename dereferenced_type<base_value_type>::type value_type ;
|
|
|
|
typedef typename Base::difference_type difference_type ;
|
|
|
|
typedef value_type& reference ;
|
|
|
|
typedef value_type* pointer;
|
2015-04-13 18:06:08 +10:00
|
|
|
typedef typename Base::iterator_category iterator_category;
|
2012-04-13 11:28:37 +10:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Base m_base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit referencing_iterator (Base _base):
|
|
|
|
m_base (_base)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
referencing_iterator& operator++() { ++m_base; return *this; }
|
|
|
|
referencing_iterator operator++(int) { auto val = *this; ++m_base; return val; }
|
|
|
|
|
|
|
|
bool operator== (const referencing_iterator<Base> &rhs) { return m_base == rhs.m_base; }
|
|
|
|
bool operator!= (const referencing_iterator<Base> &rhs) { return m_base != rhs.m_base; }
|
|
|
|
bool operator>= (const referencing_iterator<Base> &rhs) { return m_base >= rhs.m_base; }
|
|
|
|
bool operator<= (const referencing_iterator<Base> &rhs) { return m_base <= rhs.m_base; }
|
|
|
|
bool operator> (const referencing_iterator<Base> &rhs) { return m_base > rhs.m_base; }
|
|
|
|
bool operator< (const referencing_iterator<Base> &rhs) { return m_base < rhs.m_base; }
|
|
|
|
|
2015-01-10 20:07:39 +11:00
|
|
|
const value_type& operator*() const
|
2012-04-13 11:28:37 +10:00
|
|
|
{ return **m_base; }
|
|
|
|
reference operator*()
|
|
|
|
{ return **m_base; }
|
|
|
|
|
|
|
|
difference_type operator-(const referencing_iterator<Base>& rhs) const { return m_base - rhs.m_base; }
|
|
|
|
referencing_iterator<Base> operator-(int rhs) const { return referencing_iterator (m_base - rhs); }
|
|
|
|
referencing_iterator<Base> operator+(int rhs) const { return referencing_iterator (m_base + rhs); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|