containe.h
上传用户:nizebo
上传日期:2022-05-14
资源大小:882k
文件大小:9k
源码类别:

STL

开发平台:

Visual C++

  1. /*
  2.  * Copyright (c) 1999
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Permission to use, copy, modify, distribute and sell this software
  6.  * and its documentation for any purpose is hereby granted without fee,
  7.  * provided that the above copyright notice appear in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation.  Silicon Graphics makes no
  10.  * representations about the suitability of this software for any
  11.  * purpose.  It is provided "as is" without express or implied warranty.
  12.  */
  13. #ifndef __STL_CONTAINER_CONCEPTS_H
  14. #define __STL_CONTAINER_CONCEPTS_H
  15. #include <concept_checks.h>
  16. #ifdef __STL_USE_CONCEPT_CHECKS
  17. // This file covers the following concepts:
  18. //       _Container
  19. //       _ForwardContainer
  20. //       _ReversibleContainer
  21. //       _const_ReversibleContainer
  22. //       _RandomAccessContainer
  23. //
  24. struct _ERROR_IN_STL_CONTAINER {
  25.   /* Container expresssions */
  26.   template <class _Container>
  27.   static void
  28.   __begin_iterator_accessor_requirement_violation(_Container __c) {
  29.     __c.begin();
  30.   }
  31.   template <class _Container>
  32.   static void
  33.   __const_begin_iterator_accessor_requirement_violation(const _Container& __c) {
  34.     __c.begin();
  35.   }
  36.   template <class _Container>
  37.   static void
  38.   __end_iterator_accessor_requirement_violation(_Container __c) {
  39.     __c.end();
  40.   }
  41.   template <class _Container>
  42.   static void
  43.   __const_end_iterator_accessor_requirement_violation(const _Container& __c) {
  44.     __c.end();
  45.   }
  46.   template <class _Container>
  47.   static void
  48.   __rbegin_iterator_accessor_requirement_violation(_Container __c) {
  49.     __c.rbegin();
  50.   }
  51.   template <class _Container>
  52.   static void
  53.   __const_rbegin_iterator_accessor_requirement_violation(const _Container& __c) {
  54.     __c.rbegin();
  55.   }
  56.   template <class _Container>
  57.   static void
  58.   __rend_iterator_accessor_requirement_violation(_Container __c) {
  59.     __c.rend();
  60.   }
  61.   template <class _Container>
  62.   static void
  63.   __const_rend_iterator_accessor_requirement_violation(const _Container& __c) {
  64.     __c.rend();
  65.   }
  66.   template <class _Container>
  67.   static void
  68.   __size_function_must_be_const(const _Container& __c) {
  69.     __c.size();
  70.   }
  71.   template <class _Container>
  72.   static void
  73.   __size_function_requirement_violation(_Container& __c) {
  74.     __c.size();
  75.     __size_function_must_be_const(__c);
  76.   }
  77.   template <class _Container>
  78.   static void
  79.   __max_size_function_must_be_const(const _Container& __c) {
  80.     __c.max_size();
  81.   }
  82.   template <class _Container>
  83.   static void
  84.   __max_size_function_requirement_violation(_Container& __c) {
  85.     __c.max_size();
  86.     __max_size_function_must_be_const(__c);
  87.   }
  88.   template <class _Container>
  89.   static void
  90.   __empty_function_must_be_const(const _Container& __c) {
  91.     __c.empty();
  92.   }
  93.   template <class _Container>
  94.   static void
  95.   __empty_function_requirement_violation(_Container& __c) {
  96.     __c.empty();
  97.     __empty_function_must_be_const(__c);
  98.   }
  99.   template <class _Container>
  100.   static void
  101.   __swap_function_requirement_violation(_Container& __c) {
  102.     __c.swap(__c);
  103.   }
  104. };
  105. __STL_TYPEDEF_REQUIREMENT(iterator);
  106. __STL_TYPEDEF_REQUIREMENT(const_iterator);
  107. /* Containers */
  108. template <class _Container>
  109. struct _Container_concept_specification {
  110. static void
  111. _Container_requirement_violation(_Container __c) {
  112.   // Refinement of Assignable
  113.   _Assignable_concept_specification<_Container>::_Assignable_requirement_violation(__c);
  114.   // Associated Types
  115.   __value_type__typedef_requirement_violation<_Container>();
  116.   __difference_type__typedef_requirement_violation<_Container>();
  117.   __size_type__typedef_requirement_violation<_Container>();
  118.   __reference__typedef_requirement_violation<_Container>();
  119.   __const_reference__typedef_requirement_violation<_Container>();
  120.   __pointer__typedef_requirement_violation<_Container>();
  121.   __const_pointer__typedef_requirement_violation<_Container>();
  122.   __iterator__typedef_requirement_violation<_Container>();
  123.   __const_iterator__typedef_requirement_violation<_Container>();
  124.   // Valid Expressions
  125.   _ERROR_IN_STL_CONTAINER::__const_begin_iterator_accessor_requirement_violation(__c);
  126.   _ERROR_IN_STL_CONTAINER::__const_end_iterator_accessor_requirement_violation(__c);
  127.   _ERROR_IN_STL_CONTAINER::__begin_iterator_accessor_requirement_violation(__c);
  128.   _ERROR_IN_STL_CONTAINER::__end_iterator_accessor_requirement_violation(__c);
  129.   _ERROR_IN_STL_CONTAINER::__size_function_requirement_violation(__c);
  130.   _ERROR_IN_STL_CONTAINER::__max_size_function_requirement_violation(__c);
  131.   _ERROR_IN_STL_CONTAINER::__empty_function_requirement_violation(__c);
  132.   _ERROR_IN_STL_CONTAINER::__swap_function_requirement_violation(__c);
  133.   // Requirements on Iterators
  134.   typedef typename _Container::iterator iter;
  135.   typedef typename _Container::const_iterator const_iter;
  136.   _InputIterator_concept_specification<const_iter>::_InputIterator_requirement_violation(const_iter());
  137.   _InputIterator_concept_specification<iter>::_InputIterator_requirement_violation(iter());
  138. }
  139. };
  140. template <class _ForwardContainer>
  141. struct _ForwardContainer_concept_specification {
  142. static void
  143. _ForwardContainer_requirement_violation(_ForwardContainer __c) {
  144.   // Refinement of Container
  145.   _Container_concept_specification<_ForwardContainer>::_Container_requirement_violation(__c);
  146.   // Requirements on Iterators
  147.   typedef typename _ForwardContainer::iterator iter;
  148.   typedef typename _ForwardContainer::const_iterator const_iter;
  149.   _ForwardIterator_concept_specification<const_iter>::_ForwardIterator_requirement_violation(const_iter());
  150.   _Mutable_ForwardIterator_concept_specification<iter>::_Mutable_ForwardIterator_requirement_violation(iter());
  151. }
  152. };
  153. __STL_TYPEDEF_REQUIREMENT(reverse_iterator);
  154. __STL_TYPEDEF_REQUIREMENT(const_reverse_iterator);
  155. template <class _ReversibleContainer>
  156. struct _ReversibleContainer_concept_specification {
  157. static void
  158. _ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
  159.   // Refinement of ForwardContainer
  160.   _ForwardContainer_concept_specification<_ReversibleContainer>::_ForwardContainer_requirement_violation(__c);
  161.   // Associated types
  162.   __reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
  163.   __const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
  164.   // Valid Expressions
  165.   _ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
  166.   _ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
  167.   _ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
  168.   _ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
  169.   // Requirements on Iterators
  170.   typedef typename _ReversibleContainer::iterator iter;
  171.   typedef typename _ReversibleContainer::const_iterator const_iter;
  172.   _BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
  173.   _Mutable_BidirectionalIterator_concept_specification<iter>::_Mutable_BidirectionalIterator_requirement_violation(iter());
  174. }
  175. };
  176. template <class _ReversibleContainer>
  177. struct _const_ReversibleContainer_concept_specification {
  178. static void
  179. _const_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
  180.   // Refinement of Container (JGS, not ForwardContainer)
  181.   _Container_concept_specification<_ReversibleContainer>::_Container_requirement_violation(__c);
  182.   // Associated types
  183.   __reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
  184.   __const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
  185.   // Valid Expressions
  186.   _ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
  187.   _ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
  188.   _ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
  189.   _ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
  190.   // Requirements on Iterators
  191.   typedef typename _ReversibleContainer::iterator iter;
  192.   typedef typename _ReversibleContainer::const_iterator const_iter;
  193.   
  194.   // This line won't compile on gcc 2.91 due to a compiler bug.
  195. #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 91)
  196.   __BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
  197. #endif
  198. }
  199. };
  200. template <class _RandomAccessContainer>
  201. struct _RandomAccessContainer_concept_specification {
  202. static void
  203. _RandomAccessContainer_requirement_violation(_RandomAccessContainer __c) {
  204.   // Refinement of ReversibleContainer
  205.   _ReversibleContainer_concept_specification<_RandomAccessContainer>::_ReversibleContainer_requirement_violation(__c);
  206.   // Valid Expressions
  207.   typedef typename _RandomAccessContainer::value_type __T;
  208.   typedef typename _RandomAccessContainer::difference_type _Dist;
  209.   typedef typename _Mutable_trait<__T>::_Type Type;
  210.   typedef Type* _TypePtr;
  211.   typedef typename _Mutable_trait<_Dist>::_Type Dist;
  212.   _STL_ERROR::__element_access_operator_requirement_violation(__c,
  213.       _TypePtr(), 
  214.       Dist());
  215.   // Requirements on Iterators
  216.   typedef typename _RandomAccessContainer::iterator iter;
  217.   typedef typename _RandomAccessContainer::const_iterator const_iter;
  218.   _RandomAccessIterator_concept_specification<const_iter>::_RandomAccessIterator_requirement_violation(const_iter());
  219.   _Mutable_RandomAccessIterator_concept_specification<iter>::_Mutable_RandomAccessIterator_requirement_violation(iter());
  220. }
  221. };
  222. #endif /* if __STL_USE_CONCEPT_CHECKS */
  223. #endif /* __STL_CONTAINER_CONCEPTS_H */