Is there a difference between an std::pair and an std::tuple with only two members? (Besides the obvious that std::pair requires two and only two members and tuple may have more or less…)
Is there a difference between an std::pair and an std::tuple with only two members?
Share
There are some differences:
std::tupleis not required by the standard to ever be standard-layout. Everystd::pair<T, Y>is standard-layout if bothTandYare standard-layout.It’s a bit easier to get the contents of a
pairthan atuple. You have to use a function call in thetuplecase, while thepaircase is just a member field.But that’s about it.