Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/parameter/test/basics.hpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

  • Property svn:executable set to *
File size: 2.6 KB
Line 
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
12namespace test {
13
14BOOST_PARAMETER_KEYWORD(tag, name)
15BOOST_PARAMETER_KEYWORD(tag, value)
16BOOST_PARAMETER_KEYWORD(tag, index)
17BOOST_PARAMETER_KEYWORD(tag, tester)
18
19using namespace boost::parameter;
20
21struct 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
30inline double value_default()
31{
32    return 666.222;
33}
34
35template <class T>
36inline bool equal(T const& x, T const& y)
37{
38    return x == y;
39}
40
41inline 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))
47inline bool equal(char* s1, char* s2)
48{
49    return !strcmp(s1,s2);
50}
51#endif
52
53template <class Name, class Value, class Index>
54struct 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
86template <class Name, class Value, class Index>
87inline values_t<Name,Value,Index>
88values(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
Note: See TracBrowser for help on using the repository browser.