Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: Trying to compile std::plus

From: Jacob Smith (jaroslov_at_[hidden])
Date: 2008-10-08 11:51:27


I don't know exactly what you're looking for, but this compiles on checkout
681 (Alpha 7):

#include <concepts>
#include <functional>

namespace math
{

 template<typename T >
   requires std::CopyConstructible<T> // justifies return by-value
     && std::ReferentType<T> // you required this
     && std::HasPlus<T,T> // justifies "+" operation in body
     && std::Convertible<std::HasPlus<T, T>::result_type, T> // justifies
the result's type
 struct plus// : binary_function<T,T,T>
 /* inheriting from a class that is parametrized, where at least one
template
    argument is instantiated with "T" causes a segfault; you should probably
    find a minimal test-case and report this to the tracker:
    http://svn.osl.iu.edu/trac/conceptgcc/wiki */
 {
   typedef T result_type;
   typedef T first_argument_type;
   typedef T second_argument_type;
   T operator () ( T const & x, T const & y ) const
   { return x + y; }
 };

} // namespace math

-j.

On Wed, Oct 8, 2008 at 9:17 AM, Walter E Brown <wb_at_[hidden]> wrote:

> 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
>
>
>
> _______________________________________________
> ConceptGCC mailing list
> ConceptGCC_at_[hidden]
> http://www.osl.iu.edu/mailman/listinfo.cgi/conceptgcc
>