Comment

Comment by phorese

If I just want to unpack a function's tuple result, I use "std::tie":

  tuple<int, bool, char> t = make_tuple(1, true, 'a');
  int  n = get<0>(t);
  bool b = get<1>(t);
  char c = get<2>(t);
can be written as

  int  n;
  bool b;
  char c;
  std::tie(n,b,c) = make_tuple(1, true, 'a');
This is not necessarily better or more dynamic, but at least it looks more pythonic (to me). One can even write

  std::tie(n,b,std::ignore) = make_tuple(1, true, 'a');
if not all results are needed!
parent phorese 10 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton