Namespaces
Variants
Views
Actions

Talk:cpp/container/priority queue/emplace

From cppreference.com

[edit] Complexity

Should the complexity for emplace be similar to push, i.e. logarithmic plus whatever Container::emplace_back takes? It looks like 23.6.4.3 says that emplace just calls emplace_back and then re-heaps the container. --Nate (talk) 11:56, 21 January 2014 (PST)

Looks like you're right, it's defined just the same way as push() is. --Cubbi (talk) 13:36, 21 January 2014 (PST)

[edit] Is void a correct return type in priority_queue::emplace()

As per this doc: https://cplusplus.github.io/LWG/issue2783

Both stack and queue returns decltype(auto) for their emplace() method. priority_queue is also a container adaptor and could use deque/list as it's container. Shouldn't the priority_queue::emplace() also return decltype(auto) from C++17 ? pabitrapadhy (talk) 21:22, 11 April 2022 (PDT)ppadhy

Yeah void is still the return type. Having std::priority_queue::emplace return the reference given by emplace_back would be unhelpful after the std::sort_heap is performed, see [1] for example --Ybab321 (talk) 02:27, 12 April 2022 (PDT)
right, LWG2783 only changed stack and queue; priority_queue is as before https://eel.is/c++draft/priqueue.members --Cubbi (talk) 06:31, 12 April 2022 (PDT)