1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/concept_check.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,1056 @@
1.4 +//
1.5 +// (C) Copyright Jeremy Siek 2000.
1.6 +// Distributed under the Boost Software License, Version 1.0. (See
1.7 +// accompanying file LICENSE_1_0.txt or copy at
1.8 +// http://www.boost.org/LICENSE_1_0.txt)
1.9 +//
1.10 +// Revision History:
1.11 +// 05 May 2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek)
1.12 +// 02 April 2001: Removed limits header altogether. (Jeremy Siek)
1.13 +// 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock)
1.14 +//
1.15 +
1.16 +// See http://www.boost.org/libs/concept_check for documentation.
1.17 +
1.18 +#ifndef BOOST_CONCEPT_CHECKS_HPP
1.19 +#define BOOST_CONCEPT_CHECKS_HPP
1.20 +
1.21 +#include <boost/config.hpp>
1.22 +#include <boost/iterator.hpp>
1.23 +#include <boost/type_traits/conversion_traits.hpp>
1.24 +#include <utility>
1.25 +#include <boost/type_traits/conversion_traits.hpp>
1.26 +#include <boost/static_assert.hpp>
1.27 +#include <boost/mpl/identity.hpp>
1.28 +
1.29 +
1.30 +#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__BORLANDC__)
1.31 +#define BOOST_FPTR
1.32 +#else
1.33 +#define BOOST_FPTR &
1.34 +#endif
1.35 +
1.36 +namespace boost {
1.37 +
1.38 +/*
1.39 + "inline" is used for ignore_unused_variable_warning()
1.40 + and function_requires() to make sure there is no
1.41 + overhead with g++.
1.42 + */
1.43 +
1.44 +template <class T> inline void ignore_unused_variable_warning(const T&) { }
1.45 +
1.46 +// the unused, defaulted parameter is a workaround for MSVC and Compaq C++
1.47 +template <class Concept>
1.48 +inline void function_requires(mpl::identity<Concept>* = 0)
1.49 +{
1.50 +#if !defined(NDEBUG)
1.51 + void (Concept::*x)() = BOOST_FPTR Concept::constraints;
1.52 + ignore_unused_variable_warning(x);
1.53 +#endif
1.54 +}
1.55 +
1.56 +#define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
1.57 + typedef void (ns::concept <type_var>::* func##type_var##concept)(); \
1.58 + template <func##type_var##concept Tp1_> \
1.59 + struct concept_checking_##type_var##concept { }; \
1.60 + typedef concept_checking_##type_var##concept< \
1.61 + BOOST_FPTR ns::concept<type_var>::constraints> \
1.62 + concept_checking_typedef_##type_var##concept
1.63 +
1.64 +#define BOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \
1.65 + typedef void (ns::concept <type_var1,type_var2>::* \
1.66 + func##type_var1##type_var2##concept)(); \
1.67 + template <func##type_var1##type_var2##concept Tp1_> \
1.68 + struct concept_checking_##type_var1##type_var2##concept { }; \
1.69 + typedef concept_checking_##type_var1##type_var2##concept< \
1.70 + BOOST_FPTR ns::concept<type_var1,type_var2>::constraints> \
1.71 + concept_checking_typedef_##type_var1##type_var2##concept
1.72 +
1.73 +#define BOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \
1.74 + typedef void (ns::concept <tv1,tv2,tv3>::* \
1.75 + func##tv1##tv2##tv3##concept)(); \
1.76 + template <func##tv1##tv2##tv3##concept Tp1_> \
1.77 + struct concept_checking_##tv1##tv2##tv3##concept { }; \
1.78 + typedef concept_checking_##tv1##tv2##tv3##concept< \
1.79 + BOOST_FPTR ns::concept<tv1,tv2,tv3>::constraints> \
1.80 + concept_checking_typedef_##tv1##tv2##tv3##concept
1.81 +
1.82 +#define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
1.83 + typedef void (ns::concept <tv1,tv2,tv3,tv4>::* \
1.84 + func##tv1##tv2##tv3##tv4##concept)(); \
1.85 + template <func##tv1##tv2##tv3##tv4##concept Tp1_> \
1.86 + struct concept_checking_##tv1##tv2##tv3##tv4##concept { }; \
1.87 + typedef concept_checking_##tv1##tv2##tv3##tv4##concept< \
1.88 + BOOST_FPTR ns::concept<tv1,tv2,tv3,tv4>::constraints> \
1.89 + concept_checking_typedef_##tv1##tv2##tv3##tv4##concept
1.90 +
1.91 +// NOTE: The BOOST_CLASS_REQUIRES (with an 'S' at the end) is deprecated.
1.92 +
1.93 +// The BOOST_CLASS_REQUIRES macros use function pointers as
1.94 +// template parameters, which VC++ does not support.
1.95 +
1.96 +#if defined(BOOST_NO_FUNCTION_PTR_TEMPLATE_PARAMETERS)
1.97 +
1.98 +#define BOOST_CLASS_REQUIRES(type_var, concept)
1.99 +#define BOOST_CLASS_REQUIRES2(type_var1, type_var2, concept)
1.100 +#define BOOST_CLASS_REQUIRES3(type_var1, type_var2, type_var3, concept)
1.101 +#define BOOST_CLASS_REQUIRES4(type_var1, type_var2, type_var3, type_var4, concept)
1.102 +
1.103 +#else
1.104 +
1.105 +#define BOOST_CLASS_REQUIRES(type_var, concept) \
1.106 + typedef void (concept <type_var>::* func##type_var##concept)(); \
1.107 + template <func##type_var##concept Tp1_> \
1.108 + struct concept_checking_##type_var##concept { }; \
1.109 + typedef concept_checking_##type_var##concept< \
1.110 + BOOST_FPTR concept <type_var>::constraints> \
1.111 + concept_checking_typedef_##type_var##concept
1.112 +
1.113 +#define BOOST_CLASS_REQUIRES2(type_var1, type_var2, concept) \
1.114 + typedef void (concept <type_var1,type_var2>::* func##type_var1##type_var2##concept)(); \
1.115 + template <func##type_var1##type_var2##concept Tp1_> \
1.116 + struct concept_checking_##type_var1##type_var2##concept { }; \
1.117 + typedef concept_checking_##type_var1##type_var2##concept< \
1.118 + BOOST_FPTR concept <type_var1,type_var2>::constraints> \
1.119 + concept_checking_typedef_##type_var1##type_var2##concept
1.120 +
1.121 +#define BOOST_CLASS_REQUIRES3(type_var1, type_var2, type_var3, concept) \
1.122 + typedef void (concept <type_var1,type_var2,type_var3>::* func##type_var1##type_var2##type_var3##concept)(); \
1.123 + template <func##type_var1##type_var2##type_var3##concept Tp1_> \
1.124 + struct concept_checking_##type_var1##type_var2##type_var3##concept { }; \
1.125 + typedef concept_checking_##type_var1##type_var2##type_var3##concept< \
1.126 + BOOST_FPTR concept <type_var1,type_var2,type_var3>::constraints> \
1.127 + concept_checking_typedef_##type_var1##type_var2##type_var3##concept
1.128 +
1.129 +#define BOOST_CLASS_REQUIRES4(type_var1, type_var2, type_var3, type_var4, concept) \
1.130 + typedef void (concept <type_var1,type_var2,type_var3,type_var4>::* func##type_var1##type_var2##type_var3##type_var4##concept)(); \
1.131 + template <func##type_var1##type_var2##type_var3##type_var4##concept Tp1_> \
1.132 + struct concept_checking_##type_var1##type_var2##type_var3##type_var4##concept { }; \
1.133 + typedef concept_checking_##type_var1##type_var2##type_var3##type_var4##concept< \
1.134 + BOOST_FPTR concept <type_var1,type_var2,type_var3,type_var4>::constraints> \
1.135 + concept_checking_typedef_##type_var1##type_var2##type_var3##type_var4##concept
1.136 +
1.137 +
1.138 +#endif
1.139 +
1.140 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.141 +template <class T, class U>
1.142 +struct require_same { };
1.143 +
1.144 +template <class T>
1.145 +struct require_same<T,T> { typedef T type; };
1.146 +#else
1.147 +// This version does not perform checking, but will not do any harm.
1.148 +template <class T, class U>
1.149 +struct require_same { typedef T type; };
1.150 +#endif
1.151 +
1.152 + template <class T>
1.153 + struct IntegerConcept {
1.154 + void constraints() {
1.155 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.156 + x.error_type_must_be_an_integer_type();
1.157 +#endif
1.158 + }
1.159 + T x;
1.160 + };
1.161 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.162 + template <> struct IntegerConcept<short> { void constraints() {} };
1.163 + template <> struct IntegerConcept<unsigned short> { void constraints() {} };
1.164 + template <> struct IntegerConcept<int> { void constraints() {} };
1.165 + template <> struct IntegerConcept<unsigned int> { void constraints() {} };
1.166 + template <> struct IntegerConcept<long> { void constraints() {} };
1.167 + template <> struct IntegerConcept<unsigned long> { void constraints() {} };
1.168 + // etc.
1.169 +#endif
1.170 +
1.171 + template <class T>
1.172 + struct SignedIntegerConcept {
1.173 + void constraints() {
1.174 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.175 + x.error_type_must_be_a_signed_integer_type();
1.176 +#endif
1.177 + }
1.178 + T x;
1.179 + };
1.180 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.181 + template <> struct SignedIntegerConcept<short> { void constraints() {} };
1.182 + template <> struct SignedIntegerConcept<int> { void constraints() {} };
1.183 + template <> struct SignedIntegerConcept<long> { void constraints() {} };
1.184 +# if defined(BOOST_HAS_LONG_LONG)
1.185 + template <> struct SignedIntegerConcept< ::boost::long_long_type> { void constraints() {} };
1.186 +# endif
1.187 + // etc.
1.188 +#endif
1.189 +
1.190 + template <class T>
1.191 + struct UnsignedIntegerConcept {
1.192 + void constraints() {
1.193 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.194 + x.error_type_must_be_an_unsigned_integer_type();
1.195 +#endif
1.196 + }
1.197 + T x;
1.198 + };
1.199 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.200 + template <> struct UnsignedIntegerConcept<unsigned short>
1.201 + { void constraints() {} };
1.202 + template <> struct UnsignedIntegerConcept<unsigned int>
1.203 + { void constraints() {} };
1.204 + template <> struct UnsignedIntegerConcept<unsigned long>
1.205 + { void constraints() {} };
1.206 + // etc.
1.207 +#endif
1.208 +
1.209 + //===========================================================================
1.210 + // Basic Concepts
1.211 +
1.212 + template <class TT>
1.213 + struct DefaultConstructibleConcept
1.214 + {
1.215 + void constraints() {
1.216 + TT a; // require default constructor
1.217 + ignore_unused_variable_warning(a);
1.218 + }
1.219 + };
1.220 +
1.221 + template <class TT>
1.222 + struct AssignableConcept
1.223 + {
1.224 + void constraints() {
1.225 +#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
1.226 + a = a; // require assignment operator
1.227 +#endif
1.228 + const_constraints(a);
1.229 + }
1.230 + void const_constraints(const TT& b) {
1.231 +#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
1.232 + a = b; // const required for argument to assignment
1.233 +#endif
1.234 + }
1.235 + TT a;
1.236 + };
1.237 +
1.238 + template <class TT>
1.239 + struct CopyConstructibleConcept
1.240 + {
1.241 + void constraints() {
1.242 + TT a(b); // require copy constructor
1.243 + TT* ptr = &a; // require address of operator
1.244 + const_constraints(a);
1.245 + ignore_unused_variable_warning(ptr);
1.246 + }
1.247 + void const_constraints(const TT& a) {
1.248 + TT c(a); // require const copy constructor
1.249 + const TT* ptr = &a; // require const address of operator
1.250 + ignore_unused_variable_warning(c);
1.251 + ignore_unused_variable_warning(ptr);
1.252 + }
1.253 + TT b;
1.254 + };
1.255 +
1.256 + // The SGI STL version of Assignable requires copy constructor and operator=
1.257 + template <class TT>
1.258 + struct SGIAssignableConcept
1.259 + {
1.260 + void constraints() {
1.261 + TT b(a);
1.262 +#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
1.263 + a = a; // require assignment operator
1.264 +#endif
1.265 + const_constraints(a);
1.266 + ignore_unused_variable_warning(b);
1.267 + }
1.268 + void const_constraints(const TT& b) {
1.269 + TT c(b);
1.270 +#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
1.271 + a = b; // const required for argument to assignment
1.272 +#endif
1.273 + ignore_unused_variable_warning(c);
1.274 + }
1.275 + TT a;
1.276 + };
1.277 +
1.278 + template <class X, class Y>
1.279 + struct ConvertibleConcept
1.280 + {
1.281 + void constraints() {
1.282 + Y y = x;
1.283 + ignore_unused_variable_warning(y);
1.284 + }
1.285 + X x;
1.286 + };
1.287 +
1.288 + // The C++ standard requirements for many concepts talk about return
1.289 + // types that must be "convertible to bool". The problem with this
1.290 + // requirement is that it leaves the door open for evil proxies that
1.291 + // define things like operator|| with strange return types. Two
1.292 + // possible solutions are:
1.293 + // 1) require the return type to be exactly bool
1.294 + // 2) stay with convertible to bool, and also
1.295 + // specify stuff about all the logical operators.
1.296 + // For now we just test for convertible to bool.
1.297 + template <class TT>
1.298 + void require_boolean_expr(const TT& t) {
1.299 + bool x = t;
1.300 + ignore_unused_variable_warning(x);
1.301 + }
1.302 +
1.303 + template <class TT>
1.304 + struct EqualityComparableConcept
1.305 + {
1.306 + void constraints() {
1.307 + require_boolean_expr(a == b);
1.308 + require_boolean_expr(a != b);
1.309 + }
1.310 + TT a, b;
1.311 + };
1.312 +
1.313 + template <class TT>
1.314 + struct LessThanComparableConcept
1.315 + {
1.316 + void constraints() {
1.317 + require_boolean_expr(a < b);
1.318 + }
1.319 + TT a, b;
1.320 + };
1.321 +
1.322 + // This is equivalent to SGI STL's LessThanComparable.
1.323 + template <class TT>
1.324 + struct ComparableConcept
1.325 + {
1.326 + void constraints() {
1.327 + require_boolean_expr(a < b);
1.328 + require_boolean_expr(a > b);
1.329 + require_boolean_expr(a <= b);
1.330 + require_boolean_expr(a >= b);
1.331 + }
1.332 + TT a, b;
1.333 + };
1.334 +
1.335 +#define BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(OP,NAME) \
1.336 + template <class First, class Second> \
1.337 + struct NAME { \
1.338 + void constraints() { (void)constraints_(); } \
1.339 + bool constraints_() { \
1.340 + return a OP b; \
1.341 + } \
1.342 + First a; \
1.343 + Second b; \
1.344 + }
1.345 +
1.346 +#define BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(OP,NAME) \
1.347 + template <class Ret, class First, class Second> \
1.348 + struct NAME { \
1.349 + void constraints() { (void)constraints_(); } \
1.350 + Ret constraints_() { \
1.351 + return a OP b; \
1.352 + } \
1.353 + First a; \
1.354 + Second b; \
1.355 + }
1.356 +
1.357 + BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, EqualOpConcept);
1.358 + BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(!=, NotEqualOpConcept);
1.359 + BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<, LessThanOpConcept);
1.360 + BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<=, LessEqualOpConcept);
1.361 + BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>, GreaterThanOpConcept);
1.362 + BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>=, GreaterEqualOpConcept);
1.363 +
1.364 + BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(+, PlusOpConcept);
1.365 + BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(*, TimesOpConcept);
1.366 + BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(/, DivideOpConcept);
1.367 + BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(-, SubtractOpConcept);
1.368 + BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(%, ModOpConcept);
1.369 +
1.370 + //===========================================================================
1.371 + // Function Object Concepts
1.372 +
1.373 + template <class Func, class Return>
1.374 + struct GeneratorConcept
1.375 + {
1.376 + void constraints() {
1.377 + const Return& r = f(); // require operator() member function
1.378 + ignore_unused_variable_warning(r);
1.379 + }
1.380 + Func f;
1.381 + };
1.382 +
1.383 +
1.384 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.385 + template <class Func>
1.386 + struct GeneratorConcept<Func,void>
1.387 + {
1.388 + void constraints() {
1.389 + f(); // require operator() member function
1.390 + }
1.391 + Func f;
1.392 + };
1.393 +#endif
1.394 +
1.395 + template <class Func, class Return, class Arg>
1.396 + struct UnaryFunctionConcept
1.397 + {
1.398 + // required in case any of our template args are const-qualified:
1.399 + UnaryFunctionConcept();
1.400 +
1.401 + void constraints() {
1.402 + r = f(arg); // require operator()
1.403 + }
1.404 + Func f;
1.405 + Arg arg;
1.406 + Return r;
1.407 + };
1.408 +
1.409 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.410 + template <class Func, class Arg>
1.411 + struct UnaryFunctionConcept<Func, void, Arg> {
1.412 + void constraints() {
1.413 + f(arg); // require operator()
1.414 + }
1.415 + Func f;
1.416 + Arg arg;
1.417 + };
1.418 +#endif
1.419 +
1.420 + template <class Func, class Return, class First, class Second>
1.421 + struct BinaryFunctionConcept
1.422 + {
1.423 + void constraints() {
1.424 + r = f(first, second); // require operator()
1.425 + }
1.426 + Func f;
1.427 + First first;
1.428 + Second second;
1.429 + Return r;
1.430 + };
1.431 +
1.432 +#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.433 + template <class Func, class First, class Second>
1.434 + struct BinaryFunctionConcept<Func, void, First, Second>
1.435 + {
1.436 + void constraints() {
1.437 + f(first, second); // require operator()
1.438 + }
1.439 + Func f;
1.440 + First first;
1.441 + Second second;
1.442 + };
1.443 +#endif
1.444 +
1.445 + template <class Func, class Arg>
1.446 + struct UnaryPredicateConcept
1.447 + {
1.448 + void constraints() {
1.449 + require_boolean_expr(f(arg)); // require operator() returning bool
1.450 + }
1.451 + Func f;
1.452 + Arg arg;
1.453 + };
1.454 +
1.455 + template <class Func, class First, class Second>
1.456 + struct BinaryPredicateConcept
1.457 + {
1.458 + void constraints() {
1.459 + require_boolean_expr(f(a, b)); // require operator() returning bool
1.460 + }
1.461 + Func f;
1.462 + First a;
1.463 + Second b;
1.464 + };
1.465 +
1.466 + // use this when functor is used inside a container class like std::set
1.467 + template <class Func, class First, class Second>
1.468 + struct Const_BinaryPredicateConcept {
1.469 + void constraints() {
1.470 + const_constraints(f);
1.471 + }
1.472 + void const_constraints(const Func& fun) {
1.473 + function_requires<BinaryPredicateConcept<Func, First, Second> >();
1.474 + // operator() must be a const member function
1.475 + require_boolean_expr(fun(a, b));
1.476 + }
1.477 + Func f;
1.478 + First a;
1.479 + Second b;
1.480 + };
1.481 +
1.482 + template <class Func, class Return>
1.483 + struct AdaptableGeneratorConcept
1.484 + {
1.485 + void constraints() {
1.486 + typedef typename Func::result_type result_type;
1.487 + BOOST_STATIC_ASSERT((is_convertible<result_type, Return>::value));
1.488 + function_requires< GeneratorConcept<Func, result_type> >();
1.489 + }
1.490 + };
1.491 +
1.492 + template <class Func, class Return, class Arg>
1.493 + struct AdaptableUnaryFunctionConcept
1.494 + {
1.495 + void constraints() {
1.496 + typedef typename Func::argument_type argument_type;
1.497 + typedef typename Func::result_type result_type;
1.498 + BOOST_STATIC_ASSERT((is_convertible<result_type, Return>::value));
1.499 + BOOST_STATIC_ASSERT((is_convertible<Arg, argument_type>::value));
1.500 + function_requires< UnaryFunctionConcept<Func, result_type, argument_type> >();
1.501 + }
1.502 + };
1.503 +
1.504 + template <class Func, class Return, class First, class Second>
1.505 + struct AdaptableBinaryFunctionConcept
1.506 + {
1.507 + void constraints() {
1.508 + typedef typename Func::first_argument_type first_argument_type;
1.509 + typedef typename Func::second_argument_type second_argument_type;
1.510 + typedef typename Func::result_type result_type;
1.511 + BOOST_STATIC_ASSERT((is_convertible<result_type, Return>::value));
1.512 + BOOST_STATIC_ASSERT((is_convertible<First, first_argument_type>::value));
1.513 + BOOST_STATIC_ASSERT((is_convertible<Second, second_argument_type>::value));
1.514 + function_requires< BinaryFunctionConcept<Func, result_type,
1.515 + first_argument_type, second_argument_type> >();
1.516 + }
1.517 + };
1.518 +
1.519 + template <class Func, class Arg>
1.520 + struct AdaptablePredicateConcept
1.521 + {
1.522 + void constraints() {
1.523 + function_requires< UnaryPredicateConcept<Func, Arg> >();
1.524 + function_requires< AdaptableUnaryFunctionConcept<Func, bool, Arg> >();
1.525 + }
1.526 + };
1.527 +
1.528 + template <class Func, class First, class Second>
1.529 + struct AdaptableBinaryPredicateConcept
1.530 + {
1.531 + void constraints() {
1.532 + function_requires< BinaryPredicateConcept<Func, First, Second> >();
1.533 + function_requires< AdaptableBinaryFunctionConcept<Func, bool, First, Second> >();
1.534 + }
1.535 + };
1.536 +
1.537 + //===========================================================================
1.538 + // Iterator Concepts
1.539 +
1.540 + template <class TT>
1.541 + struct InputIteratorConcept
1.542 + {
1.543 + void constraints() {
1.544 + function_requires< AssignableConcept<TT> >();
1.545 + function_requires< EqualityComparableConcept<TT> >();
1.546 + TT j(i);
1.547 + (void)*i; // require dereference operator
1.548 +#ifndef BOOST_NO_STD_ITERATOR_TRAITS
1.549 + // require iterator_traits typedef's
1.550 + typedef typename std::iterator_traits<TT>::difference_type D;
1.551 + // Hmm, the following is a bit fragile
1.552 + //function_requires< SignedIntegerConcept<D> >();
1.553 + typedef typename std::iterator_traits<TT>::reference R;
1.554 + typedef typename std::iterator_traits<TT>::pointer P;
1.555 + typedef typename std::iterator_traits<TT>::iterator_category C;
1.556 + function_requires< ConvertibleConcept<C, std::input_iterator_tag> >();
1.557 +#endif
1.558 + ++j; // require preincrement operator
1.559 + i++; // require postincrement operator
1.560 + }
1.561 + TT i;
1.562 + };
1.563 +
1.564 + template <class TT, class ValueT>
1.565 + struct OutputIteratorConcept
1.566 + {
1.567 + void constraints() {
1.568 + function_requires< AssignableConcept<TT> >();
1.569 + ++i; // require preincrement operator
1.570 + i++; // require postincrement operator
1.571 + *i++ = t; // require postincrement and assignment
1.572 + }
1.573 + TT i, j;
1.574 + ValueT t;
1.575 + };
1.576 +
1.577 + template <class TT>
1.578 + struct ForwardIteratorConcept
1.579 + {
1.580 + void constraints() {
1.581 + function_requires< InputIteratorConcept<TT> >();
1.582 +#ifndef BOOST_NO_STD_ITERATOR_TRAITS
1.583 + typedef typename std::iterator_traits<TT>::iterator_category C;
1.584 + function_requires< ConvertibleConcept<C, std::forward_iterator_tag> >();
1.585 + typedef typename std::iterator_traits<TT>::reference reference;
1.586 + reference r = *i;
1.587 + ignore_unused_variable_warning(r);
1.588 +#endif
1.589 + }
1.590 + TT i;
1.591 + };
1.592 +
1.593 + template <class TT>
1.594 + struct Mutable_ForwardIteratorConcept
1.595 + {
1.596 + void constraints() {
1.597 + function_requires< ForwardIteratorConcept<TT> >();
1.598 + *i++ = *i; // require postincrement and assignment
1.599 + }
1.600 + TT i;
1.601 + };
1.602 +
1.603 + template <class TT>
1.604 + struct BidirectionalIteratorConcept
1.605 + {
1.606 + void constraints() {
1.607 + function_requires< ForwardIteratorConcept<TT> >();
1.608 +#ifndef BOOST_NO_STD_ITERATOR_TRAITS
1.609 + typedef typename std::iterator_traits<TT>::iterator_category C;
1.610 + function_requires< ConvertibleConcept<C,
1.611 + std::bidirectional_iterator_tag> >();
1.612 +#endif
1.613 + --i; // require predecrement operator
1.614 + i--; // require postdecrement operator
1.615 + }
1.616 + TT i;
1.617 + };
1.618 +
1.619 + template <class TT>
1.620 + struct Mutable_BidirectionalIteratorConcept
1.621 + {
1.622 + void constraints() {
1.623 + function_requires< BidirectionalIteratorConcept<TT> >();
1.624 + function_requires< Mutable_ForwardIteratorConcept<TT> >();
1.625 + *i-- = *i; // require postdecrement and assignment
1.626 + }
1.627 + TT i;
1.628 + };
1.629 +
1.630 +
1.631 + template <class TT>
1.632 + struct RandomAccessIteratorConcept
1.633 + {
1.634 + void constraints() {
1.635 + function_requires< BidirectionalIteratorConcept<TT> >();
1.636 + function_requires< ComparableConcept<TT> >();
1.637 +#ifndef BOOST_NO_STD_ITERATOR_TRAITS
1.638 + typedef typename std::iterator_traits<TT>::iterator_category C;
1.639 + function_requires< ConvertibleConcept< C,
1.640 + std::random_access_iterator_tag> >();
1.641 + typedef typename std::iterator_traits<TT>::reference R;
1.642 +#endif
1.643 +
1.644 + i += n; // require assignment addition operator
1.645 + i = i + n; i = n + i; // require addition with difference type
1.646 + i -= n; // require assignment subtraction operator
1.647 + i = i - n; // require subtraction with difference type
1.648 + n = i - j; // require difference operator
1.649 + (void)i[n]; // require element access operator
1.650 + }
1.651 + TT a, b;
1.652 + TT i, j;
1.653 +#ifndef BOOST_NO_STD_ITERATOR_TRAITS
1.654 + typename std::iterator_traits<TT>::difference_type n;
1.655 +#else
1.656 + std::ptrdiff_t n;
1.657 +#endif
1.658 + };
1.659 +
1.660 + template <class TT>
1.661 + struct Mutable_RandomAccessIteratorConcept
1.662 + {
1.663 + void constraints() {
1.664 + function_requires< RandomAccessIteratorConcept<TT> >();
1.665 + function_requires< Mutable_BidirectionalIteratorConcept<TT> >();
1.666 + i[n] = *i; // require element access and assignment
1.667 + }
1.668 + TT i;
1.669 +#ifndef BOOST_NO_STD_ITERATOR_TRAITS
1.670 + typename std::iterator_traits<TT>::difference_type n;
1.671 +#else
1.672 + std::ptrdiff_t n;
1.673 +#endif
1.674 + };
1.675 +
1.676 + //===========================================================================
1.677 + // Container Concepts
1.678 +
1.679 + template <class Container>
1.680 + struct ContainerConcept
1.681 + {
1.682 + typedef typename Container::value_type value_type;
1.683 + typedef typename Container::difference_type difference_type;
1.684 + typedef typename Container::size_type size_type;
1.685 + typedef typename Container::const_reference const_reference;
1.686 + typedef typename Container::const_pointer const_pointer;
1.687 + typedef typename Container::const_iterator const_iterator;
1.688 +
1.689 + void constraints() {
1.690 + function_requires< InputIteratorConcept<const_iterator> >();
1.691 + function_requires< AssignableConcept<Container> >();
1.692 + const_constraints(c);
1.693 + }
1.694 + void const_constraints(const Container& cc) {
1.695 + i = cc.begin();
1.696 + i = cc.end();
1.697 + n = cc.size();
1.698 + n = cc.max_size();
1.699 + b = cc.empty();
1.700 + }
1.701 + Container c;
1.702 + bool b;
1.703 + const_iterator i;
1.704 + size_type n;
1.705 + };
1.706 +
1.707 + template <class Container>
1.708 + struct Mutable_ContainerConcept
1.709 + {
1.710 + typedef typename Container::value_type value_type;
1.711 + typedef typename Container::reference reference;
1.712 + typedef typename Container::iterator iterator;
1.713 + typedef typename Container::pointer pointer;
1.714 +
1.715 + void constraints() {
1.716 + function_requires< ContainerConcept<Container> >();
1.717 + function_requires< AssignableConcept<value_type> >();
1.718 + function_requires< InputIteratorConcept<iterator> >();
1.719 +
1.720 + i = c.begin();
1.721 + i = c.end();
1.722 + c.swap(c2);
1.723 + }
1.724 + iterator i;
1.725 + Container c, c2;
1.726 + };
1.727 +
1.728 + template <class ForwardContainer>
1.729 + struct ForwardContainerConcept
1.730 + {
1.731 + void constraints() {
1.732 + function_requires< ContainerConcept<ForwardContainer> >();
1.733 + typedef typename ForwardContainer::const_iterator const_iterator;
1.734 + function_requires< ForwardIteratorConcept<const_iterator> >();
1.735 + }
1.736 + };
1.737 +
1.738 + template <class ForwardContainer>
1.739 + struct Mutable_ForwardContainerConcept
1.740 + {
1.741 + void constraints() {
1.742 + function_requires< ForwardContainerConcept<ForwardContainer> >();
1.743 + function_requires< Mutable_ContainerConcept<ForwardContainer> >();
1.744 + typedef typename ForwardContainer::iterator iterator;
1.745 + function_requires< Mutable_ForwardIteratorConcept<iterator> >();
1.746 + }
1.747 + };
1.748 +
1.749 + template <class ReversibleContainer>
1.750 + struct ReversibleContainerConcept
1.751 + {
1.752 + typedef typename ReversibleContainer::const_iterator const_iterator;
1.753 + typedef typename ReversibleContainer::const_reverse_iterator
1.754 + const_reverse_iterator;
1.755 +
1.756 + void constraints() {
1.757 + function_requires< ForwardContainerConcept<ReversibleContainer> >();
1.758 + function_requires< BidirectionalIteratorConcept<const_iterator> >();
1.759 + function_requires<
1.760 + BidirectionalIteratorConcept<const_reverse_iterator> >();
1.761 + const_constraints(c);
1.762 + }
1.763 + void const_constraints(const ReversibleContainer& cc) {
1.764 + const_reverse_iterator i = cc.rbegin();
1.765 + i = cc.rend();
1.766 + }
1.767 + ReversibleContainer c;
1.768 + };
1.769 +
1.770 + template <class ReversibleContainer>
1.771 + struct Mutable_ReversibleContainerConcept
1.772 + {
1.773 + typedef typename ReversibleContainer::iterator iterator;
1.774 + typedef typename ReversibleContainer::reverse_iterator reverse_iterator;
1.775 +
1.776 + void constraints() {
1.777 + function_requires< ReversibleContainerConcept<ReversibleContainer> >();
1.778 + function_requires<
1.779 + Mutable_ForwardContainerConcept<ReversibleContainer> >();
1.780 + function_requires< Mutable_BidirectionalIteratorConcept<iterator> >();
1.781 + function_requires<
1.782 + Mutable_BidirectionalIteratorConcept<reverse_iterator> >();
1.783 +
1.784 + reverse_iterator i = c.rbegin();
1.785 + i = c.rend();
1.786 + }
1.787 + ReversibleContainer c;
1.788 + };
1.789 +
1.790 + template <class RandomAccessContainer>
1.791 + struct RandomAccessContainerConcept
1.792 + {
1.793 + typedef typename RandomAccessContainer::size_type size_type;
1.794 + typedef typename RandomAccessContainer::const_reference const_reference;
1.795 + typedef typename RandomAccessContainer::const_iterator const_iterator;
1.796 + typedef typename RandomAccessContainer::const_reverse_iterator
1.797 + const_reverse_iterator;
1.798 +
1.799 + void constraints() {
1.800 + function_requires< ReversibleContainerConcept<RandomAccessContainer> >();
1.801 + function_requires< RandomAccessIteratorConcept<const_iterator> >();
1.802 + function_requires<
1.803 + RandomAccessIteratorConcept<const_reverse_iterator> >();
1.804 +
1.805 + const_constraints(c);
1.806 + }
1.807 + void const_constraints(const RandomAccessContainer& cc) {
1.808 + const_reference r = cc[n];
1.809 + ignore_unused_variable_warning(r);
1.810 + }
1.811 + RandomAccessContainer c;
1.812 + size_type n;
1.813 + };
1.814 +
1.815 + template <class RandomAccessContainer>
1.816 + struct Mutable_RandomAccessContainerConcept
1.817 + {
1.818 + typedef typename RandomAccessContainer::size_type size_type;
1.819 + typedef typename RandomAccessContainer::reference reference;
1.820 + typedef typename RandomAccessContainer::iterator iterator;
1.821 + typedef typename RandomAccessContainer::reverse_iterator reverse_iterator;
1.822 +
1.823 + void constraints() {
1.824 + function_requires<
1.825 + RandomAccessContainerConcept<RandomAccessContainer> >();
1.826 + function_requires<
1.827 + Mutable_ReversibleContainerConcept<RandomAccessContainer> >();
1.828 + function_requires< Mutable_RandomAccessIteratorConcept<iterator> >();
1.829 + function_requires<
1.830 + Mutable_RandomAccessIteratorConcept<reverse_iterator> >();
1.831 +
1.832 + reference r = c[i];
1.833 + ignore_unused_variable_warning(r);
1.834 + }
1.835 + size_type i;
1.836 + RandomAccessContainer c;
1.837 + };
1.838 +
1.839 + // A Sequence is inherently mutable
1.840 + template <class Sequence>
1.841 + struct SequenceConcept
1.842 + {
1.843 +
1.844 + typedef typename Sequence::reference reference;
1.845 + typedef typename Sequence::const_reference const_reference;
1.846 +
1.847 + void constraints() {
1.848 + // Matt Austern's book puts DefaultConstructible here, the C++
1.849 + // standard places it in Container
1.850 + // function_requires< DefaultConstructible<Sequence> >();
1.851 + function_requires< Mutable_ForwardContainerConcept<Sequence> >();
1.852 + function_requires< DefaultConstructibleConcept<Sequence> >();
1.853 +
1.854 + Sequence
1.855 + c(n),
1.856 + c2(n, t),
1.857 + c3(first, last);
1.858 +
1.859 + c.insert(p, t);
1.860 + c.insert(p, n, t);
1.861 + c.insert(p, first, last);
1.862 +
1.863 + c.erase(p);
1.864 + c.erase(p, q);
1.865 +
1.866 + reference r = c.front();
1.867 +
1.868 + ignore_unused_variable_warning(c);
1.869 + ignore_unused_variable_warning(c2);
1.870 + ignore_unused_variable_warning(c3);
1.871 + ignore_unused_variable_warning(r);
1.872 + const_constraints(c);
1.873 + }
1.874 + void const_constraints(const Sequence& c) {
1.875 + const_reference r = c.front();
1.876 + ignore_unused_variable_warning(r);
1.877 + }
1.878 + typename Sequence::value_type t;
1.879 + typename Sequence::size_type n;
1.880 + typename Sequence::value_type* first, *last;
1.881 + typename Sequence::iterator p, q;
1.882 + };
1.883 +
1.884 + template <class FrontInsertionSequence>
1.885 + struct FrontInsertionSequenceConcept
1.886 + {
1.887 + void constraints() {
1.888 + function_requires< SequenceConcept<FrontInsertionSequence> >();
1.889 +
1.890 + c.push_front(t);
1.891 + c.pop_front();
1.892 + }
1.893 + FrontInsertionSequence c;
1.894 + typename FrontInsertionSequence::value_type t;
1.895 + };
1.896 +
1.897 + template <class BackInsertionSequence>
1.898 + struct BackInsertionSequenceConcept
1.899 + {
1.900 + typedef typename BackInsertionSequence::reference reference;
1.901 + typedef typename BackInsertionSequence::const_reference const_reference;
1.902 +
1.903 + void constraints() {
1.904 + function_requires< SequenceConcept<BackInsertionSequence> >();
1.905 +
1.906 + c.push_back(t);
1.907 + c.pop_back();
1.908 + reference r = c.back();
1.909 + ignore_unused_variable_warning(r);
1.910 + }
1.911 + void const_constraints(const BackInsertionSequence& cc) {
1.912 + const_reference r = cc.back();
1.913 + ignore_unused_variable_warning(r);
1.914 + };
1.915 + BackInsertionSequence c;
1.916 + typename BackInsertionSequence::value_type t;
1.917 + };
1.918 +
1.919 + template <class AssociativeContainer>
1.920 + struct AssociativeContainerConcept
1.921 + {
1.922 + void constraints() {
1.923 + function_requires< ForwardContainerConcept<AssociativeContainer> >();
1.924 + function_requires< DefaultConstructibleConcept<AssociativeContainer> >();
1.925 +
1.926 + i = c.find(k);
1.927 + r = c.equal_range(k);
1.928 + c.erase(k);
1.929 + c.erase(i);
1.930 + c.erase(r.first, r.second);
1.931 + const_constraints(c);
1.932 + }
1.933 + void const_constraints(const AssociativeContainer& cc) {
1.934 + ci = cc.find(k);
1.935 + n = cc.count(k);
1.936 + cr = cc.equal_range(k);
1.937 + }
1.938 + typedef typename AssociativeContainer::iterator iterator;
1.939 + typedef typename AssociativeContainer::const_iterator const_iterator;
1.940 +
1.941 + AssociativeContainer c;
1.942 + iterator i;
1.943 + std::pair<iterator,iterator> r;
1.944 + const_iterator ci;
1.945 + std::pair<const_iterator,const_iterator> cr;
1.946 + typename AssociativeContainer::key_type k;
1.947 + typename AssociativeContainer::size_type n;
1.948 + };
1.949 +
1.950 + template <class UniqueAssociativeContainer>
1.951 + struct UniqueAssociativeContainerConcept
1.952 + {
1.953 + void constraints() {
1.954 + function_requires< AssociativeContainerConcept<UniqueAssociativeContainer> >();
1.955 +
1.956 + UniqueAssociativeContainer c(first, last);
1.957 +
1.958 + pos_flag = c.insert(t);
1.959 + c.insert(first, last);
1.960 +
1.961 + ignore_unused_variable_warning(c);
1.962 + }
1.963 + std::pair<typename UniqueAssociativeContainer::iterator, bool> pos_flag;
1.964 + typename UniqueAssociativeContainer::value_type t;
1.965 + typename UniqueAssociativeContainer::value_type* first, *last;
1.966 + };
1.967 +
1.968 + template <class MultipleAssociativeContainer>
1.969 + struct MultipleAssociativeContainerConcept
1.970 + {
1.971 + void constraints() {
1.972 + function_requires< AssociativeContainerConcept<MultipleAssociativeContainer> >();
1.973 +
1.974 + MultipleAssociativeContainer c(first, last);
1.975 +
1.976 + pos = c.insert(t);
1.977 + c.insert(first, last);
1.978 +
1.979 + ignore_unused_variable_warning(c);
1.980 + ignore_unused_variable_warning(pos);
1.981 + }
1.982 + typename MultipleAssociativeContainer::iterator pos;
1.983 + typename MultipleAssociativeContainer::value_type t;
1.984 + typename MultipleAssociativeContainer::value_type* first, *last;
1.985 + };
1.986 +
1.987 + template <class SimpleAssociativeContainer>
1.988 + struct SimpleAssociativeContainerConcept
1.989 + {
1.990 + void constraints() {
1.991 + function_requires< AssociativeContainerConcept<SimpleAssociativeContainer> >();
1.992 + typedef typename SimpleAssociativeContainer::key_type key_type;
1.993 + typedef typename SimpleAssociativeContainer::value_type value_type;
1.994 + typedef typename require_same<key_type, value_type>::type req;
1.995 + }
1.996 + };
1.997 +
1.998 + template <class SimpleAssociativeContainer>
1.999 + struct PairAssociativeContainerConcept
1.1000 + {
1.1001 + void constraints() {
1.1002 + function_requires< AssociativeContainerConcept<SimpleAssociativeContainer> >();
1.1003 + typedef typename SimpleAssociativeContainer::key_type key_type;
1.1004 + typedef typename SimpleAssociativeContainer::value_type value_type;
1.1005 + typedef typename SimpleAssociativeContainer::mapped_type mapped_type;
1.1006 + typedef std::pair<const key_type, mapped_type> required_value_type;
1.1007 + typedef typename require_same<value_type, required_value_type>::type req;
1.1008 + }
1.1009 + };
1.1010 +
1.1011 + template <class SortedAssociativeContainer>
1.1012 + struct SortedAssociativeContainerConcept
1.1013 + {
1.1014 + void constraints() {
1.1015 + function_requires< AssociativeContainerConcept<SortedAssociativeContainer> >();
1.1016 + function_requires< ReversibleContainerConcept<SortedAssociativeContainer> >();
1.1017 +
1.1018 + SortedAssociativeContainer
1.1019 + c(kc),
1.1020 + c2(first, last),
1.1021 + c3(first, last, kc);
1.1022 +
1.1023 + p = c.upper_bound(k);
1.1024 + p = c.lower_bound(k);
1.1025 + r = c.equal_range(k);
1.1026 +
1.1027 + c.insert(p, t);
1.1028 +
1.1029 + ignore_unused_variable_warning(c);
1.1030 + ignore_unused_variable_warning(c2);
1.1031 + ignore_unused_variable_warning(c3);
1.1032 + }
1.1033 + void const_constraints(const SortedAssociativeContainer& c) {
1.1034 + kc = c.key_comp();
1.1035 + vc = c.value_comp();
1.1036 +
1.1037 + cp = c.upper_bound(k);
1.1038 + cp = c.lower_bound(k);
1.1039 + cr = c.equal_range(k);
1.1040 + }
1.1041 + typename SortedAssociativeContainer::key_compare kc;
1.1042 + typename SortedAssociativeContainer::value_compare vc;
1.1043 + typename SortedAssociativeContainer::value_type t;
1.1044 + typename SortedAssociativeContainer::key_type k;
1.1045 + typedef typename SortedAssociativeContainer::iterator iterator;
1.1046 + typedef typename SortedAssociativeContainer::const_iterator const_iterator;
1.1047 + iterator p;
1.1048 + const_iterator cp;
1.1049 + std::pair<iterator,iterator> r;
1.1050 + std::pair<const_iterator,const_iterator> cr;
1.1051 + typename SortedAssociativeContainer::value_type* first, *last;
1.1052 + };
1.1053 +
1.1054 + // HashedAssociativeContainer
1.1055 +
1.1056 +} // namespace boost
1.1057 +
1.1058 +#endif // BOOST_CONCEPT_CHECKS_HPP
1.1059 +