3

Possible Duplicate:
std::tuple get() member function

There seem to be separate overloads for std::get, for different homogeneous and heterogeneous containers such as for std::tuple.

This seems a bit awkward; The more obvious choice would be if there was an std::tuple::get() with one template parameter (the index). I'd be surprised if this choice was made on a whim, so I wonder why the standardisation committee would choose to make it a free function instead of a member function, despite the latter being a more natural interface.

Is there any good reason?

Community
  • 1
  • 1
bitmask
  • 32,434
  • 14
  • 99
  • 159
  • @JesseGood: Darn, I searched the heck out of this. I agree, it's a dupe. – bitmask Oct 16 '12 at 01:57
  • It should also be noted that, with free functions, you can provide overloads *without* changing the definition of a class. You can make any type superficially act like a `tuple` simply by overloading the global `get`, even classes that you're not allowed to change. In C++, free functions *are* a natural interface; C++ isn't Java and C#, where everything must be a member of something. – Nicol Bolas Oct 16 '12 at 03:32
  • @NicolBolas: I don't dispute that. I just think that in *this* case, a member function would have been a *more* natural interface. But that might be just taste. – bitmask Oct 16 '12 at 04:20
  • Then you won't be able to make third-party class that you can't change to behave as a `std::tuple`. –  Oct 16 '12 at 14:41
  • @jons34yp: Sure I can. I can just implement `MyTuple::get` to work just like `std::tuple::get` -- if such a thing would exist. This is even better, because I don't have to go violating the `std` namespace by implementing my stuff in there. – bitmask Oct 16 '12 at 17:13
  • Let's say you want tuple-like interface to std::string (or similar interface that you can't possibly get patched upstream). What's then? –  Oct 16 '12 at 19:34
  • @jons34yp: Then, you're doing it wrong. I'm having trouble imagining any scenario where changing the `std` semantics would not break your neck. – bitmask Oct 16 '12 at 22:38

0 Answers0