• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright 2007 Tobias Schwinger
3 Copyright 2017 Daniel James
4 
5 Copyright 2019 Glen Joseph Fernandes
6 (glenjofe@gmail.com)
7 
8 Distributed under the Boost Software License, Version 1.0.
9 (http://www.boost.org/LICENSE_1_0.txt)
10 */
11 #include <boost/functional/factory.hpp>
12 #include <boost/core/lightweight_test.hpp>
13 #include <boost/smart_ptr/shared_ptr.hpp>
14 #include <memory>
15 
16 class sum  {
17 public:
sum(int a,int b)18     sum(int a, int b)
19         : value_(a + b) { }
20 
get() const21     int get() const {
22         return value_;
23     }
24 
25 private:
26     int value_;
27 };
28 
main()29 int main()
30 {
31     int a = 1;
32     int b = 2;
33     {
34         boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>,
35             std::allocator<char>,
36             boost::factory_alloc_for_pointee_and_deleter>()(a, b));
37         BOOST_TEST(s->get() == 3);
38     }
39     {
40         boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>,
41             std::allocator<char>,
42             boost::factory_passes_alloc_to_smart_pointer>()(a, b));
43         BOOST_TEST(s->get() == 3);
44     }
45     return boost::report_errors();
46 }
47