This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [lambda] Segmentation fault in simple lambda program
- From: Esben Mose Hansen <kde at mosehansen dot dk>
- To: "Smith-Rowland, Edward M" <ESmith-rowland at alionscience dot com>, gcc at gcc dot gnu dot org
- Date: Thu, 30 Apr 2009 21:31:49 +0200
- Subject: Re: [lambda] Segmentation fault in simple lambda program
- References: <B3F9ED7D12B9F144B983DC5C486FD61D1B4A85@email4a.alionscience.com>
On Thursday 30 April 2009 19:19:31 you wrote:
> When I try to specify the capture it works ((&sum, &f) works too but f is
> const):
>
> #include <algorithm>
>
> int
> main(void)
> {
> int numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
> const std::size_t nn = sizeof(numbers)/sizeof(int);
> int sum = 0;
> int f = 5;
>
> //std::for_each(&numbers[0], &numbers[nn], [&](int n) { sum += n * f; });
>
> std::for_each(&numbers[0], &numbers[nn], [&sum, f](int n) { sum += n * f;
> });
>
> return 0;
> }
Yup. In fact, almost any other capture block than the [&] works :) I will try
to look at those tree options when I get sober again.
--
Kind regards, Esben