BVB Source Codes

mars Show iterator_concepts.hpp Source code

Return Download mars: download iterator_concepts.hpp Source code - Download mars Source code - Type:.hpp
  1. // (C) Copyright Jeremy Siek 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5.  
  6. #ifndef BOOST_ITERATOR_CONCEPTS_HPP
  7. #define BOOST_ITERATOR_CONCEPTS_HPP
  8.  
  9. #include <boost/concept_check.hpp>
  10. #include <boost/iterator/iterator_categories.hpp>
  11.  
  12. // Use mars_boost::detail::iterator_traits to work around some MSVC/Dinkumware problems.
  13. #include <boost/detail/iterator.hpp>
  14.  
  15. #include <boost/type_traits/is_same.hpp>
  16. #include <boost/type_traits/is_integral.hpp>
  17.  
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/mpl/if.hpp>
  20. #include <boost/mpl/and.hpp>
  21. #include <boost/mpl/or.hpp>
  22.  
  23. #include <boost/static_assert.hpp>
  24.  
  25. // Use boost/limits to work around missing limits headers on some compilers
  26. #include <boost/limits.hpp>
  27. #include <boost/config.hpp>
  28.  
  29. #include <algorithm>
  30.  
  31. #include <boost/concept/detail/concept_def.hpp>
  32.  
  33. namespace mars_boost_concepts
  34. {
  35.   // Used a different namespace here (instead of "boost") so that the
  36.   // concept descriptions do not take for granted the names in
  37.   // namespace mars_boost.
  38.  
  39.   //===========================================================================
  40.   // Iterator Access Concepts
  41.  
  42.   BOOST_concept(ReadableIterator,(Iterator))
  43.     : mars_boost::Assignable<Iterator>
  44.     , mars_boost::CopyConstructible<Iterator>
  45.  
  46.   {
  47.       typedef BOOST_DEDUCED_TYPENAME mars_boost::detail::iterator_traits<Iterator>::value_type value_type;
  48.       typedef BOOST_DEDUCED_TYPENAME mars_boost::detail::iterator_traits<Iterator>::reference reference;
  49.  
  50.       BOOST_CONCEPT_USAGE(ReadableIterator)
  51.       {
  52.  
  53.           value_type v = *i;
  54.           mars_boost::ignore_unused_variable_warning(v);
  55.       }
  56.   private:
  57.       Iterator i;
  58.   };
  59.  
  60.   template <
  61.       typename Iterator
  62.     , typename ValueType = BOOST_DEDUCED_TYPENAME mars_boost::detail::iterator_traits<Iterator>::value_type
  63.   >
  64.   struct WritableIterator
  65.     : mars_boost::CopyConstructible<Iterator>
  66.   {
  67.       BOOST_CONCEPT_USAGE(WritableIterator)
  68.       {
  69.           *i = v;
  70.       }
  71.   private:
  72.       ValueType v;
  73.       Iterator i;
  74.   };
  75.  
  76.   template <
  77.       typename Iterator
  78.     , typename ValueType = BOOST_DEDUCED_TYPENAME mars_boost::detail::iterator_traits<Iterator>::value_type
  79.   >
  80.   struct WritableIteratorConcept : WritableIterator<Iterator,ValueType> {};
  81.  
  82.   BOOST_concept(SwappableIterator,(Iterator))
  83.   {
  84.       BOOST_CONCEPT_USAGE(SwappableIterator)
  85.       {
  86.           std::iter_swap(i1, i2);
  87.       }
  88.   private:
  89.       Iterator i1;
  90.       Iterator i2;
  91.   };
  92.  
  93.   BOOST_concept(LvalueIterator,(Iterator))
  94.   {
  95.       typedef typename mars_boost::detail::iterator_traits<Iterator>::value_type value_type;
  96.  
  97.       BOOST_CONCEPT_USAGE(LvalueIterator)
  98.       {
  99.         value_type& r = const_cast<value_type&>(*i);
  100.         mars_boost::ignore_unused_variable_warning(r);
  101.       }
  102.   private:
  103.       Iterator i;
  104.   };
  105.  
  106.  
  107.   //===========================================================================
  108.   // Iterator Traversal Concepts
  109.  
  110.   BOOST_concept(IncrementableIterator,(Iterator))
  111.     : mars_boost::Assignable<Iterator>
  112.     , mars_boost::CopyConstructible<Iterator>
  113.   {
  114.       typedef typename mars_boost::iterator_traversal<Iterator>::type traversal_category;
  115.  
  116.       BOOST_CONCEPT_ASSERT((
  117.         mars_boost::Convertible<
  118.             traversal_category
  119.           , mars_boost::incrementable_traversal_tag
  120.         >));
  121.  
  122.       BOOST_CONCEPT_USAGE(IncrementableIterator)
  123.       {
  124.           ++i;
  125.           (void)i++;
  126.       }
  127.   private:
  128.       Iterator i;
  129.   };
  130.  
  131.   BOOST_concept(SinglePassIterator,(Iterator))
  132.     : IncrementableIterator<Iterator>
  133.     , mars_boost::EqualityComparable<Iterator>
  134.  
  135.   {
  136.       BOOST_CONCEPT_ASSERT((
  137.           mars_boost::Convertible<
  138.              BOOST_DEDUCED_TYPENAME SinglePassIterator::traversal_category
  139.            , mars_boost::single_pass_traversal_tag
  140.           > ));
  141.   };
  142.  
  143.   BOOST_concept(ForwardTraversal,(Iterator))
  144.     : SinglePassIterator<Iterator>
  145.     , mars_boost::DefaultConstructible<Iterator>
  146.   {
  147.       typedef typename mars_boost::detail::iterator_traits<Iterator>::difference_type difference_type;
  148.  
  149.       BOOST_MPL_ASSERT((mars_boost::is_integral<difference_type>));
  150.       BOOST_MPL_ASSERT_RELATION(std::numeric_limits<difference_type>::is_signed, ==, true);
  151.  
  152.       BOOST_CONCEPT_ASSERT((
  153.           mars_boost::Convertible<
  154.              BOOST_DEDUCED_TYPENAME ForwardTraversal::traversal_category
  155.            , mars_boost::forward_traversal_tag
  156.           > ));
  157.   };
  158.  
  159.   BOOST_concept(BidirectionalTraversal,(Iterator))
  160.     : ForwardTraversal<Iterator>
  161.   {
  162.       BOOST_CONCEPT_ASSERT((
  163.           mars_boost::Convertible<
  164.              BOOST_DEDUCED_TYPENAME BidirectionalTraversal::traversal_category
  165.            , mars_boost::bidirectional_traversal_tag
  166.           > ));
  167.  
  168.       BOOST_CONCEPT_USAGE(BidirectionalTraversal)
  169.       {
  170.           --i;
  171.           (void)i--;
  172.       }
  173.    private:
  174.       Iterator i;
  175.   };
  176.  
  177.   BOOST_concept(RandomAccessTraversal,(Iterator))
  178.     : BidirectionalTraversal<Iterator>
  179.   {
  180.       BOOST_CONCEPT_ASSERT((
  181.           mars_boost::Convertible<
  182.              BOOST_DEDUCED_TYPENAME RandomAccessTraversal::traversal_category
  183.            , mars_boost::random_access_traversal_tag
  184.           > ));
  185.  
  186.       BOOST_CONCEPT_USAGE(RandomAccessTraversal)
  187.       {
  188.           i += n;
  189.           i = i + n;
  190.           i = n + i;
  191.           i -= n;
  192.           i = i - n;
  193.           n = i - j;
  194.       }
  195.  
  196.    private:
  197.       typename BidirectionalTraversal<Iterator>::difference_type n;
  198.       Iterator i, j;
  199.   };
  200.  
  201.   //===========================================================================
  202.   // Iterator Interoperability
  203.  
  204.   namespace detail
  205.   {
  206.     template <typename Iterator1, typename Iterator2>
  207.     void interop_single_pass_constraints(Iterator1 const& i1, Iterator2 const& i2)
  208.     {
  209.         bool b;
  210.         b = i1 == i2;
  211.         b = i1 != i2;
  212.  
  213.         b = i2 == i1;
  214.         b = i2 != i1;
  215.         mars_boost::ignore_unused_variable_warning(b);
  216.     }
  217.  
  218.     template <typename Iterator1, typename Iterator2>
  219.     void interop_rand_access_constraints(
  220.         Iterator1 const& i1, Iterator2 const& i2,
  221.         mars_boost::random_access_traversal_tag, mars_boost::random_access_traversal_tag)
  222.     {
  223.         bool b;
  224.         typename mars_boost::detail::iterator_traits<Iterator2>::difference_type n;
  225.         b = i1 <  i2;
  226.         b = i1 <= i2;
  227.         b = i1 >  i2;
  228.         b = i1 >= i2;
  229.         n = i1 -  i2;
  230.  
  231.         b = i2 <  i1;
  232.         b = i2 <= i1;
  233.         b = i2 >  i1;
  234.         b = i2 >= i1;
  235.         n = i2 -  i1;
  236.         mars_boost::ignore_unused_variable_warning(b);
  237.         mars_boost::ignore_unused_variable_warning(n);
  238.     }
  239.  
  240.     template <typename Iterator1, typename Iterator2>
  241.     void interop_rand_access_constraints(
  242.         Iterator1 const&, Iterator2 const&,
  243.         mars_boost::single_pass_traversal_tag, mars_boost::single_pass_traversal_tag)
  244.     { }
  245.  
  246.   } // namespace detail
  247.  
  248.   BOOST_concept(InteroperableIterator,(Iterator)(ConstIterator))
  249.   {
  250.    private:
  251.       typedef typename mars_boost::iterators::pure_iterator_traversal<Iterator>::type traversal_category;
  252.       typedef typename mars_boost::iterators::pure_iterator_traversal<ConstIterator>::type const_traversal_category;
  253.  
  254.    public:
  255.       BOOST_CONCEPT_ASSERT((SinglePassIterator<Iterator>));
  256.       BOOST_CONCEPT_ASSERT((SinglePassIterator<ConstIterator>));
  257.  
  258.       BOOST_CONCEPT_USAGE(InteroperableIterator)
  259.       {
  260.           detail::interop_single_pass_constraints(i, ci);
  261.           detail::interop_rand_access_constraints(i, ci, traversal_category(), const_traversal_category());
  262.  
  263.           ci = i;
  264.       }
  265.  
  266.    private:
  267.       Iterator      i;
  268.       ConstIterator ci;
  269.   };
  270.  
  271. } // namespace mars_boost_concepts
  272.  
  273. #include <boost/concept/detail/concept_undef.hpp>
  274.  
  275. #endif // BOOST_ITERATOR_CONCEPTS_HPP
  276.  
downloaditerator_concepts.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top