Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / functional / factory / test / factory_move.cpp
1 /*
2 Copyright 2019 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #include <boost/config.hpp>
9 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
10     !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
11 #include <boost/functional/factory.hpp>
12 #include <boost/core/lightweight_test.hpp>
13 #include <boost/smart_ptr/scoped_ptr.hpp>
14
15 class arg {
16 public:
17     explicit arg(int n)
18         : value_(n) { }
19
20     arg(arg&& a)
21         : value_(a.value_) { }
22
23     int get() const {
24         return value_;
25     }
26
27 private:
28     int value_;
29 };
30
31 class sum {
32 public:
33     explicit sum(arg&& a1, arg&& a2)
34         : value_(a1.get() + a2.get()) { }
35
36     int get() const {
37         return value_;
38     }
39
40 private:
41     int value_;
42 };
43
44 int main()
45 {
46     boost::scoped_ptr<sum> s(boost::factory<sum*>()(arg(1), arg(2)));
47     BOOST_TEST(s->get() == 3);
48     return boost::report_errors();
49 }
50 #else
51 int main()
52 {
53     return 0;
54 }
55 #endif