Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is there some iterable class I can inherit from and override <code>++</code>, <code>==</code>, etc. to get the desired effect without storing the <code>std::vector&lt;double&gt;</code>? </p> </blockquote> <p>Yes, there is. Its name is <code>std::iterator&lt;std::input_iterator_tag, double&gt;</code>.</p> <p>Here is a start for you, using <code>int</code>. To save space in my brain, I use the same class to represent both the range and the iterator.</p> <pre><code>#include &lt;iterator&gt; #include &lt;iostream&gt; struct NumericRange : public std::iterator&lt; std::input_iterator_tag, int &gt; { int current, fini, delta; typedef NumericRange iterator; typedef iterator const_iterator; iterator begin() { return *this; } iterator end() { return iterator(fini, fini, delta); } iterator&amp; operator++() { current += delta; return *this; } iterator operator++(int) { iterator result(*this); ++*this; return result; } int operator*() const { return current; } NumericRange(int start, int fini, int delta) : current(start), fini(fini), delta(delta) { } bool operator==(const iterator&amp; rhs) { return rhs.current == current; } bool operator!=(const iterator&amp; rhs) { return !(*this == rhs); } }; void f(int i, int j) { std::cout &lt;&lt; i &lt;&lt; " " &lt;&lt; j &lt;&lt; "\n"; } int main () { int lower = 4, upper = 14, delta = 5; NumericRange nr(lower, upper, delta); for (NumericRange::const_iterator iter = nr.begin(); iter != nr.end(); iter++) { f(*iter, *nr.end()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload