1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// -*- c++ -*-
/* Copyright 2002, The libsigc++ Development Team
* Assigned to public domain. Use as you wish without restriction.
*/
#include "testutilities.h"
#include <sigc++/adaptors/hide.h>
#include <sstream>
#include <cstdlib>
namespace
{
std::ostringstream result_stream;
struct foo : public sigc::functor_base
{
// choose a type that can hold all return values
typedef int result_type;
int operator()()
{
result_stream << "foo() ";
return true;
}
int operator()(int j)
{
result_stream << "foo(int " << j << ") ";
return 1 + j;
}
};
struct foo_void : public sigc::functor_base
{
typedef void result_type;
void operator()()
{
result_stream << "foo_void()";
}
};
} // end anonymous namespace
namespace sigc { SIGC_FUNCTOR_TRAIT(foo,bool) }
int main(int argc, char* argv[])
{
auto util = TestUtilities::get_instance();
if (!util->check_command_args(argc, argv))
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
result_stream << sigc::hide<0>(foo())(1, 2);
util->check_result(result_stream, "foo(int 2) 3");
result_stream << sigc::hide<1>(foo())(1, 2);
util->check_result(result_stream, "foo(int 1) 2");
result_stream << sigc::hide<-1>(foo())(1);
util->check_result(result_stream, "foo() 1");
result_stream << sigc::hide(foo())(1);
util->check_result(result_stream, "foo() 1");
sigc::hide(foo_void())(1); // void test
util->check_result(result_stream, "foo_void()");
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}
|