Ticket #1947: boost-changes.diff

File boost-changes.diff, 10.2 KB (added by Dave Abrahams, 12 years ago)
  • boost/iterator/iterator_facade.hpp

     
    352352          : m_iter(iter)
    353353        {}
    354354
    355         operator reference() const
     355        operator value_type() const
    356356        {
    357357            return *m_iter;
    358358        }
  • boost/iterator/iterator_archetypes.hpp

     
    8484      assign_proxy& operator=(T) { return *this; }
    8585  };
    8686
    87   template <class T>
     87  template <class T, int id=0>
    8888  struct read_proxy
    8989  {
    9090      operator T() { return static_object<T>::get(); }
    9191  };
    9292
    93   template <class T>
     93  template <class T, int id=0>
    9494  struct read_write_proxy
    95     : read_proxy<T> // Use to inherit from assign_proxy, but that doesn't work. -JGS
     95      : read_proxy<T,id> // Use to inherit from assign_proxy, but that doesn't work. -JGS
    9696  {
    9797      read_write_proxy& operator=(T) { return *this; }
    9898  };
    9999
    100   template <class T>
     100  template <class T, int id=0>
    101101  struct arrow_proxy
    102102  {
    103103      T const* operator->() const { return 0; }
     
    108108  template <class ValueType>
    109109  struct readable_operator_brackets
    110110  {
    111       read_proxy<ValueType> operator[](std::ptrdiff_t n) const { return read_proxy<ValueType>(); }
     111      read_proxy<ValueType,1> operator[](std::ptrdiff_t n) const { return read_proxy<ValueType,1>(); }
    112112  };
    113113
    114114  template <class ValueType>
    115115  struct writable_operator_brackets
    116116  {
    117       read_write_proxy<ValueType> operator[](std::ptrdiff_t n) const { return read_write_proxy<ValueType>(); }
     117      read_write_proxy<ValueType,1> operator[](std::ptrdiff_t n) const { return read_write_proxy<ValueType,1>(); }
    118118  };
    119119
    120120  template <class Value, class AccessCategory, class TraversalCategory>
     
    307307    template <class Value> struct archetype;
    308308};
    309309
    310 template <class Value, class AccessCategory>
    311 struct iterator_access_archetype
    312   : mpl::aux::msvc_eti_base<
    313         typename iterator_access_archetype_impl<
    314             AccessCategory
    315         >::template archetype<Value>
    316     >::type
    317 {
    318 };
    319 
    320310template <>
    321311struct iterator_access_archetype_impl<
    322312    iterator_archetypes::readable_iterator_t
     
    326316    struct archetype
    327317    {
    328318        typedef typename remove_cv<Value>::type value_type;
    329         typedef Value                           reference;
    330         typedef Value*                          pointer;
     319        typedef detail::read_proxy<Value>       reference;
     320        typedef detail::arrow_proxy<Value>      pointer;
    331321
    332         value_type operator*() const { return static_object<value_type>::get(); }
    333 
    334         detail::arrow_proxy<Value> operator->() const { return detail::arrow_proxy<Value>(); }
     322        reference operator*() const { return reference(); }
     323        pointer operator->() const { return pointer(); }
    335324    };
    336325};
    337326
     
    347336        BOOST_STATIC_ASSERT(!is_const<Value>::value);
    348337# endif
    349338        typedef void value_type;
    350         typedef void reference;
     339        typedef detail::assign_proxy<Value> reference;
    351340        typedef void pointer;
    352341
    353         detail::assign_proxy<Value> operator*() const { return detail::assign_proxy<Value>(); }
     342        reference operator*() const { return reference(); }
    354343    };
    355344};
    356345
     346template <class Value, class AccessCategory>
     347struct iterator_access_archetype
     348    :
     349# ifdef BOOST_MSVC
     350    mpl::aux::msvc_eti_base<
     351# endif
     352        iterator_access_archetype_impl<
     353            AccessCategory
     354        >::template archetype<Value>
     355# ifdef BOOST_MSVC
     356    >::type
     357# endif
     358{
     359};
     360
    357361template <>
    358362struct iterator_access_archetype_impl<
    359363    iterator_archetypes::readable_writable_iterator_t
     
    367371    {
    368372        typedef detail::read_write_proxy<Value>    reference;
    369373
    370         detail::read_write_proxy<Value> operator*() const { return detail::read_write_proxy<Value>(); }
     374        reference operator*() const { return reference(); }
    371375    };
    372376};
    373377
     
    511515
    512516} // namespace boost
    513517
    514 
     518namespace std
     519{
     520    template <class Value, class AccessCategory, class TraversalCategory>
     521    struct iterator_traits<
     522        boost::iterator_archetype<Value, AccessCategory, TraversalCategory>
     523        >
     524    : boost::detail::iterator_archetype_base<
     525        Value,AccessCategory,TraversalCategory
     526        >
     527    {};
     528}
    515529#endif // BOOST_ITERATOR_ARCHETYPES_HPP
  • boost/iterator/iterator_concepts.hpp

     
    88
    99#include <boost/concept_check.hpp>
    1010#include <boost/iterator/iterator_categories.hpp>
     11#include <boost/iterator/is_readable_iterator.hpp>
    1112
    1213// Use boost::detail::iterator_traits to work around some MSVC/Dinkumware problems.
    1314#include <boost/detail/iterator.hpp>
     
    191192          i -= n;
    192193          i = i - n;
    193194          n = i - j;
     195          check_brackets(boost::is_readable_iterator<Iterator>());
    194196      }
     197
     198      void check_brackets(boost::mpl::false_) {}
     199      void check_brackets(boost::mpl::true_)
     200      {
     201          typename ReadableIterator<Iterator>::value_type x = i[n];
     202          boost::ignore_unused_variable_warning(x);
     203      }
    195204     
    196205   private:
    197206      typename BidirectionalTraversal<Iterator>::difference_type n;
  • boost/concept_archetype.hpp

     
    604604    self operator++(int) { return *this; }
    605605    self& operator--() { return *this; }
    606606    self operator--(int) { return *this; }
    607     reference operator[](difference_type) const
    608       { return static_object<T>::get(); }
     607    convertible_to_archetype<T> operator[](difference_type) const
     608      { return detail::dummy_constructor(); }
    609609    self& operator+=(difference_type) { return *this; }
    610610    self& operator-=(difference_type) { return *this; }
    611611    difference_type operator-(const self&) const
     
    644644    self operator++(int) { return *this; }
    645645    self& operator--() { return *this; }
    646646    self operator--(int) { return *this; }
    647     reference operator[](difference_type) const
    648       { return static_object<T>::get(); }
     647    convertible_to_archetype<T> operator[](difference_type) const
     648      { return detail::dummy_constructor(); }
    649649    self& operator+=(difference_type) { return *this; }
    650650    self& operator-=(difference_type) { return *this; }
    651651    difference_type operator-(const self&) const
  • boost/concept_check.hpp

     
    573573          i -= n;             // require assignment subtraction operator
    574574          i = i - n;                  // require subtraction with difference type
    575575          n = i - j;                  // require difference operator
    576           (void)i[n];                 // require element access operator
     576
     577          // require element access operator
     578          typename boost::detail::iterator_traits<TT>::value_type v = i[n];
     579          ignore_unused_variable_warning(v);
    577580      }
    578581     
    579582   private:
  • libs/iterator/test/iterator_adaptor_cc.cpp

     
    55
    66#include <boost/iterator/reverse_iterator.hpp>
    77#include <boost/iterator/iterator_concepts.hpp>
     8#include <boost/iterator/iterator_archetypes.hpp>
    89#include <boost/concept_check.hpp>
     10#include <boost/type_traits/is_same.hpp>
    911#include <boost/cstdlib.hpp>
    1012#include <list>
    1113
     14template <class archetype>
     15struct adaptor_passthru
     16    : boost::iterator_adaptor<adaptor_passthru<archetype>, archetype>
     17{
     18};
     19
     20struct dummy_value_type {};
     21
     22typedef boost::iterator_archetype<
     23    dummy_value_type, boost::iterator_archetypes::readable_iterator_t,
     24    boost::random_access_traversal_tag>
     25random_traversal_archetype;
     26
     27template <class T, class U>
     28void assert_not_same(T const& x, U const& y)
     29{
     30    BOOST_MPL_ASSERT_NOT((boost::is_same<T,U>));
     31}
     32
    1233int main()
    1334{
    1435  {
     
    2041    boost::function_requires< boost_concepts::RandomAccessTraversalConcept<rev_iter> >();
    2142    boost::function_requires< boost::RandomAccessIteratorConcept<rev_iter> >();
    2243    boost::function_requires< boost_concepts::InteroperableIteratorConcept<rev_iter, c_rev_iter> >();
     44
     45    // Make sure we're testing what we mean to, below.  Given a proxy
     46    // iterator, its reference type and its operator brackets result
     47    // may be unrelated.
     48    random_traversal_archetype it;
     49    assert_not_same(*it, it[0]);
     50
     51    // In particular, tests that passing our
     52    // random_traversal_archetype through iterator_adaptor preserves
     53    // the ability to convert i[n] into the value type.
     54    BOOST_CONCEPT_ASSERT((
     55        boost_concepts::RandomAccessTraversal<
     56            adaptor_passthru<
     57                random_traversal_archetype
     58            >
     59        >
     60                             ));
    2361  }
    2462
    2563    // Many compilers' builtin container iterators don't interoperate well, though
  • libs/iterator/test/concept_tests.cpp

     
    1616  : public boost::iterator< new_random_access, int >
    1717{
    1818  int& operator*() const { return *m_x; }
     19  int& operator[](difference_type n) const { return *(m_x+n); }
    1920  new_iterator& operator++() { return *this; }
    2021  new_iterator operator++(int) { return *this; }
    2122  new_iterator& operator--() { return *this; }
     
    3637  : public boost::iterator<std::random_access_iterator_tag, int>
    3738{
    3839  int& operator*() const { return *m_x; }
     40  int& operator[](difference_type n) const { return *(m_x+n); }
    3941  old_iterator& operator++() { return *this; }
    4042  old_iterator operator++(int) { return *this; }
    4143  old_iterator& operator--() { return *this; }