Brian Silverman | f14e1af | 2018-08-04 23:36:29 -0700 | [diff] [blame^] | 1 | /*============================================================================= |
| 2 | Copyright (c) 2007 Tobias Schwinger |
| 3 | |
| 4 | Use modification and distribution are subject to the Boost Software |
| 5 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 6 | http://www.boost.org/LICENSE_1_0.txt). |
| 7 | ==============================================================================*/ |
| 8 | |
| 9 | #include <boost/functional/factory.hpp> |
| 10 | #include <boost/core/lightweight_test.hpp> |
| 11 | |
| 12 | #include <memory> |
| 13 | |
| 14 | class sum |
| 15 | { |
| 16 | int val_sum; |
| 17 | public: |
| 18 | sum(int a, int b) : val_sum(a + b) { } |
| 19 | |
| 20 | operator int() const { return this->val_sum; } |
| 21 | }; |
| 22 | |
| 23 | // Suppress warnings about std::auto_ptr. |
| 24 | #if defined(__clang__) |
| 25 | #pragma clang diagnostic push |
| 26 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 27 | #endif |
| 28 | |
| 29 | int main() |
| 30 | { |
| 31 | int one = 1, two = 2; |
| 32 | { |
| 33 | sum* instance( boost::factory< sum* >()(one,two) ); |
| 34 | BOOST_TEST(*instance == 3); |
| 35 | } |
| 36 | #if !defined(BOOST_NO_AUTO_PTR) |
| 37 | { |
| 38 | std::auto_ptr<sum> instance( boost::factory< std::auto_ptr<sum> >()(one,two) ); |
| 39 | BOOST_TEST(*instance == 3); |
| 40 | } |
| 41 | #endif |
| 42 | #if !defined(BOOST_NO_CXX11_SMART_PTR) |
| 43 | { |
| 44 | std::unique_ptr<sum> instance( boost::factory< std::unique_ptr<sum> >()(one,two) ); |
| 45 | BOOST_TEST(*instance == 3); |
| 46 | } |
| 47 | #endif |
| 48 | return boost::report_errors(); |
| 49 | } |
| 50 | |
| 51 | #if defined(__clang__) |
| 52 | #pragma clang diagnostic pop |
| 53 | #endif |