mpl_plus_pass.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // Adaptation to Boost of the libcxx
  10. // Copyright 2010 Vicente J. Botet Escriba
  11. // Distributed under the Boost Software License, Version 1.0.
  12. // See http://www.boost.org/LICENSE_1_0.txt
  13. // test mpl::plus
  14. #define BOOST_RATIO_EXTENSIONS
  15. #include <boost/ratio/mpl/plus.hpp>
  16. #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
  17. #define NOTHING ""
  18. #endif
  19. void test()
  20. {
  21. {
  22. typedef boost::ratio<1, 1> R1;
  23. typedef boost::mpl::int_<1> R2;
  24. typedef boost::mpl::plus<R1, R2> R;
  25. BOOST_RATIO_STATIC_ASSERT(R::num == 2 && R::den == 1, NOTHING, ());
  26. typedef boost::mpl::plus<R, R2> RR;
  27. BOOST_RATIO_STATIC_ASSERT(RR::num == 3 && RR::den == 1, NOTHING, ());
  28. }
  29. {
  30. typedef boost::mpl::int_<1> R1;
  31. typedef boost::ratio<1, 2> R2;
  32. typedef boost::mpl::plus<R1, R2> R;
  33. BOOST_RATIO_STATIC_ASSERT(R::num == 3 && R::den == 2, NOTHING, ());
  34. }
  35. {
  36. typedef boost::ratio<-1, 2> R1;
  37. typedef boost::ratio<1, 1> R2;
  38. typedef boost::mpl::int_<0> R3;
  39. typedef boost::mpl::plus<R1, R2, R3> R;
  40. BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
  41. }
  42. {
  43. typedef boost::ratio<1, -2> R1;
  44. typedef boost::ratio<1, 1> R2;
  45. typedef boost::mpl::int_<0> R3;
  46. typedef boost::mpl::plus<R1, R2, R3> R;
  47. BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
  48. }
  49. {
  50. typedef boost::ratio<1, 2> R1;
  51. typedef boost::ratio<-1, 1> R2;
  52. typedef boost::mpl::int_<0> R3;
  53. typedef boost::mpl::plus<R1, R2, R3> R;
  54. BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ());
  55. }
  56. {
  57. typedef boost::ratio<1, 2> R1;
  58. typedef boost::ratio<1, -1> R2;
  59. typedef boost::mpl::int_<0> R3;
  60. typedef boost::mpl::plus<R1, R2, R3> R;
  61. BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ());
  62. }
  63. {
  64. typedef boost::ratio<56987354, 467584654> R1;
  65. typedef boost::ratio<544668, 22145> R2;
  66. typedef boost::mpl::int_<0> R3;
  67. typedef boost::mpl::plus<R1, R2, R3> R;
  68. BOOST_RATIO_STATIC_ASSERT(R::num == 127970191639601LL && R::den == 5177331081415LL, NOTHING, ());
  69. }
  70. {
  71. typedef boost::ratio<BOOST_RATIO_INTMAX_T_MAX, 1> R1;
  72. typedef boost::ratio<-1, 1> R2;
  73. typedef boost::mpl::int_<0> R3;
  74. typedef boost::mpl::plus<R1, R2, R3>::type RT;
  75. }
  76. }
  77. boost::intmax_t func(boost::ratio<5,6> s) {
  78. return s.num;
  79. }
  80. boost::intmax_t test_conversion() {
  81. return func(
  82. boost::mpl::plus<
  83. boost::ratio<1,2>,
  84. boost::ratio<1,3>
  85. >
  86. ()
  87. );
  88. }