Changeset 3238


Ignore:
Timestamp:
May 24, 2014, 12:27:39 PM (9 years ago)
Author:
Peter
Message:

sort_index: add some compile tests, CONCEPT_ASSERTs, and add docs on requirements the compiler tests revealed.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility.cc

    r3210 r3238  
    511511  if (false) {
    512512    std::vector<size_t> vec;
    513     utility::sort_index(boost::forward_iterator_archetype<double>(),
    514                         boost::forward_iterator_archetype<double>(),
    515                         vec);
     513    // value type must be possible to store in a vector so has to be
     514    // default constructible and assignable
     515    typedef boost::default_constructible_archetype<
     516      boost::sgi_assignable_archetype<
     517        boost::less_than_comparable_archetype<> > > value_type;
     518    boost::input_iterator_archetype<value_type> iter;
     519    utility::sort_index(iter, iter, vec);
     520    // try with a random access container as well
     521    std::vector<value_type> vec2;
     522    utility::sort_index(vec2.begin(), vec2.end(), vec);
     523  }
     524  // same thing with four argument version
     525  if (false) {
     526    std::vector<size_t> vec;
     527    // value type must be possible to store in a vector so has to be
     528    // default constructible and assignable
     529    typedef boost::default_constructible_archetype<
     530      boost::sgi_assignable_archetype<> > value_type;
     531
     532    boost::input_iterator_archetype<value_type> iter;
     533
     534    // Create a binary predicate that is assignable and default constructible
     535    boost::default_constructible_archetype<
     536      boost::sgi_assignable_archetype<
     537        boost::binary_predicate_archetype<
     538          value_type, value_type> > > comp;
     539
     540    utility::sort_index(iter, iter, vec, comp);
     541    // try with a random access container as well
     542    std::vector<value_type> vec2;
     543    utility::sort_index(vec2.begin(), vec2.end(), vec, comp);
    516544  }
    517545}
  • trunk/yat/utility/sort_index.h

    r3237 r3238  
    4949     <a href=http://www.sgi.com/tech/stl/LessThanComparable.html>
    5050     LessThan Comparable</a>
     51     - \c InputIterator::value_type is
     52     <a href=http://www.sgi.com/tech/stl/DefaultConstructible.html>
     53     Default Constructible</a> and
     54     <a href=http://www.sgi.com/tech/stl/Assignable.html>
     55     Assignable</a>
    5156
    5257     \since New in yat 0.5. In versions prior 0.13 function was restricted to
    53      \forward_iterator and \c value_type of \c double.
     58     \forward_iterator with \c value_type convertible to \c double.
    5459  */
    5560  template<typename InputIterator>
     
    6671     <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">
    6772     Strict Weak Ordering</a>
     73     - \c Compare is
     74     <a href="http://www.sgi.com/tech/stl/Assignable.html">
     75     Assignable</a>
     76     - \c InputIterator::value_type is
     77     <a href=http://www.sgi.com/tech/stl/DefaultConstructible.html>
     78     Default Constructible</a> and
     79     <a href=http://www.sgi.com/tech/stl/Assignable.html>
     80     Assignable</a>
    6881     - \c InputIterator::value_type is convertible to \c Compare's
    6982       argument type
     
    121134    BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
    122135    typedef typename std::iterator_traits<InputIterator>::value_type T;
     136    BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<T>));
     137    BOOST_CONCEPT_ASSERT((boost::SGIAssignable<T>));
    123138    BOOST_CONCEPT_ASSERT((boost::LessThanComparable<T>));
    124139    sort_index(first, last, idx, std::less<T>());
     
    131146  {
    132147    BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
    133    
    134148    typedef typename std::iterator_traits<InputIterator> traits;
     149    typedef typename std::iterator_traits<InputIterator>::value_type T;
     150    BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<T>));
     151    BOOST_CONCEPT_ASSERT((boost::SGIAssignable<T>));
     152    BOOST_CONCEPT_ASSERT((boost::Assignable<Compare>));
     153
    135154    typedef typename traits::iterator_category category;
    136155    detail::sort_index(first, last, idx, comp, category());
Note: See TracChangeset for help on using the changeset viewer.