Last active
August 29, 2015 14:18
-
-
Save Fiona-J-W/5ffb6ebce7862f5ee1b0 to your computer and use it in GitHub Desktop.
Resolving overloaded functions as described here: http://florianjw.de/en/passing_overloaded_functions.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Resolves overloaded functions when passing them to | |
* function-templates. | |
* | |
* Example: | |
* std::transform(vec1.begin(), vec1.end(), vec2.begin(), std::back_inserter(vec3), | |
* std::max); // ERROR: cannot infer template-argument | |
* | |
* std::transform(vec1.begin(), vec1.end(), vec2.begin(), std::back_inserter(vec3), | |
* UTIL_RESOLVE(std::max)); // Works. | |
* | |
* Requires: C++14, will hopefully become unneeded in C++17 | |
* Description: http://florianjw.de/en/passing_overloaded_functions.html | |
* Author: Florian Weber (florianjw.de) | |
* License: Public Domain or similar if not legally possible | |
*/ | |
#define UTIL_RESOLVE(...) \ | |
[](auto&&...args)->decltype(auto){return __VA_ARGS__(std::forward<decltype(args)>(args)...);} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment