Boost logo

Boost :

Subject: Re: [boost] [concept] forward declarations and `BOOST_CONCEPT_REQUIRES()`
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-08-10 16:05:30


On Mon, Aug 9, 2010 at 10:00 PM, Dave Abrahams <dave_at_[hidden]> wrote:
> On Mon, Aug 9, 2010 at 1:03 PM, Lorenzo Caminiti <lorcaminiti_at_[hidden]> wrote:
>> Hello all,
>>
>> Can I forward declare a function template that checks concepts using
>> `BOOST_CONCEPT_REQUIRES()`?
>>
>> In the following example, MSVC gives me an ambiguous call error when I
>> try to do that... (I have not yet tried other compilers).
>>
>>    c00.cpp(28) : error C2668: 'all_equals' : ambiguous call to
>> overloaded function
>>            c00.cpp(18): could be 'bool
>> all_equals<std::_Vector_iterator<_Ty,_Alloc>,double>(Iter,Iter,const T
>> &)'
>>            with
>>            [
>>                _Ty=double,
>>                _Alloc=std::allocator<double>,
>>                Iter=std::_Vector_iterator<double,std::allocator<double>>,
>>                T=double
>>            ]
>>            c00.cpp(11): or 'bool
>> all_equals<std::_Vector_iterator<_Ty,_Alloc>,double>(Iter,Iter,const T
>> &)'
>>            with
>>            [
>>                _Ty=double,
>>                _Alloc=std::allocator<double>,
>>                Iter=std::_Vector_iterator<double,std::allocator<double>>,
>>                T=double
>>            ]
>>            while trying to match the argument list
>> '(std::_Vector_iterator<_Ty,_Alloc>,
>> std::_Vector_iterator<_Ty,_Alloc>, double)'
>>            with
>>            [
>>                _Ty=double,
>>                _Alloc=std::allocator<double>
>>            ]
>>
>> Thank you very much.
>
> Just from looking at the error message this would seem to be a
> cut-and-dried case of bugs in the compiler.  The "overloads" it is
> saying are ambiguous are identical, meaning they're really just one
> thing.

Yes, I noticed the same thing. I cannot try the code on other
compilers at the moment, it would be great if anyone from this mailing
list could do that and let me know...

Even assuming this is a MSVC bug, is there a workaround for it?

I have been thinking to do the following:

    // (1) Forward declaration without concepts.
    template<class Iter, class T>
    bool all_equals(Iter first, Iter last, const T& val);

    // (2) Actual definition with concepts.
    template<class Iter, class T>
        BOOST_CONCEPT_REQUIRES(
            ((boost::ForwardIterator<Iter>)) ((boost::EqualityComparable<T>))
        ,
    (bool) ) all_equals(Iter first, Iter last, const T& val) {
        ... // Implementation.
    }

But I do not think this will work because the first declaration is not
guarded by the concepts so it will only generate a linker-time error
"missing definition" if the T does not satisfy the concepts
(correct?). However, I do not really understand the
Boost.ConceptCheck/EnableIf machinery so there might be a way around
this issue.

Thank you again.

-- 
Lorenzo

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk