public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [cxx-conversion] is enable_if ok?
@ 2012-04-14 19:54 Pedro Lamarão
  2012-04-14 20:07 ` Jonathan Wakely
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pedro Lamarão @ 2012-04-14 19:54 UTC (permalink / raw)
  To: gcc

Hello,

currently proposed C++ Coding Conventions imply a very strict 
weird-is-forbidden style, which I like.

But if defining new templates should in general be avoided, I'm unsure 
what is the best path in converting VEC.

VEC interface optimizes element acessors to copy primitive types and 
point-to object types.

If VEC is to be a template class, default accessors in C++ would 
naturally return a (const-)reference-to anything. It would be possible 
to optimize accessors to return a copy instead of a const-reference-to 
with enable_if. All this would allow VEC to be mostly just one thing, 
with small variations in corresponding to VEC_last and VEC_index.

Since enable_if is not part of C++98, it would be added to GCC itself -- 
perhaps in namespace gcc.

This decision will not block work in the branch, of course -- VEC can be 
converted first unoptimized and then reoptimized with whatever tricks 
are allowed.

--
  P.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [cxx-conversion] is enable_if ok?
  2012-04-14 19:54 [cxx-conversion] is enable_if ok? Pedro Lamarão
@ 2012-04-14 20:07 ` Jonathan Wakely
  2012-04-14 20:13   ` Pedro Lamarão
  2012-04-14 20:41 ` Marc Glisse
  2012-04-14 21:26 ` Gabriel Dos Reis
  2 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2012-04-14 20:07 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On 14 April 2012 20:55, Pedro Lamarão wrote:
> Since enable_if is not part of C++98, it would be added to GCC itself --
> perhaps in namespace gcc.

libstdc++ provides __gnu_cxx::__enable_if in <ext/type_traits.h:>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [cxx-conversion] is enable_if ok?
  2012-04-14 20:07 ` Jonathan Wakely
@ 2012-04-14 20:13   ` Pedro Lamarão
  2012-04-14 20:19     ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Pedro Lamarão @ 2012-04-14 20:13 UTC (permalink / raw)
  To: gcc

On 04/14/2012 05:07 PM, Jonathan Wakely wrote:
> On 14 April 2012 20:55, Pedro Lamarão wrote:
>> Since enable_if is not part of C++98, it would be added to GCC itself --
>> perhaps in namespace gcc.
>
> libstdc++ provides __gnu_cxx::__enable_if in<ext/type_traits.h:>
>

When vec.h is compiled in stage1 by the host compiler, can we include 
the file you mention?

Or perhaps the suggestion is to optimize with enable_if only after stage1?

--
  P.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [cxx-conversion] is enable_if ok?
  2012-04-14 20:13   ` Pedro Lamarão
@ 2012-04-14 20:19     ` Jonathan Wakely
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2012-04-14 20:19 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On 14 April 2012 21:14, Pedro Lamarão wrote:
> On 04/14/2012 05:07 PM, Jonathan Wakely wrote:
>>
>> On 14 April 2012 20:55, Pedro Lamarão wrote:
>>>
>>> Since enable_if is not part of C++98, it would be added to GCC itself --
>>> perhaps in namespace gcc.
>>
>>
>> libstdc++ provides __gnu_cxx::__enable_if in<ext/type_traits.h:>
>>
>
> When vec.h is compiled in stage1 by the host compiler, can we include the
> file you mention?

I don't know, my point is just that GCC already contains an enable_if
that works in C++03 mode, in addition to std::enable_if, so reusing it
somehow would make more sense than adding a third implementation.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [cxx-conversion] is enable_if ok?
  2012-04-14 19:54 [cxx-conversion] is enable_if ok? Pedro Lamarão
  2012-04-14 20:07 ` Jonathan Wakely
@ 2012-04-14 20:41 ` Marc Glisse
  2012-04-14 21:26 ` Gabriel Dos Reis
  2 siblings, 0 replies; 7+ messages in thread
From: Marc Glisse @ 2012-04-14 20:41 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On Sat, 14 Apr 2012, Pedro Lamarão wrote:

> Hello,
>
> currently proposed C++ Coding Conventions imply a very strict 
> weird-is-forbidden style, which I like.
>
> But if defining new templates should in general be avoided, I'm unsure what 
> is the best path in converting VEC.
>
> VEC interface optimizes element acessors to copy primitive types and point-to 
> object types.
>
> If VEC is to be a template class, default accessors in C++ would naturally 
> return a (const-)reference-to anything. It would be possible to optimize 
> accessors to return a copy instead of a const-reference-to with enable_if. 
> All this would allow VEC to be mostly just one thing, with small variations 
> in corresponding to VEC_last and VEC_index.

Do you seriously expect it to make a difference? Accessors should be 
inlined to the point of making the value/reference thing irrelevant. If 
std::vector suffers a performance penalty because of this, it is a serious 
optimizer deficiency that should be fixed so all C++ users can benefit.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [cxx-conversion] is enable_if ok?
  2012-04-14 19:54 [cxx-conversion] is enable_if ok? Pedro Lamarão
  2012-04-14 20:07 ` Jonathan Wakely
  2012-04-14 20:41 ` Marc Glisse
@ 2012-04-14 21:26 ` Gabriel Dos Reis
  2012-04-15  1:44   ` Lawrence Crowl
  2 siblings, 1 reply; 7+ messages in thread
From: Gabriel Dos Reis @ 2012-04-14 21:26 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On Sat, Apr 14, 2012 at 2:55 PM, Pedro Lamarão <pedro.lamarao@gmail.com> wrote:
> Hello,
>
> currently proposed C++ Coding Conventions imply a very strict
> weird-is-forbidden style, which I like.
>
> But if defining new templates should in general be avoided, I'm unsure what
> is the best path in converting VEC.
>
> VEC interface optimizes element acessors to copy primitive types and
> point-to object types.
>
> If VEC is to be a template class, default accessors in C++ would naturally
> return a (const-)reference-to anything. It would be possible to optimize
> accessors to return a copy instead of a const-reference-to with enable_if.
> All this would allow VEC to be mostly just one thing, with small variations
> in corresponding to VEC_last and VEC_index.
>
> Since enable_if is not part of C++98, it would be added to GCC itself --
> perhaps in namespace gcc.
>
> This decision will not block work in the branch, of course -- VEC can be
> converted first unoptimized and then reoptimized with whatever tricks are
> allowed.

One of the requirements is that the code should bootstrap with any
C++03 compiler.
Another requirement is to keep template usage simple.  Those two
requirements to me
mean avoid enable_if.  Of course, maintainers will exercise judgment
on specific cases,
 but as a general guideline, I would suggest to forget them.

-- Gaby

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [cxx-conversion] is enable_if ok?
  2012-04-14 21:26 ` Gabriel Dos Reis
@ 2012-04-15  1:44   ` Lawrence Crowl
  0 siblings, 0 replies; 7+ messages in thread
From: Lawrence Crowl @ 2012-04-15  1:44 UTC (permalink / raw)
  To: Gabriel Dos Reis; +Cc: Pedro Lamarão, gcc

On 4/14/12, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> On Apr 14, 2012 Pedro Lamarão <pedro.lamarao@gmail.com> wrote:
> > currently proposed C++ Coding Conventions imply a very strict
> > weird-is-forbidden style, which I like.
> >
> > But if defining new templates should in general be avoided,
> > I'm unsure what is the best path in converting VEC.
> >
> > VEC interface optimizes element acessors to copy primitive
> > types and point-to object types.
> >
> > If VEC is to be a template class, default accessors in C++ would
> > naturally return a (const-)reference-to anything. It would be
> > possible to optimize accessors to return a copy instead of a
> > const-reference-to with enable_if.  All this would allow VEC to
> > be mostly just one thing, with small variations in corresponding
> > to VEC_last and VEC_index.
> >
> > Since enable_if is not part of C++98, it would be added to GCC
> > itself -- perhaps in namespace gcc.
> >
> > This decision will not block work in the branch, of course --
> > VEC can be converted first unoptimized and then reoptimized
> > with whatever tricks are allowed.
>
> One of the requirements is that the code should bootstrap with
> any C++03 compiler.  Another requirement is to keep template
> usage simple.  Those two requirements to me mean avoid enable_if.
> Of course, maintainers will exercise judgment on specific cases,
> but as a general guideline, I would suggest to forget them.

Implicit, I think, in Gabriel's statement is that if you really need
enable_if, and make a convincing case, you can get an exception to
the general rule.

To my mind, one of the advantages of enable_if is that customers do
not need to know about it.  It is an internal implementation issue,
and presumably authors using enable_if are comfortable with it.

-- 
Lawrence Crowl

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-04-15  1:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-14 19:54 [cxx-conversion] is enable_if ok? Pedro Lamarão
2012-04-14 20:07 ` Jonathan Wakely
2012-04-14 20:13   ` Pedro Lamarão
2012-04-14 20:19     ` Jonathan Wakely
2012-04-14 20:41 ` Marc Glisse
2012-04-14 21:26 ` Gabriel Dos Reis
2012-04-15  1:44   ` Lawrence Crowl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).