/Src/Dependencies/Boost/libs/parameter/test/basics.cpp

http://hadesmem.googlecode.com/ · C++ · 112 lines · 84 code · 20 blank · 8 comment · 1 complexity · e0db1c6d4ffc7d5281034f4247ac7912 MD5 · raw file

  1. // Copyright David Abrahams, Daniel Wallin 2003. Use, modification and
  2. // distribution is subject to the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/parameter.hpp>
  6. #include <cassert>
  7. #include <string.h>
  8. #include <boost/bind.hpp>
  9. #include <boost/ref.hpp>
  10. #include "basics.hpp"
  11. namespace test
  12. {
  13. // A separate function for getting the "value" key, so we can deduce
  14. // F and use lazy_binding on it.
  15. template <class Params, class F>
  16. typename boost::parameter::lazy_binding<Params,tag::value,F>::type
  17. extract_value(Params const& p, F const& f)
  18. {
  19. typename boost::parameter::lazy_binding<
  20. Params, tag::value, F
  21. >::type v = p[value || f ];
  22. return v;
  23. }
  24. template<class Params>
  25. int f_impl(Params const& p)
  26. {
  27. typename boost::parameter::binding<Params, tag::name>::type
  28. n = p[name];
  29. typename boost::parameter::binding<
  30. Params, tag::value, double
  31. >::type v = extract_value(p, boost::bind(&value_default));
  32. typename boost::parameter::binding<
  33. Params, tag::index, int
  34. >::type i =
  35. #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
  36. p[test::index | 999];
  37. #else
  38. p[index | 999];
  39. #endif
  40. p[tester](n,v,i);
  41. return 1;
  42. }
  43. template<class Tester, class Name, class Value, class Index>
  44. int f(Tester const& t, const Name& name_,
  45. const Value& value_, const Index& index_)
  46. {
  47. return f_impl(f_parameters()(t, name_, value_, index_));
  48. }
  49. template<class Tester, class Name, class Value>
  50. int f(Tester const& t, const Name& name_, const Value& value_)
  51. {
  52. return f_impl(f_parameters()(t, name_, value_));
  53. }
  54. template<class Tester, class Name>
  55. int f(Tester const& t, const Name& name_)
  56. {
  57. return f_impl(f_parameters()(t, name_));
  58. }
  59. template<class Params>
  60. int f_list(Params const& params)
  61. {
  62. return f_impl(params);
  63. }
  64. }
  65. int main()
  66. {
  67. using test::f;
  68. using test::f_list;
  69. using test::name;
  70. using test::value;
  71. using test::index;
  72. using test::tester;
  73. f(
  74. test::values(S("foo"), S("bar"), S("baz"))
  75. , S("foo"), S("bar"), S("baz")
  76. );
  77. int x = 56;
  78. f(
  79. test::values("foo", 666.222, 56)
  80. , index = boost::ref(x), name = "foo"
  81. );
  82. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  83. // No comma operator available on Borland
  84. f_list((
  85. tester = test::values("foo", 666.222, 56)
  86. , index = boost::ref(x)
  87. , name = "foo"
  88. ));
  89. #endif
  90. //f(index = 56, name = 55); // won't compile
  91. return boost::report_errors();
  92. }