compile_is_expr.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2016-2018 T. Zachary Laine
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/yap/expression.hpp>
  7. namespace yap = boost::yap;
  8. struct alternate_expr_1
  9. {
  10. static const yap::expr_kind kind = yap::expr_kind::plus;
  11. boost::hana::tuple<> elements;
  12. };
  13. struct alternate_expr_2
  14. {
  15. static const yap::expr_kind kind = yap::expr_kind::plus;
  16. boost::hana::tuple<int, double> elements;
  17. };
  18. struct non_expr_1
  19. {};
  20. struct non_expr_2
  21. {
  22. boost::hana::tuple<int, double> elements;
  23. };
  24. struct non_expr_3
  25. {
  26. static const int kind = 0;
  27. boost::hana::tuple<int, double> elements;
  28. };
  29. struct non_expr_4
  30. {
  31. int kind;
  32. boost::hana::tuple<int, double> elements;
  33. };
  34. struct non_expr_5
  35. {
  36. static const yap::expr_kind kind = yap::expr_kind::plus;
  37. };
  38. struct non_expr_6
  39. {
  40. static const yap::expr_kind kind = yap::expr_kind::plus;
  41. int elements;
  42. };
  43. void compile_is_expr()
  44. {
  45. static_assert(
  46. yap::is_expr<yap::terminal<yap::expression, double>>::value, "");
  47. static_assert(
  48. yap::is_expr<yap::terminal<yap::expression, double> const>::value, "");
  49. static_assert(
  50. yap::is_expr<yap::terminal<yap::expression, double> const &>::value,
  51. "");
  52. static_assert(
  53. yap::is_expr<yap::terminal<yap::expression, double> &>::value, "");
  54. static_assert(
  55. yap::is_expr<yap::terminal<yap::expression, double> &&>::value, "");
  56. {
  57. using namespace yap::literals;
  58. static_assert(yap::is_expr<decltype(1_p)>::value, "");
  59. }
  60. static_assert(
  61. yap::is_expr<yap::expression<
  62. yap::expr_kind::unary_plus,
  63. boost::hana::tuple<yap::terminal<yap::expression, double>>>>::value,
  64. "");
  65. static_assert(
  66. yap::is_expr<yap::expression<
  67. yap::expr_kind::plus,
  68. boost::hana::tuple<
  69. yap::terminal<yap::expression, double>,
  70. yap::terminal<yap::expression, double>>>>::value,
  71. "");
  72. static_assert(yap::is_expr<alternate_expr_1>::value, "");
  73. static_assert(yap::is_expr<alternate_expr_2>::value, "");
  74. static_assert(!yap::is_expr<int>::value, "");
  75. static_assert(!yap::is_expr<non_expr_1>::value, "");
  76. static_assert(!yap::is_expr<non_expr_2>::value, "");
  77. static_assert(!yap::is_expr<non_expr_3>::value, "");
  78. static_assert(!yap::is_expr<non_expr_4>::value, "");
  79. static_assert(!yap::is_expr<non_expr_5>::value, "");
  80. static_assert(!yap::is_expr<non_expr_6>::value, "");
  81. }