00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00052 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_CONSTRAINTS
00053 #define STLSOFT_INCL_STLSOFT_UTIL_HPP_CONSTRAINTS
00054
00055 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00056 # define STLSOFT_VER_STLSOFT_UTIL_HPP_CONSTRAINTS_MAJOR 5
00057 # define STLSOFT_VER_STLSOFT_UTIL_HPP_CONSTRAINTS_MINOR 0
00058 # define STLSOFT_VER_STLSOFT_UTIL_HPP_CONSTRAINTS_REVISION 2
00059 # define STLSOFT_VER_STLSOFT_UTIL_HPP_CONSTRAINTS_EDIT 97
00060 #endif
00061
00062
00063
00064
00065
00066 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00067 # include <stlsoft/stlsoft.h>
00068 #endif
00069 #ifndef STLSOFT_INCL_STLSOFT_META_HPP_SIZE_OF
00070 # include <stlsoft/meta/size_of.hpp>
00071 #endif
00072
00073
00074
00075
00076
00077 #ifndef _STLSOFT_NO_NAMESPACE
00078 namespace stlsoft
00079 {
00080 #endif
00081
00082
00083
00084
00085
00086 #if defined(STLSOFT_COMPILER_IS_BORLAND) || \
00087 defined(STLSOFT_COMPILER_IS_INTEL) || \
00088 defined(STLSOFT_COMPILER_IS_MWERKS)
00089 # define stlsoft_constraint_must_be_pod(T) do { stlsoft_ns_qual(must_be_pod)<T>::func_ptr_type const pfn = stlsoft_ns_qual(must_be_pod)<T>::constraint(); STLSOFT_SUPPRESS_UNUSED(pfn); } while(0)
00090 # define stlsoft_constraint_must_be_pod_or_void(T) do { stlsoft_ns_qual(must_be_pod_or_void)<T>::func_ptr_type const pfn = stlsoft_ns_qual(must_be_pod_or_void)<T>::constraint(); STLSOFT_SUPPRESS_UNUSED(pfn); } while(0)
00091 #elif defined(STLSOFT_COMPILER_IS_DMC)
00092 # define stlsoft_constraint_must_be_pod(T) do { int i = sizeof(stlsoft_ns_qual(must_be_pod)<T>::constraint()); } while(0)
00093 # define stlsoft_constraint_must_be_pod_or_void(T) do { int i = sizeof(stlsoft_ns_qual(must_be_pod_or_void)<T>::constraint()); } while(0)
00094 #else
00095 # define stlsoft_constraint_must_be_pod(T) STLSOFT_STATIC_ASSERT(sizeof(stlsoft_ns_qual(must_be_pod)<T>::constraint()) != 0)
00096 # define stlsoft_constraint_must_be_pod_or_void(T) STLSOFT_STATIC_ASSERT(sizeof(stlsoft_ns_qual(must_be_pod_or_void)<T>::constraint()) != 0)
00097 #endif
00098
00099 # define stlsoft_constraint_must_be_same_size(T1, T2) static_cast<void>(stlsoft_ns_qual(must_be_same_size)<T1, T2>())
00100 # define stlsoft_constraint_must_be_subscriptable(T) static_cast<void>(stlsoft_ns_qual(must_be_subscriptable)<T>())
00101 # define stlsoft_constraint_must_have_base(D, B) static_cast<void>(stlsoft_ns_qual(must_have_base)<D, B>())
00102 # define stlsoft_constraint_must_be_derived(D, B) static_cast<void>(stlsoft_ns_qual(must_be_derived)<D, B>())
00103
00104
00105
00106
00107
00137
00138 template< ss_typename_param_k D
00139 , ss_typename_param_k B
00140 >
00141 struct must_have_base
00142 {
00143 public:
00144 ~must_have_base() stlsoft_throw_0()
00145 {
00146 void(*p)(D*, B*) = constraints;
00147
00148 STLSOFT_SUPPRESS_UNUSED(p);
00149 }
00150
00151 private:
00152 static void constraints(D* pd, B* pb)
00153 {
00154 pb = pd;
00155
00156 STLSOFT_SUPPRESS_UNUSED(pb);
00157 }
00158 };
00159
00160
00191
00192 template< ss_typename_param_k D
00193 , ss_typename_param_k B
00194 >
00195 struct must_be_derived
00196 {
00197 public:
00198 ~must_be_derived() stlsoft_throw_0()
00199 {
00200 # if defined(STLSOFT_COMPILER_IS_BORLAND)
00201 cant_be_overloaded_if_same_type(static_cast<D*>(0)
00202 , static_cast<B*>(0));
00203 # else
00204 void(*p)(D*, B*) = cant_be_overloaded_if_same_type;
00205
00206 STLSOFT_SUPPRESS_UNUSED(p);
00207 # endif
00208 }
00209
00210 private:
00211 static void cant_be_overloaded_if_same_type(D* pd, B* pb)
00212 {
00213 pb = pd;
00214
00215 STLSOFT_SUPPRESS_UNUSED(pb);
00216 }
00217 static void cant_be_overloaded_if_same_type(B* pb, D* pd)
00218 {
00219 pb = pd;
00220
00221 STLSOFT_SUPPRESS_UNUSED(pb);
00222 }
00223 };
00224
00225
00226
00242
00243 template< ss_typename_param_k T1
00244 , ss_typename_param_k T2
00245 >
00246 struct must_be_same_size
00247 {
00248 ~must_be_same_size() stlsoft_throw_0()
00249 {
00250 void (*pfn)(void) = constraints;
00251
00252 STLSOFT_SUPPRESS_UNUSED(pfn);
00253 }
00254 private:
00255 static void constraints()
00256 {
00257
00258
00259 struct must_be_same_size_
00260 {
00261 int T1_must_be_same_size_as_T2 : (static_cast<int>(size_of<T1>::value) == static_cast<int>(size_of<T2>::value));
00262 };
00263
00264 const int T1_must_be_same_size_as_T2 = (static_cast<int>(size_of<T1>::value) == static_cast<int>(size_of<T2>::value));
00265 int i[T1_must_be_same_size_as_T2];
00266
00267 STLSOFT_SUPPRESS_UNUSED(i);
00268 }
00269 };
00270
00271
00290
00291 template <ss_typename_param_k T>
00292 struct must_be_subscriptable
00293 {
00294 public:
00295 ~must_be_subscriptable() stlsoft_throw_0()
00296 {
00297 int (*pfn)(T const&) = constraints;
00298
00299 STLSOFT_SUPPRESS_UNUSED(pfn);
00300 }
00301 private:
00302 static int constraints(T const& T_is_not_subscriptable)
00303 {
00304
00305 return sizeof(T_is_not_subscriptable[0]);
00306 }
00307 };
00308
00327
00328 template <ss_typename_param_k T>
00329 struct must_subscript_as_decayable_pointer
00330 {
00331 public:
00332 ~must_subscript_as_decayable_pointer() stlsoft_throw_0()
00333 {
00334 ss_size_t (*pfn)(T const&) = constraints;
00335
00336 STLSOFT_SUPPRESS_UNUSED(pfn);
00337 }
00338 private:
00339 static ss_size_t constraints(T const& T_is_not_decay_subscriptable)
00340 {
00341
00342
00343 return sizeof(0[T_is_not_decay_subscriptable]);
00344 }
00345 };
00346
00347
00370
00371 template <ss_typename_param_k T>
00372 union must_be_pod
00373 {
00374 private:
00375 typedef must_be_pod<T> class_type;
00376
00377 public:
00378 T t;
00379 int i;
00380
00381 typedef int (*func_ptr_type)();
00382
00383 static func_ptr_type constraint()
00384 {
00385 return constraints;
00386 }
00387
00388
00389 ~must_be_pod() stlsoft_throw_0()
00390 {
00391 int (*pfn)(void) = constraints;
00392
00393 STLSOFT_SUPPRESS_UNUSED(pfn);
00394 }
00395
00396 private:
00397 static int constraints()
00398 {
00399 #if defined(STLSOFT_COMPILER_IS_MWERKS)
00400 # if ((__MWERKS__ & 0xFF00) < 0x3000)
00401 class_type u;
00402 # else
00403 class_type u;
00404
00405 u = *static_cast<class_type*>(0);
00406 # endif
00407 #elif defined(STLSOFT_COMPILER_IS_GCC) && \
00408 __GNUC__ < 3
00409 class_type u = *static_cast<class_type*>(0);
00410 #else
00411 class_type u = class_type();
00412 #endif
00413
00414 STLSOFT_SUPPRESS_UNUSED(u);
00415
00416 return sizeof(u);
00417 }
00418 };
00419
00420
00444
00445 template <ss_typename_param_k T>
00446 union must_be_pod_or_void
00447 {
00448 private:
00449 typedef must_be_pod_or_void<T> class_type;
00450
00451 public:
00452 T t;
00453 int i;
00454
00455 typedef int (*func_ptr_type)();
00456
00457 static func_ptr_type constraint()
00458 {
00459 return constraints;
00460 }
00461
00462 #if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
00463 protected:
00464 #else
00465 private:
00466 #endif
00467 static int constraints()
00468 {
00469 class_type u;
00470
00471 u.i = 1;
00472
00473 STLSOFT_SUPPRESS_UNUSED(u);
00474
00475 return sizeof(u);
00476 }
00477 };
00478
00479 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00480
00481 STLSOFT_TEMPLATE_SPECIALISATION
00482 union must_be_pod_or_void<void>
00483 {
00484 typedef int (*func_ptr_type)();
00485
00486 static func_ptr_type constraint()
00487 {
00488 return static_cast<func_ptr_type>(0);
00489 }
00490 };
00491
00492 #endif
00493
00494
00495
00496 #if 0
00497
00505 #ifdef NIC_TEMPLATE_VERSION
00506
00507
00508
00509 typedef void nic_null_;
00510
00511 template <ss_typename_param_k T = nic_null_>
00512 struct not_implicitly_comparable
00513 : public T
00514 {
00515 public:
00516 typedef not_implicitly_comparable<T> class_type;
00517
00518 #if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
00519 protected:
00520 #else
00521 private:
00522 #endif
00523 #if 0
00524 template <ss_typename_param_k T2>
00525 ss_bool_t operator ==(T2 const&) const;
00526 template <ss_typename_param_k T2>
00527 ss_bool_t operator !=(T2 const&) const;
00528 #endif
00529 };
00530
00536 STLSOFT_TEMPLATE_SPECIALISATION
00537 struct not_implicitly_comparable<nic_null_>
00538 {
00539 public:
00540 typedef not_implicitly_comparable<nic_null_> class_type;
00541
00542 #if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
00543 protected:
00544 #else
00545 private:
00546 #endif
00547 #if 0
00548 template <ss_typename_param_k T2>
00549 ss_bool_t operator ==(T2 const&) const;
00550 template <ss_typename_param_k T2>
00551 ss_bool_t operator !=(T2 const&) const;
00552 #endif
00553 };
00554
00555 template< ss_typename_param_k T
00556 , ss_typename_param_k T2
00557 >
00558 inline ss_bool_t operator ==(not_implicitly_comparable<T> const& lhs, T2 const& rhs)
00559 {
00560
00561
00562 lhs.this_type_does_not_support_comparisons();
00563
00564 return false;
00565 }
00566
00567 template< ss_typename_param_k T
00568 , ss_typename_param_k T2
00569 >
00570 inline ss_bool_t operator ==(T2 const& lhs, not_implicitly_comparable<T> const& rhs)
00571 {
00572
00573
00574 rhs.this_type_does_not_support_comparisons();
00575
00576 return false;
00577 }
00578
00579 #if 0
00580 template< ss_typename_param_k T1
00581 , ss_typename_param_k T2
00582 >
00583 inline ss_bool_t operator ==(not_implicitly_comparable<T1> const& lhs, not_implicitly_comparable<T2> const& rhs)
00584 {
00585
00586
00587 rhs.this_type_does_not_support_comparisons();
00588
00589 return false;
00590 }
00591 #endif
00592
00593 template< ss_typename_param_k T
00594 , ss_typename_param_k T2
00595 >
00596 inline ss_bool_t operator !=(T2 const& lhs, not_implicitly_comparable<T> const& rhs)
00597 {
00598
00599
00600 rhs.this_type_does_not_support_comparisons();
00601
00602 return false;
00603 }
00604
00605 template< ss_typename_param_k T
00606 , ss_typename_param_k T2
00607 >
00608 inline ss_bool_t operator !=(not_implicitly_comparable<T> const& lhs, T2 const& rhs)
00609 {
00610
00611
00612 lhs.this_type_does_not_support_comparisons();
00613
00614 return false;
00615 }
00616
00617 template< ss_typename_param_k T1
00618 , ss_typename_param_k T2
00619 >
00620 inline ss_bool_t operator !=(not_implicitly_comparable<T1> const& lhs, not_implicitly_comparable<T2> const& rhs)
00621 {
00622
00623
00624 lhs.this_type_does_not_support_comparisons();
00625
00626 return false;
00627 }
00628
00629 #else
00630
00631 struct not_implicitly_comparable
00632 {
00633 public:
00634 typedef not_implicitly_comparable class_type;
00635
00636 #if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
00637 protected:
00638 #else
00639 private:
00640 #endif
00641
00642 #ifndef NIC_EXTERNAL_OPERATORS
00643 ss_bool_t operator ==(class_type const&) const;
00644 ss_bool_t operator !=(class_type const&) const;
00645
00646 template <ss_typename_param_k T2>
00647 ss_bool_t operator ==(T2 const&) const;
00648 template <ss_typename_param_k T2>
00649 ss_bool_t operator !=(T2 const&) const;
00650 #endif
00651 };
00652
00653
00654 #ifdef NIC_EXTERNAL_OPERATORS
00655
00656 template< ss_typename_param_k T2
00657 >
00658 inline ss_bool_t operator ==(not_implicitly_comparable const& lhs, T2 const& rhs)
00659 {
00660
00661
00662 lhs.this_type_does_not_support_comparisons();
00663
00664 return false;
00665 }
00666
00667 template< ss_typename_param_k T2
00668 >
00669 inline ss_bool_t operator ==(T2 const& lhs, not_implicitly_comparable const& rhs)
00670 {
00671
00672
00673 rhs.this_type_does_not_support_comparisons();
00674
00675 return false;
00676 }
00677 #endif
00678
00679 #endif
00680 #endif
00681
00682
00683
00684 #ifndef _STLSOFT_NO_NAMESPACE
00685 }
00686 #endif
00687
00688
00689
00690 #endif
00691
00692