`<tuple>`: Should `allocator_arg_t` constructors of `tuple` specially handle `pair` since C++20?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
WG21-P0591R4 (adopted in C++20) extended the definition of uses-allocator construction to cover pair. It seems that strict reading of standard wording requires the allocator_arg_t constructors of tuple to be changed.
However, no implementation is currently doing this. Example (Godbolt link):
#include <cstddef>
#include <utility>
#include <tuple>
#include <memory>
#include <vector>
#include <cassert>
template<class T>
class payload_ator {
int payload{};
public:
payload_ator() = default;
constexpr explicit payload_ator(int n) noexcept : payload{n} {}
template<class U>
constexpr explicit payload_ator(payload_ator<U> a) noexcept : payload{a.payload} {}
friend bool operator==(payload_ator, payload_ator) = default;
template<class U>
friend constexpr bool operator==(payload_ator x, payload_ator<U> y) noexcept {
return x.payload == y.payload;
}
using value_type = T;
constexpr T* allocate(std::size_t n) { return std::allocator<T>{}.allocate(n); }
constexpr void deallocate(T* p, std::size_t n) { return std::allocator<T>{}.deallocate(p, n); }
constexpr int get_payload() const noexcept { return payload; }
};
bool test() {
constexpr int in_v = 42;
using my_pair_t = std::pair<int, std::vector<int, payload_ator<int>>>;
std::tuple<my_pair_t> t(std::allocator_arg, payload_ator<int>{in_v});
auto out_v = std::get<0>(t).second.get_allocator().get_payload();
return in_v == out_v;
}
int main() {
assert(test()); // passes only if allocator_arg_t constructors of tuple specially handle pair
}
Should we update these constructors or submit an LWG issue to avoid changing?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with tuple's allocator_arg_t constructors and review WG21-P0591R4's uses-allocator wording for pair. Reproduce the supplied Godbolt example and verify the allocator payload observed through std::get<0>(t). Done means determining whether C++20 requires special pair handling or whether an LWG issue should be filed instead.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100