Created
April 15, 2010 18:38
-
-
Save zed/367475 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://stackoverflow.com/questions/2638781/c-conjunction-of-binds | |
| // $ g++ -Wall -pedantic conjunctions_of_bind.cc -o conjunctions_of_bind | |
| // $ ./conjunctions_of_bind | |
| #include <cstdlib> // atoi | |
| #include <cstring> // strcmp | |
| #include <boost/bind.hpp> | |
| #include <boost/function.hpp> | |
| #include <boost/test/minimal.hpp> | |
| namespace { | |
| bool match1(const char* a, const char* b) { | |
| return (std::strcmp(a, b) == 0); | |
| } | |
| bool match2(int a, const char* b) { | |
| return (std::atoi(b) == a); | |
| } | |
| } | |
| int test_main(int, char*[]) { | |
| boost::function<bool(const char *, const char *)> f = \ | |
| boost::bind(match1, "a test", _1) && boost::bind(match2, 42, _2); | |
| BOOST_CHECK( f("a test", "42") ); | |
| BOOST_CHECK( !f("a test", "43") ); | |
| BOOST_CHECK( !f("atest", "42") ); | |
| BOOST_CHECK( !f("42", "a test") ); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment