From -6805407325937466424
X-Google-Thread: f78e5,2feb33bcd45033ce
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 20 Sep 2010 01:30:01 -0500
Return-Path: <cppmods@assassin.cs.rpi.edu>
X-Hash: SCt|e0341dae70905199d9c3d4443eb33310f92f38fb|05c1ff68428dd73191e972f83f937250
X-Countries: United States
X-SMTP-From: accepted <cppmods@assassin.cs.rpi.edu> assassin.cs.rpi.edu [128.113.126.17] (assassin.cs.rpi.edu) {United States}
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=date
	:to:sender:message-id:from:subject:references:content-type; s=
	default; i=128.113.126.17@cs.rpi.edu; t=1284964032; x=
	1285568832; l=1639; bh=NAt2mp0P759r22My48C/Dld9gZk=; b=XYXY2JLOh
	gPWEMUqA/hdwtZ8EM8ZhT66KUYw9ILnOvapw0ywUzzWtdhRwSVfvE5fvHqkHIxbZ
	rvi1hI5peYJWlL46TG8ndhRIQLEpf1cWOcP9eX54ReNLcm4FqtMKG3tRkXAaCidI
	S8Gz5A/j60GvVpMWA3PubsJGDbUIXdLSGE=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=date:to:sender
	:message-id:from:subject:references:content-type; q=dns; s=
	default; b=Bn9HcYFlFks7NfsPsrU1Zvkp+V7X4m3Q0R8lP6DsczYVLRsIQ7fJB
	4DiTDhs5Uu+wL7zd1IvK0n1p/iJa3qBUSLIpo4NKoDGBkUvFInmVG3kdj+ODXvLH
	5Y7gfZ/CJATJmnDCq2avzRHlB219LY1/e90sAtaRD549OY5PQYEuc0=
X-Spam-Report: Spam Report from cliffclavin.cs.rpi.edu (SA:3.2.5):
	-1.8 ALL_TRUSTED            Passed through trusted hosts only via SMTP
	3.4 HEADER_SPAM            Bulk email fingerprint (header-based) found
	-0.9 BAYES_00               BODY: Bayesian spam probability is 0 to 1% [score: 0.0000]
	0.2 SARE_HEAD_HDR_APPROV   Message headers used which identify spam
	0.0 AWL                    AWL: From: address is in the auto white-list
X-Spam-Info: 0.9, local;
	ALL_TRUSTED,AWL,BAYES_00,HEADER_SPAM,SARE_HEAD_HDR_APPROV
X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5
X-Virus-Scanned-By: cliffclavin.cs.rpi.edu
To: (Usenet)
Sender: std-c++-request@ruralroute.cs.rpi.edu
Approved: james.dennett@gmail.com 
Message-ID: <abf76bc3-7506-4b32-ad4f-0b775a2593da@a30g2000vbt.googlegroups.com>
Newsgroups: comp.std.c++
From: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Subject: Re: Bracket, equals, bracket? 
Organization: http://groups.google.com
References: <e8f25297-0146-45df-b2a3-c1307cac29dd@i17g2000vbq.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
X-Original-Date: Sun, 19 Sep 2010 22:53:19 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25
Date: Mon, 20 Sep 2010 01:27:12 CST
Lines: 49
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-E7fclZf8WIhmyab9IuZffRBDMDEgwpW38MG6aXjZwpl1GJ6EbrlBrLURRY3vANYYQEl8dZr0prOSOrg!ov6ohDfxVox2YSEypv7MdDXbglHsprpWnsxhSjYq3aYaspnfpYpwEzu8oO2DQdVtZhx9PkreqwyS!WVIVmRa0N13CDpzD78d0I/hXgfI=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Xref: g2news1.google.com comp.std.c++:3019

On Sep 20, 2:13 am, Duncan Smith <dsmith1...@gmail.com> wrote:
> In this months DDJ Herb Sutter writes some code like:
>
> class AsyncLogFile {
> public:
> void write( string str ) { a.Send( [=] { log.write( str ); } ); }
>
> My question is what does [=] mean, I thought square brackets were for
> indexing arrays unless maybe the operator[] is overloaded, but then a
> google codesearch shows other uses of [=], does it have a special or
> common meaning?

The meaning of [=] makes only sense in the whole context of a
so-called lambda-expression, which is a new expression form
in C++0x and defines a lambda-closure, which is a compiler-generated
class-type functor. The whole lambda-expression above is

[=] { log.write( str ); }

and defines a closure type which is - roughly said - constructed like
this:

struct __ {
 std::string s;
 __(const std::string& s) : s(s) {}
 void operator()() {
   log.write( str );
 }
};

assuming that log is a global-scope variable.

Such a closure *captures* local variables, and the = within
the [] defines the default-policy, how this is done. If this
is =, all local variables are captured by *copy* (i.e. the
string s was copied. The other alternative for the default
capture is "by-reference", where you use the token & instead
of = within the [] token.

HTH & Greetings from Bremen,

Daniel Kr�gler

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



