Author: marshall Date: Wed Jan 24 14:42:25 2018 New Revision: 323385 URL: http://llvm.org/viewvc/llvm-project?rev=323385&view=rev Log: Implement LWG2783: stack::emplace() and queue::emplace() should return decltype(auto)
Modified: libcxx/trunk/include/queue libcxx/trunk/include/stack libcxx/trunk/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp libcxx/trunk/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp libcxx/trunk/www/cxx2a_status.html Modified: libcxx/trunk/include/queue URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/queue?rev=323385&r1=323384&r2=323385&view=diff ============================================================================== --- libcxx/trunk/include/queue (original) +++ libcxx/trunk/include/queue Wed Jan 24 14:42:25 2018 @@ -290,7 +290,7 @@ public: template <class... _Args> _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) Modified: libcxx/trunk/include/stack URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stack?rev=323385&r1=323384&r2=323385&view=diff ============================================================================== --- libcxx/trunk/include/stack (original) +++ libcxx/trunk/include/stack Wed Jan 24 14:42:25 2018 @@ -199,7 +199,7 @@ public: template <class... _Args> _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) Modified: libcxx/trunk/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp?rev=323385&r1=323384&r2=323385&view=diff ============================================================================== --- libcxx/trunk/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp (original) +++ libcxx/trunk/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp Wed Jan 24 14:42:25 2018 @@ -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 @@ // <queue> -// template <class... Args> reference emplace(Args&&... args); -// return type is 'reference' in C++17; 'void' before +// template <class... Args> 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 <queue> #include <cassert> +#include <list> #include "test_macros.h" #include "../../../Emplaceable.h" +template <typename Queue> +void test_return_type() { + typedef typename Queue::container_type Container; + typedef typename Container::value_type value_type; + typedef decltype(std::declval<Queue>().emplace(std::declval<value_type &>())) queue_return_type; + +#if TEST_STD_VER > 14 + typedef decltype(std::declval<Container>().emplace_back(std::declval<value_type>())) container_return_type; + static_assert(std::is_same<queue_return_type, container_return_type>::value, ""); +#else + static_assert(std::is_same<queue_return_type, void>::value, ""); +#endif +} + int main() { - typedef Emplaceable T; - std::queue<Emplaceable> q; + test_return_type<std::queue<int> > (); + test_return_type<std::queue<int, std::list<int> > > (); + + typedef Emplaceable T; + std::queue<Emplaceable> 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)); } Modified: libcxx/trunk/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp?rev=323385&r1=323384&r2=323385&view=diff ============================================================================== --- libcxx/trunk/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp (original) +++ libcxx/trunk/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp Wed Jan 24 14:42:25 2018 @@ -11,20 +11,39 @@ // <stack> -// template <class... Args> reference emplace(Args&&... args); -// return type is 'reference' in C++17; 'void' before +// template <class... Args> 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 <stack> #include <cassert> +#include <vector> #include "test_macros.h" #include "../../../Emplaceable.h" +template <typename Stack> +void test_return_type() { + typedef typename Stack::container_type Container; + typedef typename Container::value_type value_type; + typedef decltype(std::declval<Stack>().emplace(std::declval<value_type &>())) stack_return_type; + +#if TEST_STD_VER > 14 + typedef decltype(std::declval<Container>().emplace_back(std::declval<value_type>())) container_return_type; + static_assert(std::is_same<stack_return_type, container_return_type>::value, ""); +#else + static_assert(std::is_same<stack_return_type, void>::value, ""); +#endif +} + int main() { + test_return_type<std::stack<int> > (); + test_return_type<std::stack<int, std::vector<int> > > (); + typedef Emplaceable T; - std::stack<Emplaceable> q; + std::stack<Emplaceable> q; #if TEST_STD_VER > 14 T& r1 = q.emplace(1, 2.5); assert(&r1 == &q.top()); Modified: libcxx/trunk/www/cxx2a_status.html URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx2a_status.html?rev=323385&r1=323384&r2=323385&view=diff ============================================================================== --- libcxx/trunk/www/cxx2a_status.html (original) +++ libcxx/trunk/www/cxx2a_status.html Wed Jan 24 14:42:25 2018 @@ -54,7 +54,7 @@ <!-- <tr><td><a href="https://wg21.link/n3346">3346</a></td><td>LWG</td><td>Terminology for Container Element Requirements - Rev 1</td><td>Kona</td><td>Complete</td><td>3.4</td></tr> --> - <tr><td><a href="https://wg21.link/P0463R1">P0463R1</a></td><td>LWG</td><td>Endian just Endian</td><td>Toronto</td><td><I>In progress</I></td><td>7.0</td></tr> + <tr><td><a href="https://wg21.link/P0463R1">P0463R1</a></td><td>LWG</td><td>Endian just Endian</td><td>Toronto</td><td>Complete</td><td>7.0</td></tr> <tr><td><a href="https://wg21.link/P0674R1">P0674R1</a></td><td>LWG</td><td>Extending make_shared to Support Arrays</td><td>Toronto</td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> @@ -94,7 +94,7 @@ <tr><td><a href="https://wg21.link/LWG2444">2444</a></td><td>Inconsistent complexity for <tt>std::sort_heap</tt></td><td>Toronto</td><td></td></tr> <tr><td><a href="https://wg21.link/LWG2593">2593</a></td><td>Moved-from state of Allocators</td><td>Toronto</td><td></td></tr> <tr><td><a href="https://wg21.link/LWG2597">2597</a></td><td><tt>std::log</tt> misspecified for complex numbers</td><td>Toronto</td><td></td></tr> - <tr><td><a href="https://wg21.link/LWG2783">2783</a></td><td><tt>stack::emplace()</tt> and <tt>queue::emplace()</tt> should return <tt>decltype(auto)</tt></td><td>Toronto</td><td></td></tr> + <tr><td><a href="https://wg21.link/LWG2783">2783</a></td><td><tt>stack::emplace()</tt> and <tt>queue::emplace()</tt> should return <tt>decltype(auto)</tt></td><td>Toronto</td><td>Complete</td></tr> <tr><td><a href="https://wg21.link/LWG2932">2932</a></td><td>Constraints on parallel algorithm implementations are underspecified</td><td>Toronto</td><td></td></tr> <tr><td><a href="https://wg21.link/LWG2937">2937</a></td><td>Is <tt>equivalent("existing_thing", "not_existing_thing")</tt> an error</td><td>Toronto</td><td>Complete</td></tr> <tr><td><a href="https://wg21.link/LWG2940">2940</a></td><td><tt>result_of</tt> specification also needs a little cleanup</td><td>Toronto</td><td></td></tr> @@ -135,7 +135,7 @@ <!-- <tr><td></td><td></td><td></td><td></td></tr> --> </table> - <p>Last Updated: 22-Jan-2018</p> + <p>Last Updated: 24-Jan-2018</p> </div> </body> </html> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits