September 2003 Archives

C++ STL extras - random_sample_n

| 1 Comment

Working on some code for my research tonight, I wasted a lot of time looking for some information on a particlar STL function. Since I couldn't find the answers elsewhere, I am posting a quick explanation/solution here, to hopefully save someone else the trouble.

I am writing a C++ application, and use the STL in various places. I have been consulting the SGI Standard Template Library Programmer's Guide. It is quite poorly named; it is really a reference, with not much guidance at all. And unfortunately I have yet to find a decent book on the STL (I have one but it sucks).

(Note that the below applies to the g++ compiler version 3.3; I don't know about other compilers or libraries.)

Anyway, I found just the function I was after: random_sample_n. So I added the include for algorithm, and couldn't get the sucker to compile. It turns out that since it is an extension to the STL, it is located in the ext/algorithm header, and under the namespace __gnu_cxx:: instead of std::. This stuff I found the hard way, slugging through header files.

Another thing: I didn't find any decent examples (the one in the SGI docs is trivial) so here is some real code:

My Photos

www.flickr.com
This is a Flickr badge showing public photos and videos from antonyme. Make your own badge here.

Recent Tweets

    About this Archive

    This page is an archive of entries from September 2003 listed from newest to oldest.

    July 2003 is the previous archive.

    October 2003 is the next archive.

    Find recent content on the main index or look in the archives to find all content.