The following compiles in Visual Studio 2017 with the MSVC compiler, but fails to 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 make use of enable_if like so:
#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 introducing a user type instead of a bool (this is what you will need to do in the case of a constructor having the 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 issue I'm having here is that I have a non-trivial sized game project and am trying to compile in Xcode for iOS. As far as I can tell I cannot get the same behaviour Visual Studio exhibits across all compilers (this would be nice). So as a result I am trying to edit my project to make it more conformant to the standard.
In an effort to do this in Visual Studio since it is my primary work environment I would like to know which non-standard extension is being used and how to disable it if at all possible. I can attempt to do this in Xcode, but for this particular problem I've found quite a few ambiguity issues and it only gives me a handful at a time.
As an additional curiosity I'm wondering if this ambiguous case has any standard proposal to address it or if Visual Studio is just going completely rogue in this case.