Better HN
topnewbestaskshowjobs
Log inSign up

ljrmorgan

1 karma · joined Jul 16, 2014 (12y ago) · 1 submissions

Submissions

comment 8y ago · link · parent

This is not really the same though, because the Rust version compiles after the bounds have been added:

  use std::fmt::Display;

  fn f<T: Display>(s: T) {
    println!("{}", s);
  }

  fn main() {
    f(7);
  }
whereas there would be no way to get `f(7)` to compile in your C++ version since you can't make `int` inherit from `Display`. _A_ downside is that the library author has to add these sorts of checks, but for me a bigger downside is that anyone who then wants to use the library has to inherit from the library's types.