blob: a32b79d980d8697b5311ce934a617e5a87e6612e [file] [log] [blame]
Brian Silverman50051a92018-08-04 20:43:41 -07001// (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 <iterator>
9#include <list>
10#include <deque>
11#include <boost/static_assert.hpp>
12#include <boost/type_traits.hpp>
13
14template <class RandomAccessIterator >
15RandomAccessIterator 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
26int 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