struct_macros.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/assert.hpp>
  5. #include <boost/hana/detail/struct_macros.hpp>
  6. #include <string>
  7. #include <vector>
  8. //////////////////////////////////////////////////////////////////////////////
  9. // BOOST_HANA_PP_NARG
  10. //////////////////////////////////////////////////////////////////////////////
  11. static_assert(BOOST_HANA_PP_NARG(x) == 1, "");
  12. static_assert(BOOST_HANA_PP_NARG(x, x) == 2, "");
  13. static_assert(BOOST_HANA_PP_NARG(x, x, x) == 3, "");
  14. static_assert(BOOST_HANA_PP_NARG(x, x, x, x) == 4, "");
  15. static_assert(BOOST_HANA_PP_NARG(
  16. x, x, x, x, x, x, x, x, x, x,
  17. x, x, x, x, x, x, x, x, x, x,
  18. x, x, x, x, x, x, x, x, x, x,
  19. x, x, x, x, x, x, x, x) == 38, "");
  20. static_assert(BOOST_HANA_PP_NARG(
  21. x, x, x, x, x, x, x, x, x, x,
  22. x, x, x, x, x, x, x, x, x, x,
  23. x, x, x, x, x, x, x, x, x, x,
  24. x, x, x, x, x, x, x, x, x) == 39, "");
  25. static_assert(BOOST_HANA_PP_NARG(
  26. x, x, x, x, x, x, x, x, x, x,
  27. x, x, x, x, x, x, x, x, x, x,
  28. x, x, x, x, x, x, x, x, x, x,
  29. x, x, x, x, x, x, x, x, x, x) == 40, "");
  30. //////////////////////////////////////////////////////////////////////////////
  31. // BOOST_HANA_PP_BACK
  32. //////////////////////////////////////////////////////////////////////////////
  33. static_assert(BOOST_HANA_PP_BACK(1) == 1, "");
  34. static_assert(BOOST_HANA_PP_BACK(1, 2) == 2, "");
  35. static_assert(BOOST_HANA_PP_BACK(1, 2, 3) == 3, "");
  36. static_assert(BOOST_HANA_PP_BACK(1, 2, 3, 4) == 4, "");
  37. static_assert(BOOST_HANA_PP_BACK(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  38. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  39. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  40. 31, 32, 33, 34, 35, 36, 37, 38, 39) == 39, "");
  41. static_assert(BOOST_HANA_PP_BACK(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  42. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  43. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  44. 31, 32, 33, 34, 35, 36, 37, 38) == 38, "");
  45. static_assert(BOOST_HANA_PP_BACK(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  46. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  47. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  48. 31, 32, 33, 34, 35, 36, 37, 38, 39, 40) == 40, "");
  49. int main() {
  50. using Vector = std::vector<int>;
  51. //////////////////////////////////////////////////////////////////////////
  52. // BOOST_HANA_PP_DROP_BACK
  53. //////////////////////////////////////////////////////////////////////////
  54. {
  55. Vector args = {BOOST_HANA_PP_DROP_BACK(1)};
  56. BOOST_HANA_RUNTIME_CHECK(args.empty());
  57. }{
  58. Vector args = {BOOST_HANA_PP_DROP_BACK(1, 2)};
  59. BOOST_HANA_RUNTIME_CHECK(args == Vector{1});
  60. }{
  61. Vector args = {BOOST_HANA_PP_DROP_BACK(1, 2, 3)};
  62. BOOST_HANA_RUNTIME_CHECK(args == Vector{1, 2});
  63. }{
  64. Vector args = {BOOST_HANA_PP_DROP_BACK(1, 2, 3, 4)};
  65. BOOST_HANA_RUNTIME_CHECK(args == Vector{1, 2, 3});
  66. }{
  67. Vector args = {BOOST_HANA_PP_DROP_BACK(1, 2, 3, 4, 5)};
  68. BOOST_HANA_RUNTIME_CHECK(args == Vector{1, 2, 3, 4});
  69. }{
  70. Vector args = {BOOST_HANA_PP_DROP_BACK(
  71. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  72. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  73. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  74. 31, 32, 33, 34, 35, 36, 37, 38, 39
  75. )};
  76. BOOST_HANA_RUNTIME_CHECK(args == Vector{
  77. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  78. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  79. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  80. 31, 32, 33, 34, 35, 36, 37, 38
  81. });
  82. }{
  83. Vector args = {BOOST_HANA_PP_DROP_BACK(
  84. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  85. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  86. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  87. 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
  88. )};
  89. BOOST_HANA_RUNTIME_CHECK(args == Vector{
  90. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  91. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  92. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  93. 31, 32, 33, 34, 35, 36, 37, 38, 39
  94. });
  95. }
  96. }