mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1305422 - part 6a - add operator- support for ns{Reading,Writing}Iterator; r=erahm
This change is necessary so we can start using a pair of iterators (current, end) and subtract them to figure out how far we have left to go. The current code just uses size_forward and size_backward for this purpose, and it's quite an unusual iterator that knows how far it can go until it's done.
This commit is contained in:
parent
70d6d5515f
commit
7fbe6c830e
@ -21,6 +21,7 @@ class nsReadingIterator
|
|||||||
public:
|
public:
|
||||||
typedef nsReadingIterator<CharT> self_type;
|
typedef nsReadingIterator<CharT> self_type;
|
||||||
typedef ptrdiff_t difference_type;
|
typedef ptrdiff_t difference_type;
|
||||||
|
typedef size_t size_type;
|
||||||
typedef CharT value_type;
|
typedef CharT value_type;
|
||||||
typedef const CharT* pointer;
|
typedef const CharT* pointer;
|
||||||
typedef const CharT& reference;
|
typedef const CharT& reference;
|
||||||
@ -129,6 +130,17 @@ public:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We return an unsigned type here (with corresponding assert) rather than
|
||||||
|
// the more usual difference_type because we want to make this class go
|
||||||
|
// away in favor of mozilla::RangedPtr. Since RangedPtr has the same
|
||||||
|
// requirement we are enforcing here, the transition ought to be much
|
||||||
|
// smoother.
|
||||||
|
size_type operator-(const self_type& aOther) const
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(mPosition >= aOther.mPosition);
|
||||||
|
return mPosition - aOther.mPosition;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,6 +153,7 @@ class nsWritingIterator
|
|||||||
public:
|
public:
|
||||||
typedef nsWritingIterator<CharT> self_type;
|
typedef nsWritingIterator<CharT> self_type;
|
||||||
typedef ptrdiff_t difference_type;
|
typedef ptrdiff_t difference_type;
|
||||||
|
typedef size_t size_type;
|
||||||
typedef CharT value_type;
|
typedef CharT value_type;
|
||||||
typedef CharT* pointer;
|
typedef CharT* pointer;
|
||||||
typedef CharT& reference;
|
typedef CharT& reference;
|
||||||
@ -259,6 +272,17 @@ public:
|
|||||||
nsCharTraits<value_type>::move(mPosition, aS, aN);
|
nsCharTraits<value_type>::move(mPosition, aS, aN);
|
||||||
advance(difference_type(aN));
|
advance(difference_type(aN));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We return an unsigned type here (with corresponding assert) rather than
|
||||||
|
// the more usual difference_type because we want to make this class go
|
||||||
|
// away in favor of mozilla::RangedPtr. Since RangedPtr has the same
|
||||||
|
// requirement we are enforcing here, the transition ought to be much
|
||||||
|
// smoother.
|
||||||
|
size_type operator-(const self_type& aOther) const
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(mPosition >= aOther.mPosition);
|
||||||
|
return mPosition - aOther.mPosition;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class CharT>
|
template <class CharT>
|
||||||
|
Loading…
Reference in New Issue
Block a user