Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost FFT Example - error on compile, what is this code doing?

Tags:

c++

boost

fft

I'm following the example at the following link:

https://www.boost.org/doc/libs/1_55_0/libs/math/doc/html/math_toolkit/high_precision/use_multiprecision.html

I get an error on the following line:

[&n](cpp_dec_float_50& y)


g++ -I ../boost_1_71_0 fft.cpp -o fft
fft.cpp:52:3: error: expected expression
  [&n](cpp_dec_float_50& y)
  ^
1 error generated.

The full block is:

// Generate the sine values.
std::for_each
(
  sin_values.begin (),
  sin_values.end (),
  [&n](cpp_dec_float_50& y)
  {
    y = sin( pi<cpp_dec_float_50>() / pow(cpp_dec_float_50 (2), n));
    ++n;
  }
);

What is "[&n](cpp_dec_float_50& y)" actually doing? And why is it erroring?

like image 314
Joe Avatar asked Dec 06 '25 19:12

Joe


1 Answers

What is [&n](cpp_dec_float_50& y) actually doing?

It's the first part of a lambda expression, i.e. an anonymous function.

And why is it erroring?

You need to compile for C++11 (or higher). Use -std=c++11 (or -std=c++14 or -std=c++17) in your compiler command line. eg:

g++ -std=c++11 ...
like image 140
Paul Evans Avatar answered Dec 08 '25 11:12

Paul Evans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!