Boost logo

Boost :

From: Bruno Lalande (bruno.lalande_at_[hidden])
Date: 2008-07-21 17:48:21


Hello,

Barend and I have been facing a problem while integrating concept
checks into the Geometry Library. In order to simplify the problem, I
reduced it to a very simple test case:

template <typename T>
struct foo
{};

template <class X>
struct DummyConcept
{
    typedef typename X::something something;
};

template<typename T>
BOOST_CONCEPT_REQUIRES(((DummyConcept<T>)),
(void)) func(T&)
{ std::cout << "first overload" << std::endl; }

template<typename T>
void func(foo<T>)
{ std::cout << "second overload" << std::endl; }

int main()
{
    func(foo<int>());
    return 0;
}

This code doesn't compile because the compiler tries to check foo<int>
against the DummyConcept, even though it's supposed to select the
second overload, which doesn't carry any concept requirement. Removing
the check makes it compile and a run displays "second overload". If I
put back the check and add a "typedef void something" into foo, it
compiles and displays the same thing.

So I deduce that, more generally, a compiler compiles the return type
of every candidate overload before selecting the right one, and that's
why we have this issue with concept checking. So I have 2 questions:
- would there be any way to differ the check until after the right
overload has been selected, thus doing the check only for that
overload?
- if no, is there a better workaround than replacing
BOOST_CONCEPT_REQUIRES by a simple BOOST_ASSERT inside the function?

Thanks in advance.

Bruno


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