(C++17) | ||||
| Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
| Associative | ||||
| Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Views | ||||
(C++20) | ||||
(C++23) | ||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
| Member types | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
template<class...Args> constexpr reference emplace_back( Args&&...args); | (since C++26) | |
Appends a new element to the end of the container. Typically, the element is constructed using placement-new to construct the element in-place at the location provided by the container. The argumentsargs... are forwarded to the constructor asstd::forward<Args>(args)....
No iterators or references are invalidated, exceptend(), which is invalidated if the insertion occurs.
Contents |
| args | - | arguments to forward to the constructor of the element |
| Type requirements | ||
-T must meet the requirements ofEmplaceConstructible. | ||
back(), i.e. a reference to the inserted element.
Constant.
If an exception is thrown for any reason, these functions have no effect (strong exception safety guarantee).
#include <inplace_vector>#include <new>#include <print>#include <string>#include <utility> int main(){std::inplace_vector<std::pair<std::string,std::string>,2> fauna;std::string dog{"\N{DOG}"}; fauna.emplace_back("\N{CAT}", dog); fauna.emplace_back("\N{CAT}", std::move(dog));std::println("fauna = {}", fauna); try{ fauna.emplace_back("\N{BUG}","\N{BUG}");// throws: there is no space}catch(conststd::bad_alloc& ex){std::println("{}", ex.what());}std::println("fauna = {}", fauna);}
Possible output:
fauna = [("🐈", "🐕"), ("🐈", "🐕")]std::bad_allocfauna = [("🐈", "🐕"), ("🐈", "🐕")]| adds a range of elements to the end (public member function)[edit] | |
| adds an element to the end (public member function)[edit] | |
| tries to add an element to the end (public member function)[edit] | |
| tries to construct an element in-place at the end (public member function)[edit] | |
| tries to add a range of elements to the end (public member function)[edit] | |
| unconditionally adds an element to the end (public member function)[edit] | |
| unconditionally constructs an element in-place at the end (public member function)[edit] | |
| removes the last element (public member function)[edit] | |
| creates astd::back_insert_iterator of type inferred from the argument (function template)[edit] |