blob: ca434f3437a7b83f971ff40021c627a9c3ae8911 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001//
2// (C) Copyright Jeremy Siek 2000.
3// Copyright 2002 The Trustees of Indiana University.
4//
5// Distributed under the Boost Software License, Version 1.0. (See
6// accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// Revision History:
10// 05 May 2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek)
11// 02 April 2001: Removed limits header altogether. (Jeremy Siek)
12// 01 April 2001: Modified to use new <ndnboost/limits.hpp> header. (JMaddock)
13//
14
15// See http://www.boost.org/libs/concept_check for documentation.
16
Jeff Thompson3d613fd2013-10-15 15:39:04 -070017#ifndef NDNBOOST_CONCEPT_CHECKS_HPP
18# define NDNBOOST_CONCEPT_CHECKS_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070019
20# include <ndnboost/concept/assert.hpp>
21
22# include <ndnboost/iterator.hpp>
23# include <ndnboost/type_traits/conversion_traits.hpp>
24# include <utility>
25# include <ndnboost/type_traits/is_same.hpp>
26# include <ndnboost/type_traits/is_void.hpp>
27# include <ndnboost/mpl/assert.hpp>
28# include <ndnboost/mpl/bool.hpp>
29# include <ndnboost/detail/workaround.hpp>
30# include <ndnboost/detail/iterator.hpp>
31
32# include <ndnboost/concept/usage.hpp>
33# include <ndnboost/concept/detail/concept_def.hpp>
34
35namespace ndnboost
36{
37
38 //
39 // Backward compatibility
40 //
41
42 template <class Model>
43 inline void function_requires(Model* = 0)
44 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045 NDNBOOST_CONCEPT_ASSERT((Model));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070046 }
47 template <class T> inline void ignore_unused_variable_warning(T const&) {}
48
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049# define NDNBOOST_CLASS_REQUIRE(type_var, ns, concept) \
50 NDNBOOST_CONCEPT_ASSERT((ns::concept<type_var>))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070051
Jeff Thompson3d613fd2013-10-15 15:39:04 -070052# define NDNBOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \
53 NDNBOOST_CONCEPT_ASSERT((ns::concept<type_var1,type_var2>))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070054
Jeff Thompson3d613fd2013-10-15 15:39:04 -070055# define NDNBOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \
56 NDNBOOST_CONCEPT_ASSERT((ns::concept<tv1,tv2,tv3>))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070057
Jeff Thompson3d613fd2013-10-15 15:39:04 -070058# define NDNBOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
59 NDNBOOST_CONCEPT_ASSERT((ns::concept<tv1,tv2,tv3,tv4>))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070060
61
62 //
63 // Begin concept definitions
64 //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070065 NDNBOOST_concept(Integer, (T))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070066 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070067 NDNBOOST_CONCEPT_USAGE(Integer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070068 {
69 x.error_type_must_be_an_integer_type();
70 }
71 private:
72 T x;
73 };
74
75 template <> struct Integer<char> {};
76 template <> struct Integer<signed char> {};
77 template <> struct Integer<unsigned char> {};
78 template <> struct Integer<short> {};
79 template <> struct Integer<unsigned short> {};
80 template <> struct Integer<int> {};
81 template <> struct Integer<unsigned int> {};
82 template <> struct Integer<long> {};
83 template <> struct Integer<unsigned long> {};
Jeff Thompson3d613fd2013-10-15 15:39:04 -070084# if defined(NDNBOOST_HAS_LONG_LONG)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070085 template <> struct Integer< ::ndnboost::long_long_type> {};
86 template <> struct Integer< ::ndnboost::ulong_long_type> {};
Jeff Thompson3d613fd2013-10-15 15:39:04 -070087# elif defined(NDNBOOST_HAS_MS_INT64)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070088 template <> struct Integer<__int64> {};
89 template <> struct Integer<unsigned __int64> {};
90# endif
91
Jeff Thompson3d613fd2013-10-15 15:39:04 -070092 NDNBOOST_concept(SignedInteger,(T)) {
93 NDNBOOST_CONCEPT_USAGE(SignedInteger) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070094 x.error_type_must_be_a_signed_integer_type();
95 }
96 private:
97 T x;
98 };
99 template <> struct SignedInteger<signed char> { };
100 template <> struct SignedInteger<short> {};
101 template <> struct SignedInteger<int> {};
102 template <> struct SignedInteger<long> {};
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700103# if defined(NDNBOOST_HAS_LONG_LONG)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700104 template <> struct SignedInteger< ::ndnboost::long_long_type> {};
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105# elif defined(NDNBOOST_HAS_MS_INT64)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700106 template <> struct SignedInteger<__int64> {};
107# endif
108
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700109 NDNBOOST_concept(UnsignedInteger,(T)) {
110 NDNBOOST_CONCEPT_USAGE(UnsignedInteger) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700111 x.error_type_must_be_an_unsigned_integer_type();
112 }
113 private:
114 T x;
115 };
116
117 template <> struct UnsignedInteger<unsigned char> {};
118 template <> struct UnsignedInteger<unsigned short> {};
119 template <> struct UnsignedInteger<unsigned int> {};
120 template <> struct UnsignedInteger<unsigned long> {};
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700121# if defined(NDNBOOST_HAS_LONG_LONG)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700122 template <> struct UnsignedInteger< ::ndnboost::ulong_long_type> {};
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700123# elif defined(NDNBOOST_HAS_MS_INT64)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700124 template <> struct UnsignedInteger<unsigned __int64> {};
125# endif
126
127 //===========================================================================
128 // Basic Concepts
129
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700130 NDNBOOST_concept(DefaultConstructible,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700131 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700132 NDNBOOST_CONCEPT_USAGE(DefaultConstructible) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700133 TT a; // require default constructor
134 ignore_unused_variable_warning(a);
135 }
136 };
137
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700138 NDNBOOST_concept(Assignable,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700139 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700140 NDNBOOST_CONCEPT_USAGE(Assignable) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700141#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
142 a = b; // require assignment operator
143#endif
144 const_constraints(b);
145 }
146 private:
147 void const_constraints(const TT& x) {
148#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
149 a = x; // const required for argument to assignment
150#else
151 ignore_unused_variable_warning(x);
152#endif
153 }
154 private:
155 TT a;
156 TT b;
157 };
158
159
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700160 NDNBOOST_concept(CopyConstructible,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700161 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700162 NDNBOOST_CONCEPT_USAGE(CopyConstructible) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700163 TT a(b); // require copy constructor
164 TT* ptr = &a; // require address of operator
165 const_constraints(a);
166 ignore_unused_variable_warning(ptr);
167 }
168 private:
169 void const_constraints(const TT& a) {
170 TT c(a); // require const copy constructor
171 const TT* ptr = &a; // require const address of operator
172 ignore_unused_variable_warning(c);
173 ignore_unused_variable_warning(ptr);
174 }
175 TT b;
176 };
177
178#if (defined _MSC_VER)
179# pragma warning( push )
180# pragma warning( disable : 4510 ) // default constructor could not be generated
181# pragma warning( disable : 4610 ) // object 'class' can never be instantiated - user-defined constructor required
182#endif
183 // The SGI STL version of Assignable requires copy constructor and operator=
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700184 NDNBOOST_concept(SGIAssignable,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700185 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700186 NDNBOOST_CONCEPT_USAGE(SGIAssignable) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700187 TT c(a);
188#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
189 a = b; // require assignment operator
190#endif
191 const_constraints(b);
192 ignore_unused_variable_warning(c);
193 }
194 private:
195 void const_constraints(const TT& x) {
196 TT c(x);
197#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
198 a = x; // const required for argument to assignment
199#endif
200 ignore_unused_variable_warning(c);
201 }
202 TT a;
203 TT b;
204 };
205#if (defined _MSC_VER)
206# pragma warning( pop )
207#endif
208
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700209 NDNBOOST_concept(Convertible,(X)(Y))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700210 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700211 NDNBOOST_CONCEPT_USAGE(Convertible) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700212 Y y = x;
213 ignore_unused_variable_warning(y);
214 }
215 private:
216 X x;
217 };
218
219 // The C++ standard requirements for many concepts talk about return
220 // types that must be "convertible to bool". The problem with this
221 // requirement is that it leaves the door open for evil proxies that
222 // define things like operator|| with strange return types. Two
223 // possible solutions are:
224 // 1) require the return type to be exactly bool
225 // 2) stay with convertible to bool, and also
226 // specify stuff about all the logical operators.
227 // For now we just test for convertible to bool.
228 template <class TT>
229 void require_boolean_expr(const TT& t) {
230 bool x = t;
231 ignore_unused_variable_warning(x);
232 }
233
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700234 NDNBOOST_concept(EqualityComparable,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700235 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700236 NDNBOOST_CONCEPT_USAGE(EqualityComparable) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700237 require_boolean_expr(a == b);
238 require_boolean_expr(a != b);
239 }
240 private:
241 TT a, b;
242 };
243
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700244 NDNBOOST_concept(LessThanComparable,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700245 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700246 NDNBOOST_CONCEPT_USAGE(LessThanComparable) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700247 require_boolean_expr(a < b);
248 }
249 private:
250 TT a, b;
251 };
252
253 // This is equivalent to SGI STL's LessThanComparable.
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700254 NDNBOOST_concept(Comparable,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700255 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700256 NDNBOOST_CONCEPT_USAGE(Comparable) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700257 require_boolean_expr(a < b);
258 require_boolean_expr(a > b);
259 require_boolean_expr(a <= b);
260 require_boolean_expr(a >= b);
261 }
262 private:
263 TT a, b;
264 };
265
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700266#define NDNBOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(OP,NAME) \
267 NDNBOOST_concept(NAME, (First)(Second)) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700268 { \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700269 NDNBOOST_CONCEPT_USAGE(NAME) { (void)constraints_(); } \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700270 private: \
271 bool constraints_() { return a OP b; } \
272 First a; \
273 Second b; \
274 }
275
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700276#define NDNBOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(OP,NAME) \
277 NDNBOOST_concept(NAME, (Ret)(First)(Second)) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700278 { \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700279 NDNBOOST_CONCEPT_USAGE(NAME) { (void)constraints_(); } \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700280 private: \
281 Ret constraints_() { return a OP b; } \
282 First a; \
283 Second b; \
284 }
285
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700286 NDNBOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, EqualOp);
287 NDNBOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(!=, NotEqualOp);
288 NDNBOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<, LessThanOp);
289 NDNBOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<=, LessEqualOp);
290 NDNBOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>, GreaterThanOp);
291 NDNBOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>=, GreaterEqualOp);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700292
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700293 NDNBOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(+, PlusOp);
294 NDNBOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(*, TimesOp);
295 NDNBOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(/, DivideOp);
296 NDNBOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(-, SubtractOp);
297 NDNBOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(%, ModOp);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700298
299 //===========================================================================
300 // Function Object Concepts
301
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700302 NDNBOOST_concept(Generator,(Func)(Return))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700303 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700304 NDNBOOST_CONCEPT_USAGE(Generator) { test(is_void<Return>()); }
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700305
306 private:
307 void test(ndnboost::mpl::false_)
308 {
309 // Do we really want a reference here?
310 const Return& r = f();
311 ignore_unused_variable_warning(r);
312 }
313
314 void test(ndnboost::mpl::true_)
315 {
316 f();
317 }
318
319 Func f;
320 };
321
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700322 NDNBOOST_concept(UnaryFunction,(Func)(Return)(Arg))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700323 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700324 NDNBOOST_CONCEPT_USAGE(UnaryFunction) { test(is_void<Return>()); }
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700325
326 private:
327 void test(ndnboost::mpl::false_)
328 {
329 f(arg); // "priming the pump" this way keeps msvc6 happy (ICE)
330 Return r = f(arg);
331 ignore_unused_variable_warning(r);
332 }
333
334 void test(ndnboost::mpl::true_)
335 {
336 f(arg);
337 }
338
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700339#if (NDNBOOST_WORKAROUND(__GNUC__, NDNBOOST_TESTED_AT(4) \
340 && NDNBOOST_WORKAROUND(__GNUC__, > 3)))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700341 // Declare a dummy construktor to make gcc happy.
342 // It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
343 // (warning: non-static reference "const double& ndnboost::UnaryFunction<YourClassHere>::arg"
344 // in class without a constructor [-Wuninitialized])
345 UnaryFunction();
346#endif
347
348 Func f;
349 Arg arg;
350 };
351
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700352 NDNBOOST_concept(BinaryFunction,(Func)(Return)(First)(Second))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700353 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700354 NDNBOOST_CONCEPT_USAGE(BinaryFunction) { test(is_void<Return>()); }
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700355 private:
356 void test(ndnboost::mpl::false_)
357 {
358 f(first,second);
359 Return r = f(first, second); // require operator()
360 (void)r;
361 }
362
363 void test(ndnboost::mpl::true_)
364 {
365 f(first,second);
366 }
367
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700368#if (NDNBOOST_WORKAROUND(__GNUC__, NDNBOOST_TESTED_AT(4) \
369 && NDNBOOST_WORKAROUND(__GNUC__, > 3)))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700370 // Declare a dummy constructor to make gcc happy.
371 // It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
372 // (warning: non-static reference "const double& ndnboost::BinaryFunction<YourClassHere>::arg"
373 // in class without a constructor [-Wuninitialized])
374 BinaryFunction();
375#endif
376
377 Func f;
378 First first;
379 Second second;
380 };
381
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700382 NDNBOOST_concept(UnaryPredicate,(Func)(Arg))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700383 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700384 NDNBOOST_CONCEPT_USAGE(UnaryPredicate) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700385 require_boolean_expr(f(arg)); // require operator() returning bool
386 }
387 private:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700388#if (NDNBOOST_WORKAROUND(__GNUC__, NDNBOOST_TESTED_AT(4) \
389 && NDNBOOST_WORKAROUND(__GNUC__, > 3)))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700390 // Declare a dummy constructor to make gcc happy.
391 // It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
392 // (warning: non-static reference "const double& ndnboost::UnaryPredicate<YourClassHere>::arg"
393 // in class without a constructor [-Wuninitialized])
394 UnaryPredicate();
395#endif
396
397 Func f;
398 Arg arg;
399 };
400
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700401 NDNBOOST_concept(BinaryPredicate,(Func)(First)(Second))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700402 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700403 NDNBOOST_CONCEPT_USAGE(BinaryPredicate) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700404 require_boolean_expr(f(a, b)); // require operator() returning bool
405 }
406 private:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700407#if (NDNBOOST_WORKAROUND(__GNUC__, NDNBOOST_TESTED_AT(4) \
408 && NDNBOOST_WORKAROUND(__GNUC__, > 3)))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700409 // Declare a dummy constructor to make gcc happy.
410 // It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
411 // (warning: non-static reference "const double& ndnboost::BinaryPredicate<YourClassHere>::arg"
412 // in class without a constructor [-Wuninitialized])
413 BinaryPredicate();
414#endif
415 Func f;
416 First a;
417 Second b;
418 };
419
420 // use this when functor is used inside a container class like std::set
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700421 NDNBOOST_concept(Const_BinaryPredicate,(Func)(First)(Second))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700422 : BinaryPredicate<Func, First, Second>
423 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700424 NDNBOOST_CONCEPT_USAGE(Const_BinaryPredicate) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700425 const_constraints(f);
426 }
427 private:
428 void const_constraints(const Func& fun) {
429 // operator() must be a const member function
430 require_boolean_expr(fun(a, b));
431 }
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700432#if (NDNBOOST_WORKAROUND(__GNUC__, NDNBOOST_TESTED_AT(4) \
433 && NDNBOOST_WORKAROUND(__GNUC__, > 3)))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700434 // Declare a dummy constructor to make gcc happy.
435 // It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
436 // (warning: non-static reference "const double& ndnboost::Const_BinaryPredicate<YourClassHere>::arg"
437 // in class without a constructor [-Wuninitialized])
438 Const_BinaryPredicate();
439#endif
440
441 Func f;
442 First a;
443 Second b;
444 };
445
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700446 NDNBOOST_concept(AdaptableGenerator,(Func)(Return))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700447 : Generator<Func, typename Func::result_type>
448 {
449 typedef typename Func::result_type result_type;
450
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700451 NDNBOOST_CONCEPT_USAGE(AdaptableGenerator)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700452 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700453 NDNBOOST_CONCEPT_ASSERT((Convertible<result_type, Return>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700454 }
455 };
456
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700457 NDNBOOST_concept(AdaptableUnaryFunction,(Func)(Return)(Arg))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700458 : UnaryFunction<Func, typename Func::result_type, typename Func::argument_type>
459 {
460 typedef typename Func::argument_type argument_type;
461 typedef typename Func::result_type result_type;
462
463 ~AdaptableUnaryFunction()
464 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700465 NDNBOOST_CONCEPT_ASSERT((Convertible<result_type, Return>));
466 NDNBOOST_CONCEPT_ASSERT((Convertible<Arg, argument_type>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700467 }
468 };
469
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700470 NDNBOOST_concept(AdaptableBinaryFunction,(Func)(Return)(First)(Second))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700471 : BinaryFunction<
472 Func
473 , typename Func::result_type
474 , typename Func::first_argument_type
475 , typename Func::second_argument_type
476 >
477 {
478 typedef typename Func::first_argument_type first_argument_type;
479 typedef typename Func::second_argument_type second_argument_type;
480 typedef typename Func::result_type result_type;
481
482 ~AdaptableBinaryFunction()
483 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700484 NDNBOOST_CONCEPT_ASSERT((Convertible<result_type, Return>));
485 NDNBOOST_CONCEPT_ASSERT((Convertible<First, first_argument_type>));
486 NDNBOOST_CONCEPT_ASSERT((Convertible<Second, second_argument_type>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700487 }
488 };
489
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700490 NDNBOOST_concept(AdaptablePredicate,(Func)(Arg))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700491 : UnaryPredicate<Func, Arg>
492 , AdaptableUnaryFunction<Func, bool, Arg>
493 {
494 };
495
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700496 NDNBOOST_concept(AdaptableBinaryPredicate,(Func)(First)(Second))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700497 : BinaryPredicate<Func, First, Second>
498 , AdaptableBinaryFunction<Func, bool, First, Second>
499 {
500 };
501
502 //===========================================================================
503 // Iterator Concepts
504
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700505 NDNBOOST_concept(InputIterator,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700506 : Assignable<TT>
507 , EqualityComparable<TT>
508 {
509 typedef typename ndnboost::detail::iterator_traits<TT>::value_type value_type;
510 typedef typename ndnboost::detail::iterator_traits<TT>::difference_type difference_type;
511 typedef typename ndnboost::detail::iterator_traits<TT>::reference reference;
512 typedef typename ndnboost::detail::iterator_traits<TT>::pointer pointer;
513 typedef typename ndnboost::detail::iterator_traits<TT>::iterator_category iterator_category;
514
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700515 NDNBOOST_CONCEPT_USAGE(InputIterator)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700516 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700517 NDNBOOST_CONCEPT_ASSERT((SignedInteger<difference_type>));
518 NDNBOOST_CONCEPT_ASSERT((Convertible<iterator_category, std::input_iterator_tag>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700519
520 TT j(i);
521 (void)*i; // require dereference operator
522 ++j; // require preincrement operator
523 i++; // require postincrement operator
524 }
525 private:
526 TT i;
527 };
528
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700529 NDNBOOST_concept(OutputIterator,(TT)(ValueT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700530 : Assignable<TT>
531 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700532 NDNBOOST_CONCEPT_USAGE(OutputIterator) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700533
534 ++i; // require preincrement operator
535 i++; // require postincrement operator
536 *i++ = t; // require postincrement and assignment
537 }
538 private:
539 TT i, j;
540 ValueT t;
541 };
542
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700543 NDNBOOST_concept(ForwardIterator,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700544 : InputIterator<TT>
545 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700546 NDNBOOST_CONCEPT_USAGE(ForwardIterator)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700547 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700548 NDNBOOST_CONCEPT_ASSERT((Convertible<
549 NDNBOOST_DEDUCED_TYPENAME ForwardIterator::iterator_category
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700550 , std::forward_iterator_tag
551 >));
552
553 typename InputIterator<TT>::reference r = *i;
554 ignore_unused_variable_warning(r);
555 }
556
557 private:
558 TT i;
559 };
560
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700561 NDNBOOST_concept(Mutable_ForwardIterator,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700562 : ForwardIterator<TT>
563 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700564 NDNBOOST_CONCEPT_USAGE(Mutable_ForwardIterator) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700565 *i++ = *i; // require postincrement and assignment
566 }
567 private:
568 TT i;
569 };
570
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700571 NDNBOOST_concept(BidirectionalIterator,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700572 : ForwardIterator<TT>
573 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700574 NDNBOOST_CONCEPT_USAGE(BidirectionalIterator)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700575 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700576 NDNBOOST_CONCEPT_ASSERT((Convertible<
577 NDNBOOST_DEDUCED_TYPENAME BidirectionalIterator::iterator_category
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700578 , std::bidirectional_iterator_tag
579 >));
580
581 --i; // require predecrement operator
582 i--; // require postdecrement operator
583 }
584 private:
585 TT i;
586 };
587
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700588 NDNBOOST_concept(Mutable_BidirectionalIterator,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700589 : BidirectionalIterator<TT>
590 , Mutable_ForwardIterator<TT>
591 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700592 NDNBOOST_CONCEPT_USAGE(Mutable_BidirectionalIterator)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700593 {
594 *i-- = *i; // require postdecrement and assignment
595 }
596 private:
597 TT i;
598 };
599
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700600 NDNBOOST_concept(RandomAccessIterator,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700601 : BidirectionalIterator<TT>
602 , Comparable<TT>
603 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700604 NDNBOOST_CONCEPT_USAGE(RandomAccessIterator)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700605 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700606 NDNBOOST_CONCEPT_ASSERT((Convertible<
607 NDNBOOST_DEDUCED_TYPENAME BidirectionalIterator<TT>::iterator_category
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700608 , std::random_access_iterator_tag
609 >));
610
611 i += n; // require assignment addition operator
612 i = i + n; i = n + i; // require addition with difference type
613 i -= n; // require assignment subtraction operator
614 i = i - n; // require subtraction with difference type
615 n = i - j; // require difference operator
616 (void)i[n]; // require element access operator
617 }
618
619 private:
620 TT a, b;
621 TT i, j;
622 typename ndnboost::detail::iterator_traits<TT>::difference_type n;
623 };
624
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700625 NDNBOOST_concept(Mutable_RandomAccessIterator,(TT))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700626 : RandomAccessIterator<TT>
627 , Mutable_BidirectionalIterator<TT>
628 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700629 NDNBOOST_CONCEPT_USAGE(Mutable_RandomAccessIterator)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700630 {
631 i[n] = *i; // require element access and assignment
632 }
633 private:
634 TT i;
635 typename ndnboost::detail::iterator_traits<TT>::difference_type n;
636 };
637
638 //===========================================================================
639 // Container s
640
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700641 NDNBOOST_concept(Container,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700642 : Assignable<C>
643 {
644 typedef typename C::value_type value_type;
645 typedef typename C::difference_type difference_type;
646 typedef typename C::size_type size_type;
647 typedef typename C::const_reference const_reference;
648 typedef typename C::const_pointer const_pointer;
649 typedef typename C::const_iterator const_iterator;
650
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700651 NDNBOOST_CONCEPT_USAGE(Container)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700652 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700653 NDNBOOST_CONCEPT_ASSERT((InputIterator<const_iterator>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700654 const_constraints(c);
655 }
656
657 private:
658 void const_constraints(const C& cc) {
659 i = cc.begin();
660 i = cc.end();
661 n = cc.size();
662 n = cc.max_size();
663 b = cc.empty();
664 }
665 C c;
666 bool b;
667 const_iterator i;
668 size_type n;
669 };
670
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700671 NDNBOOST_concept(Mutable_Container,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700672 : Container<C>
673 {
674 typedef typename C::reference reference;
675 typedef typename C::iterator iterator;
676 typedef typename C::pointer pointer;
677
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700678 NDNBOOST_CONCEPT_USAGE(Mutable_Container)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700679 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700680 NDNBOOST_CONCEPT_ASSERT((
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700681 Assignable<typename Mutable_Container::value_type>));
682
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700683 NDNBOOST_CONCEPT_ASSERT((InputIterator<iterator>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700684
685 i = c.begin();
686 i = c.end();
687 c.swap(c2);
688 }
689
690 private:
691 iterator i;
692 C c, c2;
693 };
694
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700695 NDNBOOST_concept(ForwardContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700696 : Container<C>
697 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700698 NDNBOOST_CONCEPT_USAGE(ForwardContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700699 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700700 NDNBOOST_CONCEPT_ASSERT((
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700701 ForwardIterator<
702 typename ForwardContainer::const_iterator
703 >));
704 }
705 };
706
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700707 NDNBOOST_concept(Mutable_ForwardContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700708 : ForwardContainer<C>
709 , Mutable_Container<C>
710 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700711 NDNBOOST_CONCEPT_USAGE(Mutable_ForwardContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700712 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700713 NDNBOOST_CONCEPT_ASSERT((
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700714 Mutable_ForwardIterator<
715 typename Mutable_ForwardContainer::iterator
716 >));
717 }
718 };
719
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700720 NDNBOOST_concept(ReversibleContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700721 : ForwardContainer<C>
722 {
723 typedef typename
724 C::const_reverse_iterator
725 const_reverse_iterator;
726
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700727 NDNBOOST_CONCEPT_USAGE(ReversibleContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700728 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700729 NDNBOOST_CONCEPT_ASSERT((
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700730 BidirectionalIterator<
731 typename ReversibleContainer::const_iterator>));
732
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700733 NDNBOOST_CONCEPT_ASSERT((BidirectionalIterator<const_reverse_iterator>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700734
735 const_constraints(c);
736 }
737 private:
738 void const_constraints(const C& cc)
739 {
740 const_reverse_iterator i = cc.rbegin();
741 i = cc.rend();
742 }
743 C c;
744 };
745
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700746 NDNBOOST_concept(Mutable_ReversibleContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700747 : Mutable_ForwardContainer<C>
748 , ReversibleContainer<C>
749 {
750 typedef typename C::reverse_iterator reverse_iterator;
751
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700752 NDNBOOST_CONCEPT_USAGE(Mutable_ReversibleContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700753 {
754 typedef typename Mutable_ForwardContainer<C>::iterator iterator;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700755 NDNBOOST_CONCEPT_ASSERT((Mutable_BidirectionalIterator<iterator>));
756 NDNBOOST_CONCEPT_ASSERT((Mutable_BidirectionalIterator<reverse_iterator>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700757
758 reverse_iterator i = c.rbegin();
759 i = c.rend();
760 }
761 private:
762 C c;
763 };
764
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700765 NDNBOOST_concept(RandomAccessContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700766 : ReversibleContainer<C>
767 {
768 typedef typename C::size_type size_type;
769 typedef typename C::const_reference const_reference;
770
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700771 NDNBOOST_CONCEPT_USAGE(RandomAccessContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700772 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700773 NDNBOOST_CONCEPT_ASSERT((
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700774 RandomAccessIterator<
775 typename RandomAccessContainer::const_iterator
776 >));
777
778 const_constraints(c);
779 }
780 private:
781 void const_constraints(const C& cc)
782 {
783 const_reference r = cc[n];
784 ignore_unused_variable_warning(r);
785 }
786
787 C c;
788 size_type n;
789 };
790
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700791 NDNBOOST_concept(Mutable_RandomAccessContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700792 : Mutable_ReversibleContainer<C>
793 , RandomAccessContainer<C>
794 {
795 private:
796 typedef Mutable_RandomAccessContainer self;
797 public:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700798 NDNBOOST_CONCEPT_USAGE(Mutable_RandomAccessContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700799 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700800 NDNBOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<typename self::iterator>));
801 NDNBOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<typename self::reverse_iterator>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700802
803 typename self::reference r = c[i];
804 ignore_unused_variable_warning(r);
805 }
806
807 private:
808 typename Mutable_ReversibleContainer<C>::size_type i;
809 C c;
810 };
811
812 // A Sequence is inherently mutable
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700813 NDNBOOST_concept(Sequence,(S))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700814 : Mutable_ForwardContainer<S>
815 // Matt Austern's book puts DefaultConstructible here, the C++
816 // standard places it in Container --JGS
817 // ... so why aren't we following the standard? --DWA
818 , DefaultConstructible<S>
819 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700820 NDNBOOST_CONCEPT_USAGE(Sequence)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700821 {
822 S
823 c(n),
824 c2(n, t),
825 c3(first, last);
826
827 c.insert(p, t);
828 c.insert(p, n, t);
829 c.insert(p, first, last);
830
831 c.erase(p);
832 c.erase(p, q);
833
834 typename Sequence::reference r = c.front();
835
836 ignore_unused_variable_warning(c);
837 ignore_unused_variable_warning(c2);
838 ignore_unused_variable_warning(c3);
839 ignore_unused_variable_warning(r);
840 const_constraints(c);
841 }
842 private:
843 void const_constraints(const S& c) {
844 typename Sequence::const_reference r = c.front();
845 ignore_unused_variable_warning(r);
846 }
847
848 typename S::value_type t;
849 typename S::size_type n;
850 typename S::value_type* first, *last;
851 typename S::iterator p, q;
852 };
853
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700854 NDNBOOST_concept(FrontInsertionSequence,(S))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700855 : Sequence<S>
856 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700857 NDNBOOST_CONCEPT_USAGE(FrontInsertionSequence)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700858 {
859 c.push_front(t);
860 c.pop_front();
861 }
862 private:
863 S c;
864 typename S::value_type t;
865 };
866
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700867 NDNBOOST_concept(BackInsertionSequence,(S))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700868 : Sequence<S>
869 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700870 NDNBOOST_CONCEPT_USAGE(BackInsertionSequence)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700871 {
872 c.push_back(t);
873 c.pop_back();
874 typename BackInsertionSequence::reference r = c.back();
875 ignore_unused_variable_warning(r);
876 const_constraints(c);
877 }
878 private:
879 void const_constraints(const S& cc) {
880 typename BackInsertionSequence::const_reference
881 r = cc.back();
882 ignore_unused_variable_warning(r);
883 };
884 S c;
885 typename S::value_type t;
886 };
887
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700888 NDNBOOST_concept(AssociativeContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700889 : ForwardContainer<C>
890 , DefaultConstructible<C>
891 {
892 typedef typename C::key_type key_type;
893 typedef typename C::key_compare key_compare;
894 typedef typename C::value_compare value_compare;
895 typedef typename C::iterator iterator;
896
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700897 NDNBOOST_CONCEPT_USAGE(AssociativeContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700898 {
899 i = c.find(k);
900 r = c.equal_range(k);
901 c.erase(k);
902 c.erase(i);
903 c.erase(r.first, r.second);
904 const_constraints(c);
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700905 NDNBOOST_CONCEPT_ASSERT((BinaryPredicate<key_compare,key_type,key_type>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700906
907 typedef typename AssociativeContainer::value_type value_type_;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700908 NDNBOOST_CONCEPT_ASSERT((BinaryPredicate<value_compare,value_type_,value_type_>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700909 }
910
911 // Redundant with the base concept, but it helps below.
912 typedef typename C::const_iterator const_iterator;
913 private:
914 void const_constraints(const C& cc)
915 {
916 ci = cc.find(k);
917 n = cc.count(k);
918 cr = cc.equal_range(k);
919 }
920
921 C c;
922 iterator i;
923 std::pair<iterator,iterator> r;
924 const_iterator ci;
925 std::pair<const_iterator,const_iterator> cr;
926 typename C::key_type k;
927 typename C::size_type n;
928 };
929
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700930 NDNBOOST_concept(UniqueAssociativeContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700931 : AssociativeContainer<C>
932 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700933 NDNBOOST_CONCEPT_USAGE(UniqueAssociativeContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700934 {
935 C c(first, last);
936
937 pos_flag = c.insert(t);
938 c.insert(first, last);
939
940 ignore_unused_variable_warning(c);
941 }
942 private:
943 std::pair<typename C::iterator, bool> pos_flag;
944 typename C::value_type t;
945 typename C::value_type* first, *last;
946 };
947
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700948 NDNBOOST_concept(MultipleAssociativeContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700949 : AssociativeContainer<C>
950 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700951 NDNBOOST_CONCEPT_USAGE(MultipleAssociativeContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700952 {
953 C c(first, last);
954
955 pos = c.insert(t);
956 c.insert(first, last);
957
958 ignore_unused_variable_warning(c);
959 ignore_unused_variable_warning(pos);
960 }
961 private:
962 typename C::iterator pos;
963 typename C::value_type t;
964 typename C::value_type* first, *last;
965 };
966
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700967 NDNBOOST_concept(SimpleAssociativeContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700968 : AssociativeContainer<C>
969 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700970 NDNBOOST_CONCEPT_USAGE(SimpleAssociativeContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700971 {
972 typedef typename C::key_type key_type;
973 typedef typename C::value_type value_type;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700974 NDNBOOST_MPL_ASSERT((ndnboost::is_same<key_type,value_type>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700975 }
976 };
977
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700978 NDNBOOST_concept(PairAssociativeContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700979 : AssociativeContainer<C>
980 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700981 NDNBOOST_CONCEPT_USAGE(PairAssociativeContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700982 {
983 typedef typename C::key_type key_type;
984 typedef typename C::value_type value_type;
985 typedef typename C::mapped_type mapped_type;
986 typedef std::pair<const key_type, mapped_type> required_value_type;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700987 NDNBOOST_MPL_ASSERT((ndnboost::is_same<value_type,required_value_type>));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700988 }
989 };
990
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700991 NDNBOOST_concept(SortedAssociativeContainer,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700992 : AssociativeContainer<C>
993 , ReversibleContainer<C>
994 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700995 NDNBOOST_CONCEPT_USAGE(SortedAssociativeContainer)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700996 {
997 C
998 c(kc),
999 c2(first, last),
1000 c3(first, last, kc);
1001
1002 p = c.upper_bound(k);
1003 p = c.lower_bound(k);
1004 r = c.equal_range(k);
1005
1006 c.insert(p, t);
1007
1008 ignore_unused_variable_warning(c);
1009 ignore_unused_variable_warning(c2);
1010 ignore_unused_variable_warning(c3);
1011 const_constraints(c);
1012 }
1013
1014 void const_constraints(const C& c)
1015 {
1016 kc = c.key_comp();
1017 vc = c.value_comp();
1018
1019 cp = c.upper_bound(k);
1020 cp = c.lower_bound(k);
1021 cr = c.equal_range(k);
1022 }
1023
1024 private:
1025 typename C::key_compare kc;
1026 typename C::value_compare vc;
1027 typename C::value_type t;
1028 typename C::key_type k;
1029 typedef typename C::iterator iterator;
1030 typedef typename C::const_iterator const_iterator;
1031
1032 typedef SortedAssociativeContainer self;
1033 iterator p;
1034 const_iterator cp;
1035 std::pair<typename self::iterator,typename self::iterator> r;
1036 std::pair<typename self::const_iterator,typename self::const_iterator> cr;
1037 typename C::value_type* first, *last;
1038 };
1039
1040 // HashedAssociativeContainer
1041
Jeff Thompson3d613fd2013-10-15 15:39:04 -07001042 NDNBOOST_concept(Collection,(C))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001043 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -07001044 NDNBOOST_CONCEPT_USAGE(Collection)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001045 {
1046 ndnboost::function_requires<ndnboost::InputIteratorConcept<iterator> >();
1047 ndnboost::function_requires<ndnboost::InputIteratorConcept<const_iterator> >();
1048 ndnboost::function_requires<ndnboost::CopyConstructibleConcept<value_type> >();
1049 const_constraints(c);
1050 i = c.begin();
1051 i = c.end();
1052 c.swap(c);
1053 }
1054
1055 void const_constraints(const C& cc) {
1056 ci = cc.begin();
1057 ci = cc.end();
1058 n = cc.size();
1059 b = cc.empty();
1060 }
1061
1062 private:
1063 typedef typename C::value_type value_type;
1064 typedef typename C::iterator iterator;
1065 typedef typename C::const_iterator const_iterator;
1066 typedef typename C::reference reference;
1067 typedef typename C::const_reference const_reference;
1068 // typedef typename C::pointer pointer;
1069 typedef typename C::difference_type difference_type;
1070 typedef typename C::size_type size_type;
1071
1072 C c;
1073 bool b;
1074 iterator i;
1075 const_iterator ci;
1076 size_type n;
1077 };
1078} // namespace ndnboost
1079
1080# include <ndnboost/concept/detail/concept_undef.hpp>
1081
Jeff Thompson3d613fd2013-10-15 15:39:04 -07001082#endif // NDNBOOST_CONCEPT_CHECKS_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001083