Ticket #4526: broken.cpp

File broken.cpp, 810 bytes (added by Stefan van Kessel <van_kessel@…>, 12 years ago)

example code that breaks

Line 
1#include <boost/concept/requires.hpp>
2#include <boost/concept_check.hpp>
3#include <vector>
4
5// (1) Forward declaration with concepts.
6template<class Iter, class T>
7BOOST_CONCEPT_REQUIRES(
8 ((boost::ForwardIterator<Iter>)) ((boost::EqualityComparable<T>))
9 ,
10 (bool) ) all_equals(Iter first, Iter last, const T& val);
11
12// (2) Actual definition.
13template<class Iter, class T>
14BOOST_CONCEPT_REQUIRES(
15 ((boost::ForwardIterator<Iter>)) ((boost::EqualityComparable<T>))
16 ,
17 (bool) ) all_equals(Iter first, Iter last, const T& val) {
18 for (Iter i = first; i < last; ++i) {
19 if (*i != val) return false;
20 }
21 return true;
22}
23
24int main() {
25 std::vector<double> v;
26 // MSVC error: Cannot resolved ambiguous call between (1) and (2).
27 all_equals(v.begin(), v.end(), double());
28 return 0;
29}