Instantly share code, notes, and snippets.

Embed
What would you like to do?
//use std::fmt;
#include <iostream>
//
//struct Foo {
// x: i32
//}
struct Foo {
int x;
};
// impl fmt::Display for Foo {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// write!(f, "(x: {})", self.x)
// }
//}
std::ostream& operator<<(std::ostream &o, const Foo &f) {
o << "(x: " << f.x << ')';
return o;
}
//struct Bar {
// x: i32,
// y: i32
//}
struct Bar {
int x;
int y;
};
//impl fmt::Display for Bar {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// write!(f, "(x: {}, y: {})", self.x, self.y)
// }
//}
std::ostream& operator<<(std::ostream &o, const Bar &b) {
o << "(x: " << b.x << ", y: " << b.y << ')';
return o;
}
// fn print_me<T: fmt::Display>(obj : T) {
// println!("Value: {}", obj)
//}
template<typename T>
void print_me(const T &t) {
std::cout << t << '\n';
}
//fn main() {
// let foo = Foo {x: 7};
// let bar = Bar {x: 5, y: 10};
// print_me(foo);
// print_me(bar);
//}
int main()
{
auto foo = Foo { 7 };
auto bar = Bar { 5, 10 };
print_me(foo);
print_me(bar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment