PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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