value_factory.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Copyright 2007 Tobias Schwinger
  3. Copyright 2019 Glen Joseph Fernandes
  4. (glenjofe@gmail.com)
  5. Distributed under the Boost Software License, Version 1.0.
  6. (http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #include <boost/functional/value_factory.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. class sum {
  11. public:
  12. explicit sum(int i0 = 0, int i1 = 0, int i2 = 0, int i3 = 0,
  13. int i4 = 0, int i5 = 0, int i6 = 0, int i7 = 0,
  14. int i8 = 0, int i9 = 0)
  15. : value_(i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9) { }
  16. int get() const {
  17. return value_;
  18. }
  19. private:
  20. int value_;
  21. };
  22. int main()
  23. {
  24. boost::value_factory<sum> x;
  25. int a = 1;
  26. int b = 2;
  27. int c = 3;
  28. int d = 4;
  29. int e = 5;
  30. int f = 6;
  31. int g = 7;
  32. int h = 8;
  33. int i = 9;
  34. int j = 10;
  35. {
  36. sum s(x());
  37. BOOST_TEST(s.get() == 0);
  38. }
  39. {
  40. sum s(x(a));
  41. BOOST_TEST(s.get() == 1);
  42. }
  43. {
  44. sum s(x(a, b));
  45. BOOST_TEST(s.get() == 3);
  46. }
  47. {
  48. sum s(x(a, b, c));
  49. BOOST_TEST(s.get() == 6);
  50. }
  51. {
  52. sum s(x(a, b, c, d));
  53. BOOST_TEST(s.get() == 10);
  54. }
  55. {
  56. sum s(x(a, b, c, d, e));
  57. BOOST_TEST(s.get() == 15);
  58. }
  59. {
  60. sum s(x(a, b, c, d, e, f));
  61. BOOST_TEST(s.get() == 21);
  62. }
  63. {
  64. sum s(x(a, b, c, d, e, f, g));
  65. BOOST_TEST(s.get() == 28);
  66. }
  67. {
  68. sum s(x(a, b, c, d, e, f, g, h));
  69. BOOST_TEST(s.get() == 36);
  70. }
  71. {
  72. sum s(x(a, b, c, d, e, f, g, h, i));
  73. BOOST_TEST(s.get() == 45);
  74. }
  75. {
  76. sum s(x(a, b, c, d, e, f, g, h, i, j));
  77. BOOST_TEST(s.get() == 55);
  78. }
  79. return boost::report_errors();
  80. }