#include <iostream> #include <type_traits> void g(int&) { std::cout << 'L'; } void g(int&&) { std::cout << 'R'; } template<typename T> void f(T&& t) { if (std::is_same_v<T, int>) { std::cout << 1; } if (std::is_same_v<T, int&>) { std::cout << 2; } if (std::is_same_v<T, int&&>) { std::cout << 3; } g(std::forward<T>(t)); } int main() { f(42); int i = 0; f(i); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter