From cc7048888edc47b9ba15003065601fd40b22783d Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 24 Jan 2018 22:42:25 +0000 Subject: [PATCH] Implement LWG2783: stack::emplace() and queue::emplace() should return decltype(auto) git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323385 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/queue | 2 +- include/stack | 2 +- .../queue/queue.defn/emplace.pass.cpp | 55 +++++++++++++------ .../stack/stack.defn/emplace.pass.cpp | 25 ++++++++- www/cxx2a_status.html | 6 +- 5 files changed, 64 insertions(+), 26 deletions(-) diff --git a/include/queue b/include/queue index 670fbb722..80546fd81 100644 --- a/include/queue +++ b/include/queue @@ -290,7 +290,7 @@ public: template _LIBCPP_INLINE_VISIBILITY #if _LIBCPP_STD_VER > 14 - reference emplace(_Args&&... __args) + decltype(auto) emplace(_Args&&... __args) { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} #else void emplace(_Args&&... __args) diff --git a/include/stack b/include/stack index 0cb4c6ca9..7b81ade1f 100644 --- a/include/stack +++ b/include/stack @@ -199,7 +199,7 @@ public: template _LIBCPP_INLINE_VISIBILITY #if _LIBCPP_STD_VER > 14 - reference emplace(_Args&&... __args) + decltype(auto) emplace(_Args&&... __args) { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} #else void emplace(_Args&&... __args) diff --git a/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp b/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp index 4142bc369..e338c99fd 100644 --- a/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp +++ b/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. @@ -11,36 +11,55 @@ // -// template reference emplace(Args&&... args); -// return type is 'reference' in C++17; 'void' before +// template decltype(auto) emplace(Args&&... args); +// return type is 'decltype(auto)' in C++17; 'void' before +// whatever the return type of the underlying container's emplace_back() returns. #include #include +#include #include "test_macros.h" #include "../../../Emplaceable.h" +template +void test_return_type() { + typedef typename Queue::container_type Container; + typedef typename Container::value_type value_type; + typedef decltype(std::declval().emplace(std::declval())) queue_return_type; + +#if TEST_STD_VER > 14 + typedef decltype(std::declval().emplace_back(std::declval())) container_return_type; + static_assert(std::is_same::value, ""); +#else + static_assert(std::is_same::value, ""); +#endif +} + int main() { - typedef Emplaceable T; - std::queue q; + test_return_type > (); + test_return_type > > (); + + typedef Emplaceable T; + std::queue q; #if TEST_STD_VER > 14 - T& r1 = q.emplace(1, 2.5); - assert(&r1 == &q.back()); - T& r2 = q.emplace(2, 3.5); - assert(&r2 == &q.back()); - T& r3 = q.emplace(3, 4.5); - assert(&r3 == &q.back()); - assert(&r1 == &q.front()); + T& r1 = q.emplace(1, 2.5); + assert(&r1 == &q.back()); + T& r2 = q.emplace(2, 3.5); + assert(&r2 == &q.back()); + T& r3 = q.emplace(3, 4.5); + assert(&r3 == &q.back()); + assert(&r1 == &q.front()); #else - q.emplace(1, 2.5); - q.emplace(2, 3.5); - q.emplace(3, 4.5); + q.emplace(1, 2.5); + q.emplace(2, 3.5); + q.emplace(3, 4.5); #endif - assert(q.size() == 3); - assert(q.front() == Emplaceable(1, 2.5)); - assert(q.back() == Emplaceable(3, 4.5)); + assert(q.size() == 3); + assert(q.front() == Emplaceable(1, 2.5)); + assert(q.back() == Emplaceable(3, 4.5)); } diff --git a/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp index 8b19972eb..0fec47558 100644 --- a/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp +++ b/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp @@ -11,20 +11,39 @@ // -// template reference emplace(Args&&... args); -// return type is 'reference' in C++17; 'void' before +// template decltype(auto) emplace(Args&&... args); +// return type is 'decltype(auto)' in C++17; 'void' before +// whatever the return type of the underlying container's emplace_back() returns. #include #include +#include #include "test_macros.h" #include "../../../Emplaceable.h" +template +void test_return_type() { + typedef typename Stack::container_type Container; + typedef typename Container::value_type value_type; + typedef decltype(std::declval().emplace(std::declval())) stack_return_type; + +#if TEST_STD_VER > 14 + typedef decltype(std::declval().emplace_back(std::declval())) container_return_type; + static_assert(std::is_same::value, ""); +#else + static_assert(std::is_same::value, ""); +#endif +} + int main() { + test_return_type > (); + test_return_type > > (); + typedef Emplaceable T; - std::stack q; + std::stack q; #if TEST_STD_VER > 14 T& r1 = q.emplace(1, 2.5); assert(&r1 == &q.top()); diff --git a/www/cxx2a_status.html b/www/cxx2a_status.html index 6986d782c..68206cb7f 100644 --- a/www/cxx2a_status.html +++ b/www/cxx2a_status.html @@ -54,7 +54,7 @@ - P0463R1LWGEndian just EndianTorontoIn progress7.0 + P0463R1LWGEndian just EndianTorontoComplete7.0 P0674R1LWGExtending make_shared to Support ArraysToronto @@ -94,7 +94,7 @@ 2444Inconsistent complexity for std::sort_heapToronto 2593Moved-from state of AllocatorsToronto 2597std::log misspecified for complex numbersToronto - 2783stack::emplace() and queue::emplace() should return decltype(auto)Toronto + 2783stack::emplace() and queue::emplace() should return decltype(auto)TorontoComplete 2932Constraints on parallel algorithm implementations are underspecifiedToronto 2937Is equivalent("existing_thing", "not_existing_thing") an errorTorontoComplete 2940result_of specification also needs a little cleanupToronto @@ -135,7 +135,7 @@ -

Last Updated: 22-Jan-2018

+

Last Updated: 24-Jan-2018