• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright John Maddock 2000.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 //  See http://www.boost.org for most recent version including documentation.
7 
8 #include <boost/static_assert.hpp>
9 #include <boost/type_traits.hpp>
10 #include <iterator>
11 #include <list>
12 #include <deque>
13 
14 template <class RandomAccessIterator >
foo(RandomAccessIterator from,RandomAccessIterator)15 RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator /*to*/)
16 {
17    // this template can only be used with
18    // random access iterators...
19    typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat;
20    BOOST_STATIC_ASSERT((boost::is_convertible<cat, const std::random_access_iterator_tag&>::value));
21    //
22    // detail goes here...
23    return from;
24 }
25 
main()26 int main()
27 {
28    std::deque<int> d;
29    std::list<int> l;
30    foo(d.begin(), d.end()); // OK
31    //foo(l.begin(), l.end()); // error
32    return 0;
33 }
34 
35 
36 
37 
38 
39 
40 
41