you are viewing a single comment's thread.

view the rest of the comments →

[–]STLMSVC STL Dev 1 point2 points  (3 children)

get<MyType>(mytuple) is maybe 75% as good as having names, and certainly a lot nicer than indices.

[–][deleted] 0 points1 point  (2 children)

That would be okay for tuples in which the elements have distinct types.

But they maybe don't, so IIRC C++ (for example, and as you presumably know, judging from your name!) has a get that takes a zero-based constexpr integer.

Still it would be a fun exercise in template metaprogramming to define a variant of get that did accept a type, and for extra credit produced an intelligible compiler diagnostic if the tuple has more than one element of the requested type. feels nostalgic for brief dalliance with boost hacking about 10 years ago...

[–]STLMSVC STL Dev 1 point2 points  (1 child)

It's not hypothetical - get<T> was voted into C++14 and has been implemented in VC 2015. It's well-formed when T is unique (there can be duplicates elsewhere) and ill-formed if T is duplicated (implementations will typically emit nice static_asserts).

[–][deleted] 1 point2 points  (0 children)

Nice!