forked from OSchip/llvm-project
Implement LWG2783: stack::emplace() and queue::emplace() should return decltype(auto)
llvm-svn: 323385
This commit is contained in:
parent
5ee0398849
commit
e34f5ffe4b
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -11,19 +11,38 @@
|
|||
|
||||
// <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()
|
||||
{
|
||||
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
|
||||
|
|
|
@ -11,18 +11,37 @@
|
|||
|
||||
// <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;
|
||||
#if TEST_STD_VER > 14
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue