I've been playing around with Template Argument Deduction with C++17 (and onwards), and was trying to compile this exact sample from cppreference.com
#include <functional>
int func(double) { return 0; }
int main() {
std::function f{func}; // guide #1 deduces function<int(double)>
int i = 5;
std::function g = [&](double) { return i; }; // guide #2 deduces function<int(double)>
}
It compiles and runs fine in their web based compiler they have on that page, but when I try and compile this on my Macbook Pro, it fails, saying
error: no viable constructor or deduction guide for deduction of template arguments of 'function'
I've tried it both in an Xcode (v10.1) project set to C++17, and just running clang directly with -std=c++17.
I've also compiled the above example on different online compilers, such as here: https://godbolt.org/z/ERliha
I've also verified that type deductions for std::pair work, so I can't tell if:
- I screwed up my toolchains somehow when I was messing with cross compilers.
- Deduction Guides for this class are missing in Apple's Toolchain.
- I'm running an old toolchain (I don't know how to check this)
- ... (Any other reason)