Jonathan - This sounds like it would make a nice extension to the STLAlogorithmExtension library that Jeremy Siek has suggested and all sorts of boosters have recommended algorithms for. Check out the Wiki page and add it in. http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?STLAlgorithmE... sions Jeff
-----Original Message----- From: Jonathan Brownell [mailto:alphaomega@proaxis.com] Sent: Saturday, February 09, 2002 11:47 PM To: Boost-Users@yahoogroups.com Subject: [Boost-Users] Possible interest in select_by_predicate?
I work in doing programming involving quite a bit of data analysis, and lately I've gotten sick and tired of doing routine searches on vectors and other linear containers to pull out maximum/minimum values. I ended up sitting down and writing a unary function object that retains a value based on any predicate. An example is worth a thousand words:
int array[10] = { 5, 4, 6, 3, 9, 0, 7, 2, 8, 1 };
int maximum = std::for_each(&array[0], &array[10], select_by_predicate
()); int minimum = std::for_each(&array[0], &array[10], select_by_predicate
()); assert(maximum == 9 && minimum == 0);
Another example, using select_by_predicate independently:
select_by_predicate
max_error(0); for(loop through data samples) { double error; ... analyze data sample error ...
max_error.compare(error); // same as max_error(error) }
std::cout << "Maximum error: " << max_error;
Is select_by_predicate something that boost users would be interested in? It's been helpful to me in all kinds of contexts.
-Jonathan
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/