2 /* Copyright 2002, The libsigc++ Development Team
3 * Assigned to public domain. Use as you wish without restriction.
6 #include "testutilities.h"
7 #include <sigc++/adaptors/bind.h>
8 #include <sigc++/functors/slot.h>
11 #include <functional> //For std::ref().
17 std::ostringstream result_stream;
19 bool func_to_bind(int a, int b)
21 result_stream << "func_to_bind(" << a << ", " << b << ")";
25 bool func_to_bind_with_iter(int a, std::string::iterator& b)
27 result_stream << "func_to_bind_with_iter(" << a << ", " << *b << ")";
31 bool func_to_bind_with_const_iter(int a, std::string::const_iterator& b)
33 result_stream << "func_to_bind_with_const_iter(" << a << ", " << *b << ")";
37 } // end anonymous namespace
39 int main(int argc, char* argv[])
41 auto util = TestUtilities::get_instance();
43 if (!util->check_command_args(argc, argv))
44 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
47 //Test that sigc::bind()'s result can be converted to a sigc::slot<>.
49 sigc::slot<bool, int> bound_slot = sigc::bind(sigc::ptr_fun(&func_to_bind), 2);
51 util->check_result(result_stream, "func_to_bind(1, 2)");
54 //Test with a non-const iterator:
57 sigc::slot<bool, int> bound_slot = sigc::bind(sigc::ptr_fun(&func_to_bind_with_iter), c.begin());
59 util->check_result(result_stream, "func_to_bind_with_iter(1, 2)");
62 //Test with a const_iterator:
64 const std::string c = "2";
65 sigc::slot<bool, int> bound_slot = sigc::bind(sigc::ptr_fun(&func_to_bind_with_const_iter), c.begin());
67 util->check_result(result_stream, "func_to_bind_with_const_iter(1, 2)");
70 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;