PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/static_assert/static_assert_example_2.cpp

http://hadesmem.googlecode.com/
C++ | 40 lines | 19 code | 11 blank | 10 comment | 0 complexity | bcf95ca5f992546ad66368994ad91975 MD5 | raw file
 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 <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