Hacker News new | past | comments | ask | show | jobs | submit login

I remember a university project where I used the >> (and <<) operators to "send" data between services.

The code was a simulation of a parallel system with multiple services that sent messages between them, or something like that. Instead of using serviceA.send("hello",serviceB) you had something like serviceA >> "hello" >> serviceB.

I really loved that (my classmates not so much)




Reminds me of the ChucK operator.

  SinOsc b => Gain g => BiQuad f => dac;
https://chuck.stanford.edu/doc/language/oper.html#chuck


I did something similar as a student, making my own exception class with std::ostream:

throw exceptionC() << "error code: " << t;

I often found myself having to format error strings for exceptions, so I thought I could just do it like cout in one line. I know now this is bad for i18n strings.



Why would you prefer that over:

  throw exceptionC("error code: ", t);
?

Ever since perfect forwarding I've been using this pattern to get out of arrow hell:

  template <typename Arg, typename...Args>
  string to_string(Arg &&arg, Args &&...args) {
    stringstream buf;
    buf << arg;
    ((buf << std::forward<Args>(args)), ...);
    return buf.str();
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: