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