Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10321
| From | Lucien Coffe <lcof@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: C++11 lambdas |
| Date | 2011-09-20 06:38 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <j59cd5$tvl$1@speranza.aioe.org> (permalink) |
| References | <835cd0b9-b3e1-4aa2-bf61-f71760b8fb04@fi7g2000vbb.googlegroups.com> |
Jerry wrote :
> This works fine:
>
> int main()
> {
> std::map<std::string,std::string> parameters;
>
> parameters["abc"]="def";
>
> std::for_each(parameters.begin(),parameters.end(),
> [] (std::map<std::string,std::string>::value_type& pair)
> {std::cout << pair.first << "=" << pair.second << " ";});
>
> return 0;
> }
>
> But g++ 4.6.0 doesn't like it when I change the type of pair in the
> lambda to auto:
>
> int main()
> {
> std::map<std::string,std::string> parameters;
>
> parameters["abc"]="def";
>
> std::for_each(parameters.begin(),parameters.end(),
> [] (auto pair)
> {std::cout << pair.first << "=" << pair.second << " ";});
>
> return 0;
> }
>
> So, my question is: why can't it be auto?
>
> In general I am most interested in why the committee chooses to include
> things or not and I figure there must be a reason this isn't allowed.
> Or is it allowed and my compiler is just too old?
>
> Thanks,
>
> Jerry
Auto knows its type from its initializer. Here there are no initializer.
It is used for *convenience*. I may be wrong, but I think this is not
possible because of this.
Here is an example of why : http://ideone.com/pP5jz
/error: parameter declared 'auto'/
--
perl -e 's;;{]``*%)}`_^[&)/#%(`&;;\
y;%^)([]/*#&`_{};.\100acghiklmopsz;;print'
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C++11 lambdas Jerry <jerry.jeremiah@gmail.com> - 2011-09-19 15:40 -0700
Re: C++11 lambdas Lucien Coffe <lcof@nospam.invalid> - 2011-09-20 06:38 +0000
Re: C++11 lambdas Juha Nieminen <nospam@thanks.invalid> - 2011-09-20 06:41 +0000
Re: C++11 lambdas Miles Bader <miles@gnu.org> - 2011-09-20 16:57 +0900
Re: C++11 lambdas Noah Roberts <roberts.noah@gmail.com> - 2011-09-20 08:23 -0700
Re: C++11 lambdas Juha Nieminen <nospam@thanks.invalid> - 2011-09-21 07:14 +0000
Re: C++11 lambdas Victor Bazarov <v.bazarov@comcast.invalid> - 2011-09-21 18:25 -0400
Re: C++11 lambdas ChuanQi Tan <chuanqi.tan@gmail.com> - 2011-10-04 22:04 -0700
Re: C++11 lambdas Jerry <jerry.jeremiah@gmail.com> - 2011-10-23 15:21 -0700
Re: C++11 lambdas Miles Bader <miles@gnu.org> - 2011-10-24 17:27 +0900
csiph-web