1 /* Copyright 2002, The libsigc++ Development Team
2 * Assigned to public domain. Use as you wish without restriction.
5 #include "testutilities.h"
8 #include <sigc++/adaptors/bind.h>
9 #include <sigc++/adaptors/compose.h>
10 #include <sigc++/functors/mem_fun.h>
11 #include <sigc++/functors/ptr_fun.h>
15 std::ostringstream result_stream;
19 struct A : public trackable { A() {} };
21 template <class T_type, bool I_derived = std::is_base_of<trackable,T_type>::value>
22 struct with_trackable;
24 template <class T_type>
25 struct with_trackable<T_type,false>
27 static void perform(const T_type&)
29 result_stream << "other ";
33 template <class T_type>
34 struct with_trackable<T_type,true>
36 static void perform(const T_type&)
38 result_stream << "trackable ";
41 static void perform(T_type*)
43 result_stream << "trackable* ";
46 static void perform(const T_type*)
48 result_stream << "const trackable* ";
54 void operator()(int i) const
56 result_stream << "int: " << i << " ";
60 void operator()(const T& t) const
62 with_trackable<T>::perform(t);
66 void foo(int, int, int)
72 } // end anonymous namespace
74 int main(int argc, char* argv[])
76 auto util = TestUtilities::get_instance();
78 if (!util->check_command_args(argc, argv))
79 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
85 result_stream << "hit all targets: ";
86 sigc::visit_each(print(), sigc::compose(sigc::bind(sigc::ptr_fun3(&foo), std::ref(a), i), sigc::ptr_fun1(&bar)));
87 util->check_result(result_stream, "hit all targets: other trackable int: 1 other ");
89 result_stream << "hit all ints: ";
90 sigc::visit_each_type<int>(print(), sigc::compose(sigc::bind(sigc::ptr_fun3(&foo), std::ref(a), j),sigc::ptr_fun1(&bar)));
91 util->check_result(result_stream, "hit all ints: int: 2 ");
93 result_stream << "hit all trackable: ";
94 sigc::visit_each_type<trackable>(print(), sigc::compose(sigc::bind(sigc::ptr_fun3(&foo), std::ref(a), k),sigc::ptr_fun1(&bar)));
95 util->check_result(result_stream, "hit all trackable: trackable ");
97 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;