From -2483526026875354041
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!news.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Pavel Minaev <int19h@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: 34
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <7252ad7a-a2e2-49a3-a758-cc7015e564bb@x1g2000prh.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 10:54:47 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:377

On Mar 29, 2:51 pm, goo...@dalvander.com wrote:
> 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.

The very simple rule of thumb is that "auto" works the same way as
template argument deduction works (in fact, the draft standard says as
much about auto: "Once the type of a declarator-id has been determined
according to 8.3, the type of the declared variable using the
declarator-id is determined from the type of its initializer using the
rules for template argument deduction.").



-- 
[ 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                      ]



