lazy_templated_struct_tests.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ////////////////////////////////////////////////////////////////////////////
  2. // lazy_templated_struct_tests.cpp
  3. //
  4. // lazy templated struct test to check this works everywhere.
  5. //
  6. ////////////////////////////////////////////////////////////////////////////
  7. /*=============================================================================
  8. Copyright (c) 2001-2007 Joel de Guzman
  9. Copyright (c) 2015 John Fletcher
  10. Distributed under the Boost Software License, Version 1.0. (See accompanying
  11. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  12. ==============================================================================*/
  13. #include <boost/phoenix/core/limits.hpp>
  14. #include <boost/detail/lightweight_test.hpp>
  15. #include <boost/phoenix/core.hpp>
  16. #include <boost/phoenix/function.hpp>
  17. #include <boost/function.hpp>
  18. namespace example {
  19. namespace impl {
  20. // Example of templated struct.
  21. template <typename Result>
  22. struct what {
  23. typedef Result result_type;
  24. Result operator()(Result const & r) const
  25. {
  26. return r;
  27. }
  28. };
  29. template <typename Result>
  30. struct what0 {
  31. typedef Result result_type;
  32. Result operator()() const
  33. {
  34. return Result(100);
  35. }
  36. };
  37. }
  38. boost::function1<int, int > what_int = impl::what<int>();
  39. boost::function0<int> what0_int = impl::what0<int>();
  40. BOOST_PHOENIX_ADAPT_FUNCTION(int,what,what_int,1)
  41. BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(int,what0,what0_int)
  42. }
  43. int main()
  44. {
  45. int a = 99;
  46. using boost::phoenix::arg_names::arg1;
  47. BOOST_TEST(example::what_int(a) == a);
  48. BOOST_TEST(example::what(a)() == a);
  49. BOOST_TEST(example::what(arg1)(a) == a);
  50. BOOST_TEST(example::what0_int() == 100);
  51. BOOST_TEST(example::what0()() == 100);
  52. return boost::report_errors();
  53. }