Home | History | Annotate | Download | only in iterator.operations
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <iterator>
     11 
     12 // template <InputIterator Iter>
     13 //   Iter::difference_type
     14 //   distance(Iter first, Iter last);
     15 //
     16 // template <RandomAccessIterator Iter>
     17 //   Iter::difference_type
     18 //   distance(Iter first, Iter last);
     19 
     20 #include <iterator>
     21 #include <cassert>
     22 
     23 #include "test_iterators.h"
     24 
     25 template <class It>
     26 void
     27 test(It first, It last, typename std::iterator_traits<It>::difference_type x)
     28 {
     29     assert(std::distance(first, last) == x);
     30 }
     31 
     32 int main()
     33 {
     34     const char* s = "1234567890";
     35     test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), 10);
     36     test(forward_iterator<const char*>(s), forward_iterator<const char*>(s+10), 10);
     37     test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+10), 10);
     38     test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+10), 10);
     39     test(s, s+10, 10);
     40 }
     41