https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90239
Bug ID: 90239 Summary: [C++20] scoped_allocator_adaptor should support nested pair Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: kariya_mitsuru at hotmail dot com Target Milestone: --- The current implementation of scoped_allocator_adaptor is not support nested pair. =========================== sample code =========================== #include <iostream> #include <vector> #include <utility> #include <scoped_allocator> #include <new> // stateful allocator template <typename T> class MyAlloc { public: using value_type = T; T* allocate(std::size_t n) { return static_cast<T*>(::operator new(sizeof(T) * n)); } void deallocate(T* p, std::size_t n) { ::operator delete(static_cast<void*>(p), sizeof(T) * n); } MyAlloc(int state) noexcept : state(state) {} template <typename U> MyAlloc(const MyAlloc<U>& o) noexcept : state(o.state) {} int state; }; template <typename T> bool operator==(const MyAlloc<T>& lhs, const MyAlloc<T>& rhs) noexcept { return lhs.state == rhs.state; } template <typename T> bool operator!=(const MyAlloc<T>& lhs, const MyAlloc<T>& rhs) noexcept { return lhs.state != rhs.state; } // type alias template <typename T> using SA = std::scoped_allocator_adaptor<MyAlloc<T>>; template <typename T> using VEC = std::vector<T, SA<T>>; int main() { VEC<std::pair<std::pair<VEC<int>, int>, int>> v(SA<int>(1)); v.emplace_back(std::make_pair(VEC<int>{SA<int>(2)}, 1), 2); v.emplace_back(std::make_pair(VEC<int>{SA<int>(3)}, 3), 4); std::cout << v.get_allocator().state << ", " << v[0].first.first.get_allocator().state << ", " << v[1].first.first.get_allocator().state << '\n'; } =========================== sample code =========================== =========================== sample output =========================== 1, 2, 3 =========================== sample output =========================== cf. https://wandbox.org/permlink/mcVJEFjpR2UeyW0O I think that it should output "1, 1, 1" in c++2a mode. P0591R4: Utility functions to implement uses-allocator construction http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0591r4.pdf C++ 2020 Implementation Status https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2020 commit for P0591R4 https://github.com/gcc-mirror/gcc/commit/6a9c77f14d18d819dc4b03e1ebc2da4e5f085627