From 4848794359651336837
X-Google-Thread: f78e5,f1baa317914feeaf
X-Google-Attributes: gidf78e5,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news2.google.com!newsfeed.stanford.edu!news.kjsl.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Giovanni Deretta <gpderetta@gmail.com>
Newsgroups: comp.std.c++
Subject: Re: typeof keyword
Date: Tue, 31 Mar 2009 13:08:31 CST
Organization: http://groups.google.com
Lines: 51
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <14daa26d-67ff-459b-b16b-dab92e928afc@e38g2000yqa.googlegroups.com>
References: <488de3d4-77ac-4c01-8130-d196dec70bc8@v15g2000yqn.googlegroups.com>
  <gqdl38$gtu$1@news.mixmin.net>
  <d78092d1-73d4-4e20-b93a-9d1fb2849bb3@r15g2000vbi.googlegroups.com>
  <4c6295e4-2e8d-44e3-85cd-7e9eb9e72ce0@p11g2000yqe.googlegroups.com>
  <04297129-6b1b-479e-ab60-44eb7d288725@v38g2000yqb.googlegroups.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Mon, 30 Mar 2009 09:49:20 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:378

On Mar 29, 11:51 pm, goo...@dalvander.com wrote:
> On Mar 27, 11:40 pm, Giovanni Deretta <gpdere...@gmail.com> wrote:
>
> > auto x = /expression/;
>
> > will be equivalent to:
>
> > remove_reference<decltype(/expression/)>::type x = /expression/;
>
> Are you sure?

I haven't checked the exact wording, nor I know it there have been
recent changes, but I'm fairly sure that yes, that's the way auto
works.

It pretty much mimics function template argument deduction (and IIRC
it is specified in term of them).

>
> Let's say I have a class which is heavy to copy assign and copy
> construct: HeavyObject. And a function which returns a HeavyObject by
> const-reference:
> const HeavyObject& getHeavy(int howHeavy);
>
> And then do the following:
> auto heavy = getHeavy(42);
>
> The copy constructor will be called?

Yes.

>
> Do I need to use the following to prevent the copy constructor to be
> called?
> const auto& heavy = getHeavy(42);
>

Yes again.
Or make getHeavy return by value and rely on RVO. Or make the heavy
object movable.

--
gpd


-- 
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



