I'm writing a custom implementations of a container. I'm using a std::vector in which I append elements in the end with an emplace_back
functions.
In a push function I'm using custom_vector.emplace_back(std::forward<X>(value));
struct Node {
T value;
template <typename X>
Node(X &&x) : value{std::forward<X>(x)} {}
};
I'm not getting what is really doing std::forward
. In this way I can avoid to write both the copy and move constructor? Can some one explain the behaviour of std::forward?
In this case is working everything is working but only con emplace back
and not con push back
. It makes sense?
T
is copyable and movable). – superstd::forward
may not carry much meaning before understanding forwarding references. – Drew Dormann