Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / functional / factory / test / factory.cpp
1 /*
2 Copyright 2007 Tobias Schwinger
3
4 Copyright 2019 Glen Joseph Fernandes
5 (glenjofe@gmail.com)
6
7 Distributed under the Boost Software License, Version 1.0.
8 (http://www.boost.org/LICENSE_1_0.txt)
9 */
10 #include <boost/functional/factory.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #include <boost/smart_ptr/scoped_ptr.hpp>
13
14 class sum {
15 public:
16     explicit sum(int i0 = 0, int i1 = 0, int i2 = 0, int i3 = 0,
17                  int i4 = 0, int i5 = 0, int i6 = 0, int i7 = 0,
18                  int i8 = 0, int i9 = 0)
19         : value_(i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9) { }
20
21     int get() const {
22         return value_;
23     }
24
25 private:
26     int value_;
27 };
28
29 int main()
30 {
31     boost::factory<sum*> x;
32     int a = 1;
33     int b = 2;
34     int c = 3;
35     int d = 4;
36     int e = 5;
37     int f = 6;
38     int g = 7;
39     int h = 8;
40     int i = 9;
41     int j = 10;
42     {
43         boost::scoped_ptr<sum> s(x());
44         BOOST_TEST(s->get() == 0);
45     }
46     {
47         boost::scoped_ptr<sum> s(x(a));
48         BOOST_TEST(s->get() == 1);
49     }
50     {
51         boost::scoped_ptr<sum> s(x(a, b));
52         BOOST_TEST(s->get() == 3);
53     }
54     {
55         boost::scoped_ptr<sum> s(x(a, b, c));
56         BOOST_TEST(s->get() == 6);
57     }
58     {
59         boost::scoped_ptr<sum> s(x(a, b, c, d));
60         BOOST_TEST(s->get() == 10);
61     }
62     {
63         boost::scoped_ptr<sum> s(x(a, b, c, d, e));
64         BOOST_TEST(s->get() == 15);
65     }
66     {
67         boost::scoped_ptr<sum> s(x(a, b, c, d, e, f));
68         BOOST_TEST(s->get() == 21);
69     }
70     {
71         boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g));
72         BOOST_TEST(s->get() == 28);
73     }
74     {
75         boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h));
76         BOOST_TEST(s->get() == 36);
77     }
78     {
79         boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h, i));
80         BOOST_TEST(s->get() == 45);
81     }
82     {
83         boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h, i, j));
84         BOOST_TEST(s->get() == 55);
85     }
86     return boost::report_errors();
87 }