Re: Simulating for loop iteration with iota

Discussion in 'C++' started by Victor Bazarov, Jan 30, 2013.

  1. On 1/30/2013 1:40 PM, wrote:
    > Free chapter on std::iota @
    > http://www.algocoders.com/sites/default/files/chapter1_c++11algorithms_vol1.pdf
    >
    > Cheers,
    > Algocoders
    > http://www.algocoders.com/


    Perhaps I'm missing something key here; in your article you have this code:

    1 template <typename Iterator, typename T>
    2 bool test_iota_output (Iterator first, Iterator last,
    3 T initial_value)
    4 {
    5 bool ret = false;
    6 if ( first == last )
    7 {
    8 ret = true;
    9 return ret;
    10 }
    11
    12 if ( initial_value != *first )
    13 {
    14 ret = false;
    15 return ret;
    16 }
    17
    18 Iterator prev = first;
    19
    20 while ( ++first != last )
    21 {
    22 if (( *first - *prev ) != 1 )
    23 {
    24 ret = false;
    25 return ret;
    26 }
    27 prev = first;
    28 }
    29
    30 ret = true;
    31 return ret;
    32 }

    (sorry for the indenting, I've just copied this from the PDF file)

    I am puzzled with the role the variable 'ret' has. Why not simply do
    away with it and return the value?

    And what is the exact reason for you to have those numbers? They
    obviously prevent me from copying and pasting your code into my IDE
    without having to edit it - intentional? Try to apply the same rules
    you would follow posting here. If you need to refer to a line, add a
    comment to that line, put a mark in the comment and refer to the mark...

    Anyway, this is the first time I decided to waste a few minutes looking
    at your product and aside from nice/fancy formatting, it doesn't really
    strike me as terribly useful. What is your point exactly?...

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jan 30, 2013
    #1
    1. Advertising

  2. Victor Bazarov

    Öö Tiib Guest

    On Wednesday, 30 January 2013 20:56:51 UTC+2, Victor Bazarov wrote:
    > Anyway, this is the first time I decided to waste a few minutes looking
    > at your product and aside from nice/fancy formatting, it doesn't really
    > strike me as terribly useful. What is your point exactly?...


    The point of posting here seems to be to advertize that site and book by
    providing some (hopefully useful) examples from the material. Teasers.
    He did manage to get your review and some constructive suggestions so
    .... it did sort of work. ;)
     
    Öö Tiib, Jan 31, 2013
    #2
    1. Advertising

  3. Victor Bazarov

    Guest

    On Thursday, January 31, 2013 5:37:34 AM UTC+5:30, Öö Tiib wrote:
    > The point of posting here seems to be to advertize that site and book by
    > providing some (hopefully useful) examples from the material. Teasers.
    > He did manage to get your review and some constructive suggestions so
    > ... it did sort of work. ;)


    When we looked at std::iota, it looked simple and useful. Of course, it wasavailable part of SGI(and HP) STL (non-standard)extension even before C++11. But, once put to practice, we started to realize that it is very useful and need for customization, extensions, concepts and variations started coming out naturally : plenty of them : like : an excerpt for table of contents of our book : C++11 Algorithms Volume 1: Using and Extending C++11, Boostand Beyond :

    Part 3 Numeric Algorithms:

    Chapter 1
    Simulating for-loop iteration
    1.1 Overview of iota
    1.1.1 Motivation
    1.1.2 Interface
    1.1.3 Description
    1.1.4 Simple Usage
    1.1.5 Correctness-of-Algorithm
    1.2 Concepts in iota
    1.2.1 PreIncrementable
    1.2.2 Forward Iterator
    1.3 Implementing iota

    Chapter 2
    Customizing iota
    2.1 Custom Increment
    2.1.1 Overloading iota
    2.1.2 Overload-pre-increment-operator
    2.1.3 std::generate
    2.1.4 iota vs generate
    2.2 Range Version
    2.3 Empty vs Invalid Range
    2.4 iota for writing n items
    2.4.1 iota_n
    2.4.2 Additional Concepts
    2.4.3 boost::algorithm::iota_n
    2.4.4 Complexity
    2.5 Reverse iota
    2.5.1 reverse_iota
    2.5.2 reverse_iota_n
    2.5.3 PreDecrementable

    Chapter 3
    Return Type of iota
    3.1 Boost Range iota
    3.2 Validation

    Chapter 4
    Interesting variations of iota
    4.1 reverse_iota
    4.2 random iota
    4.3 hill iota
    4.4 valley iota
    4.5 double iota
    4.6 double reverse iota
    4.7 equal_iota
    4.8 equal_iota_reverse
    4.9 As Function Object
    4.10 Counting Iterator
    4.11 Compile Time iota
    4.12 Remarks
    4.13 Exercise

    And it spanned 50+ odd pages just on iota. It started exploding soon, so webundled it in form of short books as a detailed supplement to the book TheC++ Standard Library, Second Edition : A Tutorial and Reference by NicolaiM. Josuttis.

    Recommended Approach
    Though this book can be read without reference to any other source, still we recommend our readers to keep a copy of the famous book
    The C++ Standard Library, Second Edition : A Tutorial and Reference by Nicolai M. Josuttis handy for gentle introduction to C++11 algorithms followed by diving into respective sections of our book for detailed information.

    In-depth treatment of foundational aspect of C++11 algorithms is covered inanother book published by us
    Foundation of Algorithms in C++11, Volume 1(Revised Edition)
    : Using and Extending C++11, Boost and Beyond.

    It is available @ amazon:
    http://www.amazon.com/11-Algorithms-Using-Extending-Beyond/dp/1482083396

    We wanted to shared this information which we think is going to be very useful for C++11 programmers, hence chapter 1 was made available for early review and comments.

    Thanks for your time !

    Cheers,
    Algocoders,
    http://www.algocoders.com
     
    , Jan 31, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dwerdna
    Replies:
    5
    Views:
    5,494
    Ajeetha
    Mar 31, 2005
  2. iota

    , Jan 18, 2006, in forum: C++
    Replies:
    4
    Views:
    529
    Victor Bazarov
    Jan 18, 2006
  3. Rudi
    Replies:
    5
    Views:
    5,030
  4. Nene
    Replies:
    6
    Views:
    350
    John W. Krahn
    Dec 13, 2008
  5. Isaac Won
    Replies:
    9
    Views:
    387
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page