1

I was wondering if it is possible to write a std::tie()-like function (using template programming) that can bind select components of a tuple only, and bind others to some placeholders like those in std::bind(). If so, one needs only declare variables for the parts he/she is interested in.

For example,

std::tie(x,_1,y,_2) = (2,3,4,5);
thor
  • 21,418
  • 31
  • 87
  • 173
  • It's not allowed to add anything to the std namespace or change anything within. – John Dibling Jan 23 '14 at 03:59
  • 1
    @JohnDibling `std::hash` would like a word with you. – Yakk - Adam Nevraumont Jan 23 '14 at 20:14
  • @Yakk: I take it back. You can add template specializations. – John Dibling Jan 23 '14 at 20:58
  • @JohnDibling for types dependent on user-defined types only, I believe. (No `int` or `std::pair` specializations) – Yakk - Adam Nevraumont Jan 24 '14 at 00:35
  • @Yakk [litb](http://stackoverflow.com/questions/1390703/enumerate-over-an-enum-in-c) specializes `std::iterator_traits` for `color` in namespace std, so this should be ok right? I mean is this the natural way of doing these things? or are there any caveats? – Koushik Shetty Jan 24 '14 at 04:04
  • @Koushik I believe (I do not have chapter and verse from the standard) if you own a type T, then you can specialize stuff in `std` for the type `T`, or even (if I am right) `std::vector` is fair game. You do not own any types in `std` nor any built-in types, nor pointers or references to or cv qualifications of things you do not own. I should find that chapter and verse... – Yakk - Adam Nevraumont Jan 24 '14 at 04:23
  • @Yakk ah that seems fair enough. other than these specializations, std namespace should not be opened for anything else right? – Koushik Shetty Jan 24 '14 at 04:29

1 Answers1

13

Are you looking for std::ignore?

i.e.:

std::tie(x,std::ignore,y,std::ignore) = std::make_tuple(2,3,4,5);
yasouser
  • 5,113
  • 2
  • 27
  • 41