The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Diego Saraiva (4) [Avatar] Offline
#1
The code in Listing 3.22 and Listing 3.23 are used to explain how store different function objects in the std::function. But I found some issues on them.

First of all, the following code is ambiguous on clang/gcc compilers because we have two overloads functions defined at std.


std::function<float(float, float)> test_function;
test_function = std::fmax;

I believe that the correct code is the following:
test_function = std::fmaxf; // the fmaxf is defined to float only.

And the following code doesn't compile

std::string str { "A small pond" };
std::function<bool(std::string)> f;
f = &std::string::empty;
std::cout << f(str);

Is something missing here?

Best Regards

Diego



Ivan Cukic (104) [Avatar] Offline
#2
Yes, fmaxf is the best choice. Will be fixed before publishing. Thanks!

As for the second code snippet, I've had reports that clang/libc++ has problems to link it. What compiler are you using?

The code is correct, it is a bug in libc++ exported symbols.
Diego Saraiva (4) [Avatar] Offline
#3
Hi Ivan,

You're right. I'm using a libc++ compile-based. Currently, my C++ compiler is the following:

Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
OS: Mac OS X Sierra