Can I resurect removed std::result_of in MSVC 16.6 with some macro?

Viewed 511

MSVC 16.6 in C++20 mode removes the result_of that was removed in C++20 standard. I am all for doing the morally correct thing, but many 3rd party libraries(example) I use fail.

Sometimes MSVC enables users to define a define so that removed features are still enabled. Is there an option to do that for result_of? I have tried _HAS_FEATURES_REMOVED_IN_CXX20 and it seems to work, but the fact that macro starts with _ scares me, it suggests it may be internal MSVC mechanism and not something users should set.

1 Answers

Defining _HAS_DEPRECATED_RESULT_OF and _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING should more granularly restore result_of and turn off its deprecation warning.

_HAS_FEATURES_REMOVED_IN_CXX20 and _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS should do the same for all C++17 features retired in C++20.

Given past history, these "deprecation overrides" should be relatively safe to use now and for some time coming. Below is an older quote (about VS 2017) from an MS sanctioned blog.

5. (Important!) It’s very likely that you’ll encounter source breaking changes in third-party libraries that you can’t modify (easily or at all). We try to provide escape hatches so you can restore removed features or silence deprecation warnings and get on with your work, but first, please report such issues to the relevant library maintainers. By helping them update their code, you’ll help many more C++ programmers just like you.

Related