std::max: if versus ?:

Marc Glisse marc.glisse@inria.fr
Sun Sep 23 17:06:00 GMT 2012


On Sun, 23 Sep 2012, Gabriel Dos Reis wrote:

> On Sun, Sep 23, 2012 at 10:09 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>
>> Then that may mean no std::max for vectors, at least until someone makes the
>> inner type and size of vectors deducible (that would make the vector version
>> of max more specialized than the generic one and allow overloads without
>> touching the generic function). Which isn't that bad, people are big enough
>> to write (x<y)?y:x themselves...
>
> I do not understand why you can't have a syntax such as  __vector<T,N>
> those extensions.   If that syntax isn't there, you should consider adding
> it.  It is a natural thing to have.

The syntax exists (though it is ugly): T __attribute__((vector_size(N))).

What doesn't work currently is that T and N are not deducible, in a 
template context. One possibility would be to make them deducible (sounds 
like duplicating a bit of template machinery). Another one would be to 
have a regular template class (like your vector), which would thus use the 
regular template machinery, but the compiler would know that it really is 
a vector. The second version gets away from what C does, it may not match 
very well with some concepts like opaque vectors, etc.

I am open to various possibilities, if you precise a bit what you have in 
mind.

-- 
Marc Glisse



More information about the Libstdc++ mailing list