~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to libs/boost-lib/boost/test/utils/named_params.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  (C) Copyright Gennadiy Rozental 2005.
 
1
//  (C) Copyright Gennadiy Rozental 2005-2008.
2
2
//  Distributed under the Boost Software License, Version 1.0.
3
3
//  (See accompanying file LICENSE_1_0.txt or copy at 
4
4
//  http://www.boost.org/LICENSE_1_0.txt)
5
5
 
6
6
//  See http://www.boost.org/libs/test for the library home page.
7
7
//
8
 
//  File        : $RCSfile: named_params.hpp,v $
 
8
//  File        : $RCSfile$
9
9
//
10
 
//  Version     : $Revision: 1.4 $
 
10
//  Version     : $Revision: 54633 $
11
11
//
12
12
//  Description : facilities for named function parameters support
13
13
// ***************************************************************************
23
23
#include <boost/test/utils/rtti.hpp>
24
24
#include <boost/test/utils/assign_op.hpp>
25
25
 
 
26
#include <boost/type_traits/remove_reference.hpp>
 
27
 
 
28
#include <boost/test/detail/suppress_warnings.hpp>
 
29
 
26
30
//____________________________________________________________________________//
27
31
 
28
32
namespace boost {
62
66
 
63
67
struct nil {
64
68
    template<typename T>
 
69
#if defined(__GNUC__) || defined(__HP_aCC) || defined(__EDG__) || defined(__SUNPRO_CC)
65
70
    operator T() const
 
71
#else
 
72
    operator T const&() const
 
73
#endif
66
74
    { report_access_to_invalid_parameter(); static T* v = 0; return *v; }
67
75
 
 
76
    template<typename T>
 
77
    T any_cast() const
 
78
    { report_access_to_invalid_parameter(); static typename remove_reference<T>::type* v = 0; return *v; }
 
79
 
68
80
    template<typename Arg1>
69
81
    nil operator()( Arg1 const& )
70
82
    { report_access_to_invalid_parameter(); return nil(); }
80
92
    // Visitation support
81
93
    template<typename Visitor>
82
94
    void            apply_to( Visitor& V ) const {}
 
95
 
 
96
    static nil&     inst() { static nil s_inst; return s_inst; }
 
97
private:
 
98
    nil() {}
83
99
};
84
100
    
85
101
// ************************************************************************** //
95
111
 
96
112
//____________________________________________________________________________//
97
113
 
98
 
#if BOOST_WORKAROUND( __SUNPRO_CC, == 0x530 )
99
 
 
100
 
struct unknown_id_helper {
101
 
    template<typename UnknownId>
102
 
    nil     operator[]( keyword<UnknownId,false> kw ) const { return nil(); }
103
 
 
104
 
    template<typename UnknownId>
105
 
    bool    has( keyword<UnknownId,false> ) const           { return false; }
106
 
};
107
 
 
108
 
#endif
109
 
 
110
 
//____________________________________________________________________________//
111
 
 
112
114
// ************************************************************************** //
113
115
// **************             named_parameter_combine          ************** //
114
116
// ************************************************************************** //
115
117
 
116
118
template<typename NP, typename Rest = nil>
117
 
struct named_parameter_combine : Rest, named_parameter_base<named_parameter_combine<NP,Rest> > {
 
119
struct named_parameter_combine 
 
120
: Rest
 
121
, named_parameter_base<named_parameter_combine<NP,Rest> > {
118
122
    typedef typename NP::ref_type  res_type;
119
123
    typedef named_parameter_combine<NP,Rest> self_type;
120
124
 
121
125
    // Constructor
122
126
    named_parameter_combine( NP const& np, Rest const& r )
123
 
    : Rest( r ), m_param( np ) {}
 
127
    : Rest( r )
 
128
    , m_param( np )
 
129
    {}
124
130
 
125
131
    // Access methods
126
132
    res_type    operator[]( keyword<typename NP::id,true> kw ) const    { return m_param[kw]; }
127
133
    res_type    operator[]( keyword<typename NP::id,false> kw ) const   { return m_param[kw]; }
128
134
    using       Rest::operator[];
129
135
 
130
 
    bool        has( keyword<typename NP::id,false> ) const             { return true; }
 
136
    bool        has( keyword<typename NP::id,false> kw ) const          { return m_param.has( kw ); }
131
137
    using       Rest::has;
132
138
 
133
 
    #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
 
139
    void        erase( keyword<typename NP::id,false> kw ) const        { m_param.erase( kw ); }
 
140
    using       Rest::erase;
 
141
 
 
142
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) || \
 
143
    BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0610))
134
144
    template<typename NP>
135
145
    named_parameter_combine<NP,self_type> operator,( NP const& np ) const
136
146
    { return named_parameter_combine<NP,self_type>( np, *this ); }
137
 
    #else
 
147
#else
138
148
    using       named_parameter_base<named_parameter_combine<NP,Rest> >::operator,;
139
 
    #endif
 
149
#endif
140
150
 
141
151
    // Visitation support
142
152
    template<typename Visitor>
154
164
} // namespace nfp_detail
155
165
 
156
166
// ************************************************************************** //
157
 
// **************             named_parameter_combine          ************** //
 
167
// **************                 named_parameter              ************** //
158
168
// ************************************************************************** //
159
169
 
160
170
template<typename T, typename unique_id,typename ReferenceType=T&>
161
171
struct named_parameter
162
172
: nfp_detail::named_parameter_base<named_parameter<T, unique_id,ReferenceType> >
163
 
#if BOOST_WORKAROUND( __SUNPRO_CC, == 0x530 )
164
 
, nfp_detail::unknown_id_helper
165
 
#endif
166
173
{
 
174
    typedef nfp_detail::nil nil_t;
167
175
    typedef T               data_type;
168
176
    typedef ReferenceType   ref_type;
169
177
    typedef unique_id       id;
170
178
 
171
179
    // Constructor
172
 
    explicit        named_parameter( ref_type v ) : m_value( v ) {}
 
180
    explicit        named_parameter( ref_type v ) 
 
181
    : m_value( v )
 
182
    , m_erased( false )
 
183
    {}
 
184
    named_parameter( named_parameter const& np )
 
185
    : m_value( np.m_value )
 
186
    , m_erased( np.m_erased )
 
187
    {}
173
188
 
174
189
    // Access methods
175
 
    ref_type        operator[]( keyword<unique_id,true> ) const     { return m_value; }
176
 
    ref_type        operator[]( keyword<unique_id,false> ) const    { return m_value; }
177
 
#if BOOST_WORKAROUND( __SUNPRO_CC, == 0x530 )
178
 
    using           nfp_detail::unknown_id_helper::operator[];
179
 
#else
 
190
    ref_type        operator[]( keyword<unique_id,true> ) const     { return m_erased ? nil_t::inst().template any_cast<ref_type>() :  m_value; }
 
191
    ref_type        operator[]( keyword<unique_id,false> ) const    { return m_erased ? nil_t::inst().template any_cast<ref_type>() :  m_value; }
180
192
    template<typename UnknownId>
181
 
    nfp_detail::nil  operator[]( keyword<UnknownId,false> ) const   { return nfp_detail::nil(); }
182
 
#endif
 
193
    nil_t           operator[]( keyword<UnknownId,false> ) const    { return nil_t::inst(); }
183
194
 
184
 
    bool            has( keyword<unique_id,false> ) const           { return true; }
185
 
#if BOOST_WORKAROUND( __SUNPRO_CC, == 0x530 )
186
 
    using           nfp_detail::unknown_id_helper::has;
187
 
#else
 
195
    bool            has( keyword<unique_id,false> ) const           { return !m_erased; }
188
196
    template<typename UnknownId>
189
197
    bool            has( keyword<UnknownId,false> ) const           { return false; }
190
 
#endif
 
198
 
 
199
    void            erase( keyword<unique_id,false> ) const         { m_erased = true; }
 
200
    template<typename UnknownId>
 
201
    void            erase( keyword<UnknownId,false> ) const         {}
191
202
 
192
203
    // Visitation support
193
204
    template<typename Visitor>
199
210
private:
200
211
    // Data members
201
212
    ref_type        m_value;
 
213
    mutable bool    m_erased;
202
214
};
203
215
 
204
216
//____________________________________________________________________________//
209
221
 
210
222
namespace nfp_detail {
211
223
typedef named_parameter<char, struct no_params_type_t,char> no_params_type;
212
 
}
 
224
} // namespace nfp_detail
213
225
 
214
226
namespace {
215
227
nfp_detail::no_params_type no_params( '\0' );
292
304
{
293
305
    using namespace unit_test;
294
306
 
295
 
    assign_op( target, src, 0 );
 
307
    assign_op( target, src, static_cast<int>(0) );
296
308
}
297
309
 
298
310
//____________________________________________________________________________//
311
323
 
312
324
} // namespace boost
313
325
 
314
 
// ***************************************************************************
315
 
//   Revision History:
316
 
//  
317
 
//  $Log: named_params.hpp,v $
318
 
//  Revision 1.4  2005/06/13 10:35:08  schoepflin
319
 
//  Enable optionally_assign() overload workaround for Tru64/CXX-6.5 as well.
320
 
//
321
 
//  Revision 1.3  2005/06/05 18:10:59  grafik
322
 
//  named_param.hpp; Work around CW not handling operator, using declaration, by using a real operator,().
323
 
//  token_iterator_test.cpp; Work around CW-8 confused with array initialization.
324
 
//
325
 
//  Revision 1.2  2005/05/03 05:02:49  rogeeff
326
 
//  como fixes
327
 
//
328
 
//  Revision 1.1  2005/04/12 06:48:12  rogeeff
329
 
//  Runtime.Param library initial commit
330
 
//
331
 
// ***************************************************************************
 
326
#include <boost/test/detail/enable_warnings.hpp>
332
327
 
333
328
#endif // BOOST_TEST_NAMED_PARAM_022505GER
334
329