[ConceptGCC] |
ConceptGCC :Re: Trying to compile std::plus |
From: Walter E Brown (wb_at_[hidden])
Date: 2008-10-08 10:17:22
On 2008-10-07 11:04 AM, Sebastian Gesemann wrote:
> On Mon, Oct 6, 2008 at 9:38 PM, Walter E Brown <wb_at_[hidden]> wrote:
>> The enclosed file represents my attempt to compile the constrained version
>> of std::plus<> using conceptg++ (GCC) 4.3.0 20070330 (experimental) (Indiana
>> University ConceptGCC Alpha 7).
>
> A constrained template should look more like this:
>
> ----------8<----------
> #include <concepts>
> #include <functional>
>
> using namespace std;
>
> template<typename T>
> // requires ReferentType<T>
> // && HasPlus<T,T>
> // && Convertible<HasPlus<T,T>::result_type>,T>
> struct plus : public std::binary_function<T,T,T>
> {
> T operator() (const T & x, const T & y) const
> { return x + y; }
> };
> ----------8<----------
>
> The requires clause goes right under the "template<>". Unfortunately I
> can't get it to compile, either. I get the error:
>
> test.cpp:9: Error: expected template-id before »T«
> test.cpp:9: Error: expected unqualified-id before »>« token
>
> If I omit line 9 ("// && Convertible<...>") I get a segfault, too.
> (same ConceptGCC version)
Thank you for this feedback, but please see section
[arithmetic.operations] of N2798 (the latest Working Draft). You will
note there are intended to be 2 sets of constraints: one (ReferentType)
to apply to the class template, the other (HasPlus && Convertible) to
apply only to the member function. The above (changed) version would
slightly overconstrain the class template, unnecessarily impacting users
who may wish to specialize the template without using any operator+.
-- WEB