Skip to content

Instantly share code, notes, and snippets.

@Fiona-J-W
Last active August 29, 2015 14:18
Show Gist options
  • Save Fiona-J-W/5ffb6ebce7862f5ee1b0 to your computer and use it in GitHub Desktop.
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
/**
* 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