
On Wed, May 13, 2009 at 5:19 PM, Peter Dimov <pdimov@pdimov.com> 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