factory_args.cpp 995 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Copyright 2019 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/config.hpp>
  8. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
  9. !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  10. #include <boost/functional/factory.hpp>
  11. #include <boost/core/lightweight_test.hpp>
  12. #include <boost/smart_ptr/scoped_ptr.hpp>
  13. class sum {
  14. public:
  15. explicit sum(int a = 0, int b = 0, int c = 0, int d = 0,
  16. int e = 0, int f = 0, int g = 0, int h = 0,
  17. int i = 0, int j = 0, int k = 0, int l = 0)
  18. : value_(a + b + c + d + e + f + g + h + i + j + k + l) { }
  19. int get() const {
  20. return value_;
  21. }
  22. private:
  23. int value_;
  24. };
  25. int main()
  26. {
  27. boost::scoped_ptr<sum> s(boost::factory<sum*>()(1, 2, 3, 4, 5, 6, 7, 8, 9,
  28. 10, 11, 12));
  29. BOOST_TEST(s->get() == 78);
  30. return boost::report_errors();
  31. }
  32. #else
  33. int main()
  34. {
  35. return 0;
  36. }
  37. #endif