Boost logo

Boost :

Subject: Re: [boost] [iterators] Proof-of-concept for a sentinel iterator adapter
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2009-05-13 11:58:53


On Wed, May 13, 2009 at 5:19 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
>> Attached is proof-of-concept code for a sentinel iterator adapter. It
>> turns a pointer to sentinel terminated sequence, such as a C-style
>> string, into a forward iterator with a conforming end iterator.
>>
>> This is more efficient than doing a separate sequence traversal just to
>> find the end.
>
> No, it is not. :-)
>
> PS:
>
> #include <boost/functional/hash.hpp>
> #include <algorithm>
> #include <iostream>
> #include <windows.h>
>
> static size_t test_strlen( char const * s );
> static size_t test_sentinel( char const * s );
>
> int main()
> {
>   int const N = 10000000;
>
>   DWORD t1 = timeGetTime();
>
>   size_t m1 = 0;
>
>   for( int i = 0; i < N; ++i )
>   {
>       m1 += test_strlen( "This is a test." );
>   }
>

Are you sure the compiler is not computing the len at compile time?

-- 
gpd

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