Last active
September 18, 2019 19:46
-
-
Save sophiajt/a182347b763398d8ea4f to your computer and use it in GitHub Desktop.
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
//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