Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: Simulating for loop iteration with iota (http://www.velocityreviews.com/forums/t957099-re-simulating-for-loop-iteration-with-iota.html)

Victor Bazarov 01-30-2013 06:56 PM

Re: Simulating for loop iteration with iota
 
On 1/30/2013 1:40 PM, algocoders@gmail.com wrote:
> Free chapter on std::iota @
> http://www.algocoders.com/sites/defa...ithms_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

Öö Tiib 01-31-2013 12:07 AM

Re: Simulating for loop iteration with iota
 
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. ;)

algocoders@gmail.com 01-31-2013 04:29 AM

Re: Simulating for loop iteration with iota
 
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-.../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


All times are GMT. The time now is 07:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.