Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
template <typename T>
struct f_pair { T x; T y; };
template <typename T>
inline f_pair<T> make_square_pair(T x)
{
return f_pair<T>{ x, x * x };
}
template <typename T>
inline T get_y(const f_pair<T>& p)
{
return p.y;
}
#include <iostream>
#include <typeinfo>
template <typename T>
void display(T x)
{
T y = get_y(make_square_pair(x));
std::cout << y << " -> "<< (typeid(y).name()) << "\n";
}
...
display(2); //4 -> int
display(2.71828); //7.38905 -> double
display(std::string("...")); //...... -> class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment