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?
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 theallocator_arg_tconstructors oftupleto be changed.However, no implementation is currently doing this. Example (Godbolt link):
Should we update these constructors or submit an LWG issue to avoid changing?