epoc32/include/stdapis/boost/iterator/iterator_concepts.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/iterator/iterator_concepts.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,308 @@
     1.4 +// (C) Copyright Jeremy Siek 2002.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See
     1.6 +// accompanying file LICENSE_1_0.txt or copy at
     1.7 +// http://www.boost.org/LICENSE_1_0.txt)
     1.8 +
     1.9 +#ifndef BOOST_ITERATOR_CONCEPTS_HPP
    1.10 +#define BOOST_ITERATOR_CONCEPTS_HPP
    1.11 +
    1.12 +//  Revision History
    1.13 +//  26 Apr 2003 thw
    1.14 +//       Adapted to new iterator concepts
    1.15 +//  22 Nov 2002 Thomas Witt
    1.16 +//       Added interoperable concept.
    1.17 +
    1.18 +#include <boost/concept_check.hpp>
    1.19 +#include <boost/iterator/iterator_categories.hpp>
    1.20 +
    1.21 +// Use boost::detail::iterator_traits to work around some MSVC/Dinkumware problems.
    1.22 +#include <boost/detail/iterator.hpp>
    1.23 +
    1.24 +#include <boost/type_traits/is_same.hpp>
    1.25 +#include <boost/type_traits/is_integral.hpp>
    1.26 +#include <boost/type_traits/is_convertible.hpp>
    1.27 +
    1.28 +#include <boost/mpl/bool.hpp>
    1.29 +#include <boost/mpl/if.hpp>
    1.30 +#include <boost/mpl/and.hpp>
    1.31 +#include <boost/mpl/or.hpp>
    1.32 +
    1.33 +#include <boost/static_assert.hpp>
    1.34 +
    1.35 +// Use boost/limits to work around missing limits headers on some compilers
    1.36 +#include <boost/limits.hpp>
    1.37 +#include <boost/config.hpp>
    1.38 +
    1.39 +#include <algorithm>
    1.40 +
    1.41 +namespace boost_concepts {
    1.42 +  // Used a different namespace here (instead of "boost") so that the
    1.43 +  // concept descriptions do not take for granted the names in
    1.44 +  // namespace boost.
    1.45 +
    1.46 +  // We use this in place of STATIC_ASSERT((is_convertible<...>))
    1.47 +  // because some compilers (CWPro7.x) can't detect convertibility.
    1.48 +  //
    1.49 +  // Of course, that just gets us a different error at the moment with
    1.50 +  // some tests, since new iterator category deduction still depends
    1.51 +  // on convertibility detection. We might need some specializations
    1.52 +  // to support this compiler.
    1.53 +  template <class Target, class Source>
    1.54 +  struct static_assert_base_and_derived
    1.55 +  {
    1.56 +      static_assert_base_and_derived(Target* = (Source*)0) {}
    1.57 +  };
    1.58 +
    1.59 +  //===========================================================================
    1.60 +  // Iterator Access Concepts
    1.61 +
    1.62 +  template <typename Iterator>
    1.63 +  class ReadableIteratorConcept {
    1.64 +  public:
    1.65 +    typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type value_type;
    1.66 +
    1.67 +    void constraints() {
    1.68 +      boost::function_requires< boost::AssignableConcept<Iterator> >();
    1.69 +      boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
    1.70 +
    1.71 +      value_type v = *i;
    1.72 +      boost::ignore_unused_variable_warning(v);
    1.73 +    }
    1.74 +    Iterator i;
    1.75 +  };
    1.76 +  
    1.77 +  template <
    1.78 +      typename Iterator
    1.79 +    , typename ValueType = BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type
    1.80 +  >
    1.81 +  class WritableIteratorConcept {
    1.82 +  public:
    1.83 +      
    1.84 +    void constraints() {
    1.85 +      boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
    1.86 +      *i = v;
    1.87 +    }
    1.88 +    ValueType v;
    1.89 +    Iterator i;
    1.90 +  };
    1.91 +  
    1.92 +  template <typename Iterator>
    1.93 +  class SwappableIteratorConcept {
    1.94 +  public:
    1.95 +
    1.96 +    void constraints() {
    1.97 +      std::iter_swap(i1, i2);
    1.98 +    }
    1.99 +    Iterator i1;
   1.100 +    Iterator i2;
   1.101 +  };
   1.102 +
   1.103 +  template <typename Iterator>
   1.104 +  class LvalueIteratorConcept
   1.105 +  {
   1.106 +   public:
   1.107 +      typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
   1.108 +      void constraints()
   1.109 +      {
   1.110 +        value_type& r = const_cast<value_type&>(*i);
   1.111 +        boost::ignore_unused_variable_warning(r);
   1.112 +      }
   1.113 +    Iterator i;
   1.114 +  };
   1.115 +
   1.116 +  
   1.117 +  //===========================================================================
   1.118 +  // Iterator Traversal Concepts
   1.119 +
   1.120 +  template <typename Iterator>
   1.121 +  class IncrementableIteratorConcept {
   1.122 +  public:
   1.123 +    typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
   1.124 +
   1.125 +    void constraints() {
   1.126 +      boost::function_requires< boost::AssignableConcept<Iterator> >();
   1.127 +      boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
   1.128 +
   1.129 +      BOOST_STATIC_ASSERT(
   1.130 +          (boost::is_convertible<
   1.131 +                traversal_category
   1.132 +              , boost::incrementable_traversal_tag
   1.133 +           >::value
   1.134 +          ));
   1.135 +
   1.136 +      ++i;
   1.137 +      (void)i++;
   1.138 +    }
   1.139 +    Iterator i;
   1.140 +  };
   1.141 +
   1.142 +  template <typename Iterator>
   1.143 +  class SinglePassIteratorConcept {
   1.144 +  public:
   1.145 +    typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
   1.146 +    typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
   1.147 +
   1.148 +    void constraints() {
   1.149 +      boost::function_requires< IncrementableIteratorConcept<Iterator> >();
   1.150 +      boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
   1.151 +
   1.152 +      BOOST_STATIC_ASSERT(
   1.153 +          (boost::is_convertible<
   1.154 +                traversal_category
   1.155 +              , boost::single_pass_traversal_tag
   1.156 +           >::value
   1.157 +          ));
   1.158 +    }
   1.159 +  };
   1.160 +
   1.161 +  template <typename Iterator>
   1.162 +  class ForwardTraversalConcept {
   1.163 +  public:
   1.164 +    typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
   1.165 +    typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
   1.166 +
   1.167 +    void constraints() {
   1.168 +      boost::function_requires< SinglePassIteratorConcept<Iterator> >();
   1.169 +      boost::function_requires< 
   1.170 +        boost::DefaultConstructibleConcept<Iterator> >();
   1.171 +
   1.172 +      typedef boost::mpl::and_<
   1.173 +        boost::is_integral<difference_type>,
   1.174 +        boost::mpl::bool_< std::numeric_limits<difference_type>::is_signed >
   1.175 +        > difference_type_is_signed_integral;
   1.176 +
   1.177 +      BOOST_STATIC_ASSERT(difference_type_is_signed_integral::value);
   1.178 +      BOOST_STATIC_ASSERT(
   1.179 +          (boost::is_convertible<
   1.180 +                traversal_category
   1.181 +              , boost::forward_traversal_tag
   1.182 +           >::value
   1.183 +          ));
   1.184 +    }
   1.185 +  };
   1.186 +  
   1.187 +  template <typename Iterator>
   1.188 +  class BidirectionalTraversalConcept {
   1.189 +  public:
   1.190 +    typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
   1.191 +
   1.192 +    void constraints() {
   1.193 +      boost::function_requires< ForwardTraversalConcept<Iterator> >();
   1.194 +      
   1.195 +      BOOST_STATIC_ASSERT(
   1.196 +          (boost::is_convertible<
   1.197 +                traversal_category
   1.198 +              , boost::bidirectional_traversal_tag
   1.199 +           >::value
   1.200 +          ));
   1.201 +
   1.202 +      --i;
   1.203 +      (void)i--;
   1.204 +    }
   1.205 +    Iterator i;
   1.206 +  };
   1.207 +
   1.208 +  template <typename Iterator>
   1.209 +  class RandomAccessTraversalConcept {
   1.210 +  public:
   1.211 +    typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
   1.212 +    typedef typename boost::detail::iterator_traits<Iterator>::difference_type
   1.213 +      difference_type;
   1.214 +
   1.215 +    void constraints() {
   1.216 +      boost::function_requires< BidirectionalTraversalConcept<Iterator> >();
   1.217 +
   1.218 +      BOOST_STATIC_ASSERT(
   1.219 +          (boost::is_convertible<
   1.220 +                traversal_category
   1.221 +              , boost::random_access_traversal_tag
   1.222 +           >::value
   1.223 +          ));
   1.224 +      
   1.225 +      i += n;
   1.226 +      i = i + n;
   1.227 +      i = n + i;
   1.228 +      i -= n;
   1.229 +      i = i - n;
   1.230 +      n = i - j;
   1.231 +    }
   1.232 +    difference_type n;
   1.233 +    Iterator i, j;
   1.234 +  };
   1.235 +
   1.236 +  //===========================================================================
   1.237 +  // Iterator Interoperability Concept
   1.238 +
   1.239 +  namespace detail
   1.240 +  {
   1.241 +
   1.242 +    template <typename Iterator1, typename Iterator2>
   1.243 +    void interop_single_pass_constraints(Iterator1 const& i1, Iterator2 const& i2)
   1.244 +    {
   1.245 +      bool b;
   1.246 +      b = i1 == i2;
   1.247 +      b = i1 != i2;
   1.248 +      
   1.249 +      b = i2 == i1;
   1.250 +      b = i2 != i1;
   1.251 +    }
   1.252 +    
   1.253 +    template <typename Iterator1, typename Iterator2>
   1.254 +    void interop_rand_access_constraints(Iterator1 const& i1, Iterator2 const& i2,
   1.255 +                                         boost::random_access_traversal_tag, boost::random_access_traversal_tag)
   1.256 +    {
   1.257 +      bool b;
   1.258 +      typename boost::detail::iterator_traits<Iterator2>::difference_type n;
   1.259 +      b = i1 <  i2;
   1.260 +      b = i1 <= i2;
   1.261 +      b = i1 >  i2;
   1.262 +      b = i1 >= i2;
   1.263 +      n = i1 -  i2;
   1.264 +      
   1.265 +      b = i2 <  i1;
   1.266 +      b = i2 <= i1;
   1.267 +      b = i2 >  i1;
   1.268 +      b = i2 >= i1;
   1.269 +      n = i2 -  i1;
   1.270 +    }
   1.271 +    template <typename Iterator1, typename Iterator2>
   1.272 +    void interop_rand_access_constraints(Iterator1 const& i1, Iterator2 const& i2,
   1.273 +                                         boost::single_pass_traversal_tag, boost::single_pass_traversal_tag)
   1.274 +    { }
   1.275 +
   1.276 +  } // namespace detail
   1.277 +
   1.278 +  template <typename Iterator, typename ConstIterator>
   1.279 +  class InteroperableIteratorConcept
   1.280 +  {
   1.281 +  public:
   1.282 +      typedef typename boost::detail::pure_traversal_tag<
   1.283 +          typename boost::iterator_traversal<
   1.284 +              Iterator
   1.285 +          >::type
   1.286 +      >::type traversal_category;
   1.287 +
   1.288 +      typedef typename boost::detail::pure_traversal_tag<
   1.289 +          typename boost::iterator_traversal<
   1.290 +              ConstIterator
   1.291 +          >::type
   1.292 +      >::type const_traversal_category;
   1.293 +
   1.294 +      void constraints()
   1.295 +      {
   1.296 +          boost::function_requires< SinglePassIteratorConcept<Iterator> >();
   1.297 +          boost::function_requires< SinglePassIteratorConcept<ConstIterator> >();
   1.298 +
   1.299 +          detail::interop_single_pass_constraints(i, ci);
   1.300 +          detail::interop_rand_access_constraints(i, ci, traversal_category(), const_traversal_category());
   1.301 +
   1.302 +          ci = i;
   1.303 +      }
   1.304 +      Iterator      i;
   1.305 +      ConstIterator ci;
   1.306 +  };
   1.307 +
   1.308 +} // namespace boost_concepts
   1.309 +
   1.310 +
   1.311 +#endif // BOOST_ITERATOR_CONCEPTS_HPP