|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TCG_ANY_ITERATOR_H
|
|
Toshihiro Shimizu |
890ddd |
#define TCG_ANY_ITERATOR_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "base.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
\file any_iterator.h
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\brief This file contains the implementation of a type-erased iterator
|
|
Shinya Kitaoka |
120a6e |
template class.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\details Type erasure is a C++ idiom about allocating an interface
|
|
Shinya Kitaoka |
120a6e |
to an object who is then hidden as the interface's implementation
|
|
Shinya Kitaoka |
120a6e |
detail.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
The cost of using a type-erased object instead of its actual type is
|
|
Shinya Kitaoka |
120a6e |
typically
|
|
Shinya Kitaoka |
120a6e |
measured in a heap access at construction and destruction, and one
|
|
Shinya Kitaoka |
120a6e |
virtual
|
|
Toshihiro Shimizu |
890ddd |
function call per method invocation.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
A type-erased iterator can be useful to hide implementation details
|
|
Shinya Kitaoka |
120a6e |
about container
|
|
Shinya Kitaoka |
120a6e |
choices, yet providing an iterator-like interface to access the
|
|
Shinya Kitaoka |
120a6e |
stored data.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TCG_RVALUES_SUPPORT
|
|
Toshihiro Shimizu |
890ddd |
#include <boost config.hpp=""></boost>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef BOOST_NO_RVALUE_REFERENCES
|
|
Toshihiro Shimizu |
890ddd |
#define TCG_RVALUES_SUPPORT 0
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define TCG_RVALUES_SUPPORT 1
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace tcg {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// any_iterator_concept (ie the interface)
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename dist="" typename="" val,="" valptr,="" valref,=""></typename>
|
|
Shinya Kitaoka |
120a6e |
class any_iterator_concept {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
virtual ~any_iterator_concept() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual any_iterator_concept *clone() const = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual ValRef operator*() const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual ValPtr operator->() const = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual bool operator==(const any_iterator_concept &other) const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual bool operator!=(const any_iterator_concept &other) const = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual void operator++() = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual any_iterator_concept *operator++(int) {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual void operator--() { assert(false); }
|
|
Shinya Kitaoka |
120a6e |
virtual any_iterator_concept *operator--(int) {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual bool operator<(const any_iterator_concept &) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
virtual bool operator>(const any_iterator_concept &) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
virtual bool operator<=(const any_iterator_concept &) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
virtual bool operator>=(const any_iterator_concept &) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual any_iterator_concept *operator+(Dist) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
virtual void operator+=(Dist d) { assert(false); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual any_iterator_concept *operator-(Dist) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
virtual void operator-=(Dist d) { assert(false); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual Dist operator-(const any_iterator_concept &) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual ValRef operator[](Dist) const {
|
|
Shinya Kitaoka |
120a6e |
assert(false);
|
|
Shinya Kitaoka |
120a6e |
return *(Val *)0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// any_iterator_model (ie the concrete interface implementations)
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template
|
|
Shinya Kitaoka |
120a6e |
typename ValPtr, typename Dist>
|
|
Toshihiro Shimizu |
890ddd |
class any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
: public any_iterator_concept<val, dist="" valptr,="" valref,=""> {</val,>
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator_concept<val, dist="" valptr,="" valref,=""> any_it_concept;</val,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
any_iterator_model() : m_it() {}
|
|
Shinya Kitaoka |
120a6e |
any_iterator_model(const It &it) : m_it(it) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_it_concept *clone() const {
|
|
Shinya Kitaoka |
120a6e |
return new any_iterator_model<it, dist="" iterator_cat,="" val,="" valptr,="" valref,="">(</it,>
|
|
Shinya Kitaoka |
120a6e |
*this);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ValRef operator*() const { return m_it.operator*(); }
|
|
Shinya Kitaoka |
120a6e |
ValPtr operator->() const { return m_it.operator->(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool operator==(const any_it_concept &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_it == static_cast<const &="" any_iterator_model="">(other).m_it;</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator!=(const any_it_concept &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_it != static_cast<const &="" any_iterator_model="">(other).m_it;</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void operator++() { ++m_it; }
|
|
Shinya Kitaoka |
120a6e |
any_it_concept *operator++(int) {
|
|
Shinya Kitaoka |
120a6e |
return new any_iterator_model<it, dist="" iterator_cat,="" val,="" valptr,="" valref,="">(</it,>
|
|
Shinya Kitaoka |
120a6e |
m_it++);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
It m_it;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template
|
|
Shinya Kitaoka |
120a6e |
typename Dist>
|
|
Shinya Kitaoka |
120a6e |
class any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValPtr, Dist>
|
|
Shinya Kitaoka |
120a6e |
: public any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValPtr, Dist> {
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator_concept<val, dist="" valptr,="" valref,=""> any_it_concept;</val,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
using any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
Dist>::m_it;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
any_iterator_model() {}
|
|
Shinya Kitaoka |
120a6e |
any_iterator_model(const It &it)
|
|
Shinya Kitaoka |
120a6e |
: any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
Dist>(it) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_it_concept *clone() const {
|
|
Shinya Kitaoka |
120a6e |
return new any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValRef, ValPtr, Dist>(*this);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void operator--() { --m_it; }
|
|
Shinya Kitaoka |
120a6e |
any_it_concept *operator--(int) {
|
|
Shinya Kitaoka |
120a6e |
return new any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValRef, ValPtr, Dist>(m_it--);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template
|
|
Shinya Kitaoka |
120a6e |
typename Dist>
|
|
Shinya Kitaoka |
120a6e |
class any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValPtr, Dist>
|
|
Shinya Kitaoka |
120a6e |
: public any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValRef, ValPtr, Dist> {
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator_concept<val, dist="" valptr,="" valref,=""> any_it_concept;</val,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
using any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
Dist>::m_it;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
any_iterator_model() {}
|
|
Shinya Kitaoka |
120a6e |
any_iterator_model(const It &it)
|
|
Shinya Kitaoka |
120a6e |
: any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValPtr, Dist>(it) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_it_concept *clone() const {
|
|
Shinya Kitaoka |
120a6e |
return new any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValRef, ValPtr, Dist>(*this);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool operator<(const any_it_concept &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_it < static_cast<const &="" any_iterator_model="">(other).m_it;</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator>(const any_it_concept &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_it > static_cast<const &="" any_iterator_model="">(other).m_it;</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator<=(const any_it_concept &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_it <= static_cast<const &="" any_iterator_model="">(other).m_it;</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator>=(const any_it_concept &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_it >= static_cast<const &="" any_iterator_model="">(other).m_it;</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_it_concept *operator+(Dist d) const {
|
|
Shinya Kitaoka |
120a6e |
return new any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValRef, ValPtr, Dist>(m_it + d);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void operator+=(Dist d) { m_it += d; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_it_concept *operator-(Dist d) const {
|
|
Shinya Kitaoka |
120a6e |
return new any_iterator_model
|
|
Shinya Kitaoka |
120a6e |
ValRef, ValPtr, Dist>(m_it - d);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void operator-=(Dist d) { m_it -= d; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Dist operator-(const any_it_concept &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_it - static_cast<const &="" any_iterator_model="">(other).m_it;</const>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ValRef operator[](Dist d) const { return m_it[d]; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// any_iterator (ie the wrapper to the interface)
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template
|
|
Shinya Kitaoka |
120a6e |
typename ValRef = Val &, typename ValPtr = Val *,
|
|
Shinya Kitaoka |
120a6e |
typename Dist = std::ptrdiff_t>
|
|
Toshihiro Shimizu |
890ddd |
class any_iterator
|
|
Shinya Kitaoka |
120a6e |
: public std::iterator<iterator_cat, dist,="" val,="" valptr,="" valref=""> {</iterator_cat,>
|
|
Shinya Kitaoka |
120a6e |
any_iterator_concept<val, dist="" valptr,="" valref,=""> *m_model;</val,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
any_iterator() : m_model(0) {}
|
|
Shinya Kitaoka |
120a6e |
any_iterator(any_iterator_concept<val, dist="" valptr,="" valref,=""> *model)</val,>
|
|
Shinya Kitaoka |
120a6e |
: m_model(model) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
template <typename it=""></typename>
|
|
Shinya Kitaoka |
120a6e |
any_iterator(const It &it)
|
|
Shinya Kitaoka |
120a6e |
: m_model(
|
|
Shinya Kitaoka |
120a6e |
new any_iterator_model<it, dist="" iterator_cat,="" val,="" valptr,="" valref,="">(</it,>
|
|
Shinya Kitaoka |
120a6e |
it)) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_iterator(const any_iterator &other) : m_model(other.m_model->clone()) {}
|
|
Shinya Kitaoka |
120a6e |
any_iterator &operator=(any_iterator other) {
|
|
Shinya Kitaoka |
120a6e |
swap(*this, other);
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~any_iterator() { delete m_model; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
friend void swap(any_iterator &a, any_iterator &b) {
|
|
Shinya Kitaoka |
120a6e |
std::swap(a.m_model, b.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ValRef operator*() const { return m_model->operator*(); }
|
|
Shinya Kitaoka |
120a6e |
ValPtr operator->() const { return m_model->operator->(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool operator==(const any_iterator &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_model->operator==(*other.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator!=(const any_iterator &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_model->operator!=(*other.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_iterator &operator++() {
|
|
Shinya Kitaoka |
120a6e |
++*m_model;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
any_iterator operator++(int) { return any_iterator((*m_model)++); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_iterator &operator--() {
|
|
Shinya Kitaoka |
120a6e |
--*m_model;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
any_iterator operator--(int) { return any_iterator((*m_model)--); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool operator<(const any_iterator &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_model->operator<(*other.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator>(const any_iterator &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_model->operator>(*other.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator<=(const any_iterator &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_model->operator<=(*other.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bool operator>=(const any_iterator &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_model->operator>=(*other.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_iterator operator+(Dist d) const { return any_iterator((*m_model) + d); }
|
|
Shinya Kitaoka |
120a6e |
any_iterator &operator+=(Dist d) {
|
|
Shinya Kitaoka |
120a6e |
(*m_model) += d;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
any_iterator operator-(Dist d) const { return any_iterator((*m_model) - d); }
|
|
Shinya Kitaoka |
120a6e |
any_iterator &operator-=(Dist d) {
|
|
Shinya Kitaoka |
120a6e |
(*m_model) -= d;
|
|
Shinya Kitaoka |
120a6e |
return *this;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Dist operator-(const any_iterator &other) const {
|
|
Shinya Kitaoka |
120a6e |
return m_model->operator-(*other.m_model);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ValRef operator[](Dist d) const { return m_model->operator[](d); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if (TCG_RVALUES_SUPPORT > 0)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
any_iterator(any_iterator &&other) : m_model(other.m_model) {
|
|
Shinya Kitaoka |
120a6e |
other.m_model = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template
|
|
Shinya Kitaoka |
120a6e |
typename Dist>
|
|
Toshihiro Shimizu |
890ddd |
any_iterator<val, dist="" iterator_cat,="" valptr,="" valref,=""> operator+(</val,>
|
|
Shinya Kitaoka |
120a6e |
Dist d, const any_iterator<val, dist="" iterator_cat,="" valptr,="" valref,=""> &it) {</val,>
|
|
Shinya Kitaoka |
120a6e |
return it + d;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Additional typedefs to the actual types
|
|
Toshihiro Shimizu |
890ddd |
//****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename val=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct any_iterator<val, tcg::empty_type=""> {</val,>
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, std::input_iterator_tag=""> input;</val,>
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, std::output_iterator_tag=""> output;</val,>
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, std::forward_iterator_tag=""> forward;</val,>
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, std::bidirectional_iterator_tag=""> bidirectional;</val,>
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, std::random_access_iterator_tag=""> random;</val,>
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template
|
|
Shinya Kitaoka |
120a6e |
typename Dist = std::ptrdiff_t>
|
|
Toshihiro Shimizu |
890ddd |
struct any_it {
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, dist="" std::input_iterator_tag,="" valptr,="" valref,=""></val,>
|
|
Shinya Kitaoka |
120a6e |
input;
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, dist="" std::output_iterator_tag,="" valptr,="" valref,=""></val,>
|
|
Shinya Kitaoka |
120a6e |
output;
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator<val, dist="" std::forward_iterator_tag,="" valptr,="" valref,=""></val,>
|
|
Shinya Kitaoka |
120a6e |
forward;
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator
|
|
Shinya Kitaoka |
120a6e |
Dist>
|
|
Shinya Kitaoka |
120a6e |
bidirectional;
|
|
Shinya Kitaoka |
120a6e |
typedef any_iterator
|
|
Shinya Kitaoka |
120a6e |
Dist>
|
|
Shinya Kitaoka |
120a6e |
random;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace tcg
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // TCG_ANY_ITERATOR_H
|