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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// -*- c++ -*-
/* Copyright 2002, The libsigc++ Development Team
* Assigned to public domain. Use as you wish without restriction.
*/
#include "testutilities.h"
#include <sstream>
#include <sigc++/sigc++.h>
#include <cstdlib>
//TODO: put something like #ifndef FORTE ... #else ... #endif around:
#define ENABLE_TEST_OF_OVERLOADED_FUNCTIONS 0
namespace
{
std::ostringstream result_stream;
int foo()
{
result_stream << "foo()";
return 1;
}
void foo(int i1)
{
result_stream << "foo(int " << i1 << ")";
}
#if ENABLE_TEST_OF_OVERLOADED_FUNCTIONS
void bar(char i1)
{
result_stream << "bar(char " << (int)i1 << ")";
}
#endif
void bar(float i1)
{
result_stream << "bar(float " << i1 << ")";
}
double bar(int i1, int i2)
{
result_stream << "bar(int " << i1 << ", int " << i2 << ")";
return 1.0f;
}
struct test
{
static void foo()
{
result_stream << "test::foo()";
}
};
} // end anonymous namespace
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;
//Test use of overloaded functions that differ by number of parameters
//and by return type
sigc::ptr_fun<int>(&foo)();
util->check_result(result_stream, "foo()");
sigc::ptr_fun<void>(&foo)(1);
util->check_result(result_stream, "foo(int 1)");
//Test use of overloaded functions that differ by parameter type:
#if ENABLE_TEST_OF_OVERLOADED_FUNCTIONS
sigc::ptr_fun<void, char>(&bar)(2);
util->check_result(result_stream, "bar(char 2)");
sigc::ptr_fun<void, float>(&bar)(2.0f);
util->check_result(result_stream, "bar(float 2)");
#else
sigc::ptr_fun<void>(&bar)(2.0f);
util->check_result(result_stream, "bar(float 2)");
#endif
sigc::ptr_fun<double>(&bar)(3, 5);
util->check_result(result_stream, "bar(int 3, int 5)");
sigc::ptr_fun(&test::foo)();
util->check_result(result_stream, "test::foo()");
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}
|