This file contains 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
template <typename T> | |
using AsFunction = decltype(std::function{std::declval<T>()}); | |
#if defined(__GNUC__) || defined(__GNUG__) | |
// CTAD bug in gcc, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98077 | |
#define AS_FUNCTION(T) decltype(std::function{std::declval<T>()}) | |
#else | |
#define AS_FUNCTION(T) AsFunction<T> | |
#endif |
This file contains 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
auto foo(int n, std::string s) | |
{ | |
// ... calculate something expensive(like the answer to everything) | |
return 42; | |
} | |
auto fooM(int n, std::string s) | |
{ | |
// what goes in here? | |
} |
This file contains 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
auto nameByShirtNo = std::map<int, std::string>{{8, "Andres Iniesta"}}; | |
const auto shirtNumber = 8; | |
const auto nameExists = nameByShirtNo.contains(shirtNumber); | |
if (nameExists) | |
{ | |
const auto playerName = nameByShirtNo.at(shirtNumber); | |
std::cout << playerName << " wears shirt number " << shirtNumber; | |
} | |
else |