0

Also same question for variant, array.

A related question answerd why it use compile-time parameter, but not why not design its api as a member function.(Why are C++ tuples so weird?)

tuple.get<int>() looks more semantic than std::get<int>( some_tuple )

  • 3
    "looks more semantic" what does that mean? – 463035818_is_not_an_ai Jul 10 '23 at 13:01
  • 5
    `std::get` can be used on any tuple-like type in the standard library, like `std::array`, `std::pair`, `std::variant`. – Ted Lyngmo Jul 10 '23 at 13:01
  • 1
    not everything must be a member. Every thing that can be a non-member makes the types more simple and easier to use. What would be the benefit of making it a member of many different types rather than 1 template that works for all types? – 463035818_is_not_an_ai Jul 10 '23 at 13:04
  • your only argument is that a member function would be "better", but they are not, actually the common recommendation in C++ says something else. See https://stackoverflow.com/a/21028902/4117728 and https://isocpp.org/blog/2018/02/free-your-functions-klaus-iglberger and else where... – 463035818_is_not_an_ai Jul 10 '23 at 13:06
  • To me, a good reason to prefer member functions to free functions is that IDE can much better autocomplete member functions, as the context is known. – prapin Jul 10 '23 at 13:54

0 Answers0