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

http://hadesmem.googlecode.com/ · C++ Header · 112 lines · 84 code · 19 blank · 9 comment · 7 complexity · e9194c8adaf79a9e48da398782df4d34 MD5 · raw file

  1. // Copyright David Abrahams, Daniel Wallin 2005. 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. #ifndef BASICS_050424_HPP
  6. #define BASICS_050424_HPP
  7. #include <boost/parameter/keyword.hpp>
  8. #include <boost/parameter/parameters.hpp>
  9. #include <boost/type_traits/is_same.hpp>
  10. #include <boost/assert.hpp>
  11. #include <boost/mpl/assert.hpp>
  12. #include <cstring>
  13. #include <boost/detail/lightweight_test.hpp>
  14. namespace test {
  15. BOOST_PARAMETER_KEYWORD(tag, name)
  16. BOOST_PARAMETER_KEYWORD(tag, value)
  17. BOOST_PARAMETER_KEYWORD(tag, index)
  18. BOOST_PARAMETER_KEYWORD(tag, tester)
  19. using namespace boost::parameter;
  20. struct f_parameters // vc6 is happier with inheritance than with a typedef
  21. : parameters<
  22. tag::tester
  23. , tag::name
  24. , tag::value
  25. , tag::index
  26. >
  27. {};
  28. inline double value_default()
  29. {
  30. return 666.222;
  31. }
  32. template <class T>
  33. inline bool equal(T const& x, T const& y)
  34. {
  35. return x == y;
  36. }
  37. inline bool equal(char const* s1, char const* s2)
  38. {
  39. using namespace std;
  40. return !strcmp(s1,s2);
  41. }
  42. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  43. inline bool equal(char* s1, char* s2)
  44. {
  45. using namespace std;
  46. return !strcmp(s1,s2);
  47. }
  48. #endif
  49. template <class Name, class Value, class Index>
  50. struct values_t
  51. {
  52. values_t(Name const& n, Value const& v, Index const& i)
  53. : n(n), v(v), i(i)
  54. {}
  55. template <class Name_, class Value_, class Index_>
  56. void operator()(Name_ const& n_, Value_ const& v_, Index_ const& i_) const
  57. {
  58. // Only VC and its emulators fail this; they seem to have
  59. // problems with deducing the constness of string literal
  60. // arrays.
  61. #if defined(_MSC_VER) \
  62. && (BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 700) \
  63. || BOOST_WORKAROUND(BOOST_MSVC, < 1310)) \
  64. || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  65. # else
  66. BOOST_MPL_ASSERT((boost::is_same<Index,Index_>));
  67. BOOST_MPL_ASSERT((boost::is_same<Value,Value_>));
  68. BOOST_MPL_ASSERT((boost::is_same<Name,Name_>));
  69. #endif
  70. BOOST_TEST(equal(n, n_));
  71. BOOST_TEST(equal(v, v_));
  72. BOOST_TEST(equal(i, i_));
  73. }
  74. Name const& n;
  75. Value const& v;
  76. Index const& i;
  77. };
  78. template <class Name, class Value, class Index>
  79. inline values_t<Name,Value,Index>
  80. values(Name const& n, Value const& v, Index const& i)
  81. {
  82. return values_t<Name,Value,Index>(n,v,i);
  83. }
  84. } // namespace test
  85. // GCC2 has a problem with char (&)[] deduction, so we'll cast string
  86. // literals there.
  87. #undef S
  88. #if BOOST_WORKAROUND(__GNUC__, == 2) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  89. # define S(s) (char const*)s
  90. #else
  91. # define S(s) s
  92. #endif
  93. #endif // BASICS_050424_HPP