]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - tests/test_deduce_result_type.cc
Import libsigc++ 2.10.8 sources
[ext/sigc++-2.0.git] / tests / test_deduce_result_type.cc
1 // -*- c++ -*-
2 /* Copyright 2002, The libsigc++ Development Team
3  *  Assigned to public domain.  Use as you wish without restriction.
4  */
5
6 #include "testutilities.h"
7 #include <sstream>
8 #include <cstdlib>
9 #include <sigc++/sigc++.h>
10
11 namespace
12 {
13 std::ostringstream result_stream;
14
15 template <class T>
16 void bar(T)
17 {
18   result_stream << "unknown";
19 }
20
21 template <>
22 void bar<int>(int)
23 {
24   result_stream << "int";
25 }
26
27 template <>
28 void bar<double>(double)
29 {
30   result_stream << "double";
31 }
32
33 struct foo : public sigc::functor_base
34 {
35   typedef double result_type;
36
37   int operator()(int i = 1);
38   double operator()(const int&, int);
39 };
40
41 struct foo2 : public foo
42 {};
43
44 struct foo3 : public sigc::functor_base
45 {
46   typedef int result_type;
47
48   int operator()(int i = 1);
49   double operator()(const int&, int);
50 };
51
52 } // end anonymous namespace
53
54 int main(int argc, char* argv[])
55 {
56   auto util = TestUtilities::get_instance();
57
58   if (!util->check_command_args(argc, argv))
59     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
60
61   bar(sigc::deduce_result_t<foo2, long>());
62   util->check_result(result_stream, "double");
63
64   bar(sigc::deduce_result_t<foo2, int, int>());
65   util->check_result(result_stream, "double");
66
67   bar(sigc::deduce_result_t<foo3, int, int>());
68   util->check_result(result_stream, "int");
69
70 #ifdef FAIL
71   bar(sigc::deduce_result_t<foo2, int, int, int>());
72   util->check_result(result_stream, "double");
73 #endif
74
75   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
76 }