static_assert_test_fail_8.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // See http://www.boost.org for most recent version including documentation.
  6. #include <iterator>
  7. #include <list>
  8. #include <deque>
  9. #include <boost/static_assert.hpp>
  10. #include <boost/type_traits.hpp>
  11. template <class RandomAccessIterator >
  12. RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator)
  13. {
  14. // this template can only be used with
  15. // random access iterators...
  16. typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat;
  17. BOOST_STATIC_ASSERT((boost::is_convertible<cat*, std::random_access_iterator_tag*>::value));
  18. //
  19. // detail goes here...
  20. return from;
  21. }
  22. // ensure that delayed instantiation compilers like Comeau see the failure early
  23. // enough for "compile-fail" testing with the Boost.Build testing framework. (Greg Comeau)
  24. template
  25. std::list<int>::iterator
  26. foo(std::list<int>::iterator, std::list<int>::iterator);
  27. int main()
  28. {
  29. std::deque<int> d;
  30. std::list<int> l;
  31. foo(d.begin(), d.end()); // OK
  32. foo(l.begin(), l.end()); // error
  33. return 0;
  34. }