Boost logo

Boost :

From: Bjorn.Karlsson_at_[hidden]
Date: 2004-02-25 06:03:34


> From: David Abrahams [mailto:dave_at_[hidden]]
>
> See counting_iterator for inspiration as to why this might be useful.

Got it, thanks.
Perhaps these type requirements should be spelled out in the docs (proposed
patch below)? And maybe is_full_iterator_traits in detail/iterators.hpp
could be slightly changed and turned into a first-class traits
"is_iterator", which would then be used for dispatching next/prior calls to
std::advance when applicable? Although this would work, I'm not sure that
the added dependencies and complexity are worth it - if possible, I think
that dropping the two-argument versions of next and prior would be best.

Bjorn

[Note: The most interesting change to the doc are the following four lines.
<p>The one-argument version of next() and prior() can be used with any type
that provides
operator++() and operator--(), respectively. The two-argument version of
next() and prior()
can be used with any type that provides operator+() and operator-(), with
the exception of
iterator types, which only require operator++() and operator--() for both
versions.</p>
]

*** utility.htm.orig Wed Feb 25 11:47:07 2004
--- utility.htm Wed Feb 25 11:48:17 2004
***************
*** 41,61 ****
  T next(T x) { return ++x; }
  
  template &lt;class T, class Distance&gt;
! T next(T x, Distance n)
! {
! std::advance(x, n);
! return x;
! }
  
  template &lt;class T&gt;
  T prior(T x) { return --x; }
  
  template &lt;class T, class Distance&gt;
! T prior(T x, Distance n)
! {
! std::advance(x, -n);
! return x;
! }</pre>
                  </blockquote>
                  <p>Usage is simple:</p>
                  <blockquote>
--- 41,54 ----
  T next(T x) { return ++x; }
  
  template &lt;class T, class Distance&gt;
! T next(T x, Distance n);
  
  template &lt;class T&gt;
  T prior(T x) { return --x; }
  
  template &lt;class T, class Distance&gt;
! T prior(T x, Distance n);
! </pre>
                  </blockquote>
                  <p>Usage is simple:</p>
                  <blockquote>
***************
*** 66,71 ****
--- 59,68 ----
                  <p>The distance from the given iterator should be supplied
as an absolute value. For
                          example, the iterator four iterators prior to the
given iterator <code>p</code>
                          may be obtained by <code>prior(p, 4)</code>.</p>
+ <p>The one-argument version of next() and prior() can be
used with any type that provides
+ operator++() and operator--(), respectively. The
two-argument version of next() and prior()
+ can be used with any type that provides operator+() and
operator-(), with the exception of
+ iterator types, which only require operator++() and
operator--() for both versions.</p>
                  <p>Contributed by <a
href="../../people/dave_abrahams.htm">Dave Abrahams</a>. Two-argument
versions by Daniel Walker.</p>
                  <h2><a name="Class_noncopyable">Class noncopyable</a></h2>
                  <p>Class <strong>noncopyable</strong> is a base class.&nbsp;
Derive your own class


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk