1 | #include <boost/concept/requires.hpp>
|
---|
2 | #include <boost/concept_check.hpp>
|
---|
3 | #include <vector>
|
---|
4 |
|
---|
5 | // (1) Forward declaration with concepts.
|
---|
6 | template<class Iter, class T>
|
---|
7 | BOOST_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.
|
---|
13 | template<class Iter, class T>
|
---|
14 | BOOST_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 |
|
---|
24 | int 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 | }
|
---|