skypjack
skypjack

Reputation: 50550

Tuple with pair and uses-allocator construction

std::tuple support uses-allocator construction, while pairs are a kind of corner case with a special treatment that makes them work as-if they supported uses-allocator construction.
However, imagine to combine them in a container like:

std::vector<std::tuple<std::pair<T, U>, another_type>> vec{};

Quite a nonsense type that is good enough for the purpose of the question though.
In this case, the vector forwards the allocator to the tuple as expected (uses_allocator is specialized for tuples). However, the tuple only forwards the same allocator to the types for which uses_allocator_v is true and this isn't true for pairs.
Therefore, this combination breaks the assumption that a pair works as-if it supported uses-allocator construction. Unfortunately, an std::pair<T, std::pair<U, V>> suffers from the same problem from what I can tell.

Is there any way to get around this issue and make the container above (or more likely something similar that still contains a pair and a second value) work as expected?

Upvotes: 3

Views: 354

Answers (0)

Related Questions