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 (97) [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