Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/static_assert/static_assert_test_fail_8.cpp @ 33

Last change on this file since 33 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.2 KB
Line 
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)
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*, std::random_access_iterator_tag*>::value));
21   //
22   // detail goes here...
23   return from;
24}
25
26// ensure that delayed instantiation compilers like Comeau see the failure early
27// enough for "compile-fail" testing with the Boost.Build testing framework. (Greg Comeau)
28template
29std::list<int>::iterator
30   foo(std::list<int>::iterator, std::list<int>::iterator);
31
32int main()
33{
34   std::deque<int> d;
35   std::list<int> l;
36   foo(d.begin(), d.end()); // OK
37   foo(l.begin(), l.end()); // error
38   return 0;
39}
40
41
42 
43
44
Note: See TracBrowser for help on using the repository browser.