The following compilations in Visual Studio 2017 with the MSVC compiler, but do not compile in GCC or Clang.
#include <iostream>
#include <functional>
void functionTest(std::function<void()>) {
std::cout << "F\n";
}
void functionTest(bool) {
std::cout << "B\n";
}
int main() {
functionTest([](){ std::cout << "wut"; });
}
To fix this, we can use enable_f like this:
#include <iostream>
#include <functional>
void functionTest(std::function<void()>) {
std::cout << "F\n";
}
template<typename BOOL_TYPE, typename = typename std::enable_if<std::is_same<bool, BOOL_TYPE>::value>::type>
void functionTest(BOOL_TYPE) {
std::cout << "B\n";
}
int main() {
functionTest([](){ std::cout << "wut"; });
}
Or I can disambiguate by entering the user type instead of bool (this is what you will need to do in the case of a constructor that has an ambiguity problem):
#include <iostream>
#include <functional>
void functionTest(std::function<void()>) {
std::cout << "F\n";
}
enum class DescriptiveTypeName {False, True};
void functionTest(DescriptiveTypeName) {
std::cout << "B\n";
}
int main() {
functionTest([](){ std::cout << "wut"; });
}
The problem I am encountering here is that I have a non-trivial game project and am trying to compile Xcode for iOS. As far as I can tell, I can't get the same behavior as Visual Studio for all compilers (this would be nice). Therefore, as a result, I try to change my project so that it becomes more consistent with the standard.
Visual Studio, , , , . Xcode, , .
, - Visual Studio .