Hidden Features and Dark Corners of STL?

J

James Kanze

What do you think about these dark corners of stl? which ones would
you add?

Harly a dark corner, but I find a lot of programmers aren't
aware of std::accumulate (perhaps because it's in the math
section of the standard, rather than the algorithms). Define
a custom accumulator type, and it can be used for a lot of
things. For example, if I want to append an MD5 checksum to a
string, I'll use something like:

s += std::accumulate(s.begin(), s.end(), MD5Hasher());

(where s is a string, and MD5Hasher is an accumulator which
generates the MD5 checksum, and has an implicit conversion to
string which returns the hash generated so far).

Practically, accumulate is usable just about any time you want
to generate a single value which depends on a sequence of
values.
 
P

puzzlecracker

Harly a dark corner, but I find a lot of programmers aren't
aware of std::accumulate (perhaps because it's in the math
section of the standard, rather than the algorithms).  Define
a custom accumulator type, and it can be used for a lot of
things.  For example, if I want to append an MD5 checksum to a
string, I'll use something like:

    s += std::accumulate(s.begin(), s.end(), MD5Hasher());

(where s is a string, and MD5Hasher is an accumulator which
generates the MD5 checksum, and has an implicit conversion to
string which returns the hash generated so far).

Practically, accumulate is usable just about any time you want
to generate a single value which depends on a sequence of
values.

Great! James -- your features are added to the master list as well...

Rest of gurus willing to share their dark secrets -- should do it now.

Thanks the glorified community!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top