protect.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // protect.hpp
  3. //
  4. // Copyright 2012 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/proto/core.hpp>
  8. #include <boost/proto/transform/make.hpp>
  9. #include <boost/type_traits/add_pointer.hpp>
  10. #include <boost/type_traits/remove_pointer.hpp>
  11. #include <boost/test/unit_test.hpp>
  12. namespace proto=boost::proto;
  13. using proto::_;
  14. template<typename T>
  15. struct identity
  16. {
  17. typedef T type;
  18. };
  19. struct TestWithMake
  20. : proto::make< proto::protect<_> >
  21. {};
  22. struct TestWithMake1
  23. : proto::make< identity<proto::protect<_> > >
  24. {};
  25. struct TestWithMake2
  26. : proto::make< identity<proto::protect<int> > >
  27. {};
  28. struct TestWithMake3
  29. : proto::make< identity<proto::protect<identity<_> > > >
  30. {};
  31. struct TestWithMake4
  32. : proto::make< identity<proto::protect<identity<int> > > >
  33. {};
  34. struct TestWithMake5
  35. : proto::make< identity<proto::protect<identity<identity<int> > > > >
  36. {};
  37. void test_protect_with_make()
  38. {
  39. proto::terminal<int>::type i = {42};
  40. _ t = TestWithMake()(i);
  41. _ t1 = TestWithMake1()(i);
  42. int t2 = TestWithMake2()(i);
  43. identity<_> t3 = TestWithMake3()(i);
  44. identity<int> t4 = TestWithMake4()(i);
  45. identity<identity<int> > t5 = TestWithMake5()(i);
  46. }
  47. //struct TestWithWhen
  48. // : proto::when<_, proto::protect<_>() >
  49. //{};
  50. struct TestWithWhen1
  51. : proto::when<_, identity<proto::protect<_> >() >
  52. {};
  53. struct TestWithWhen2
  54. : proto::when<_, identity<proto::protect<int> >() >
  55. {};
  56. struct TestWithWhen3
  57. : proto::when<_, identity<proto::protect<identity<_> > >() >
  58. {};
  59. struct TestWithWhen4
  60. : proto::when<_, identity<proto::protect<identity<int> > >() >
  61. {};
  62. struct TestWithWhen5
  63. : proto::when<_, identity<proto::protect<identity<identity<int> > > >() >
  64. {};
  65. void test_protect_with_when()
  66. {
  67. proto::terminal<int>::type i = {42};
  68. //_ t = TestWithWhen()(i);
  69. _ t1 = TestWithWhen1()(i);
  70. int t2 = TestWithWhen2()(i);
  71. identity<_> t3 = TestWithWhen3()(i);
  72. identity<int> t4 = TestWithWhen4()(i);
  73. identity<identity<int> > t5 = TestWithWhen5()(i);
  74. }
  75. using namespace boost::unit_test;
  76. ///////////////////////////////////////////////////////////////////////////////
  77. // init_unit_test_suite
  78. //
  79. test_suite* init_unit_test_suite( int argc, char* argv[] )
  80. {
  81. test_suite *test = BOOST_TEST_SUITE("test proto::protect");
  82. test->add(BOOST_TEST_CASE(&test_protect_with_make));
  83. test->add(BOOST_TEST_CASE(&test_protect_with_when));
  84. return test;
  85. }