File: factory.cpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (87 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (11)
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
/*
Copyright 2007 Tobias Schwinger

Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)

Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/functional/factory.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/scoped_ptr.hpp>

class sum {
public:
    explicit sum(int i0 = 0, int i1 = 0, int i2 = 0, int i3 = 0,
                 int i4 = 0, int i5 = 0, int i6 = 0, int i7 = 0,
                 int i8 = 0, int i9 = 0)
        : value_(i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9) { }

    int get() const {
        return value_;
    }

private:
    int value_;
};

int main()
{
    boost::factory<sum*> x;
    int a = 1;
    int b = 2;
    int c = 3;
    int d = 4;
    int e = 5;
    int f = 6;
    int g = 7;
    int h = 8;
    int i = 9;
    int j = 10;
    {
        boost::scoped_ptr<sum> s(x());
        BOOST_TEST(s->get() == 0);
    }
    {
        boost::scoped_ptr<sum> s(x(a));
        BOOST_TEST(s->get() == 1);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b));
        BOOST_TEST(s->get() == 3);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c));
        BOOST_TEST(s->get() == 6);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c, d));
        BOOST_TEST(s->get() == 10);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c, d, e));
        BOOST_TEST(s->get() == 15);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c, d, e, f));
        BOOST_TEST(s->get() == 21);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g));
        BOOST_TEST(s->get() == 28);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h));
        BOOST_TEST(s->get() == 36);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h, i));
        BOOST_TEST(s->get() == 45);
    }
    {
        boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h, i, j));
        BOOST_TEST(s->get() == 55);
    }
    return boost::report_errors();
}