Does vector<T>::push_back() call any matching constructor of its type T?

anki vector
vector robot commands
can vector read
anki vector vs cozmo
vector robot review
anki vector updates
can vector play music
does vector talk

I used a reference_wrapper recently like so:

#include <iostream>
#include <vector>
#include <functional>
#include <memory>

struct A {
};

struct B {
    B() {};
    B(A& aA) {};
    B(const B&) = default;
};

int main () {
    A a;
    B b;

    std::vector<std::reference_wrapper<B>> rvector;
    rvector.push_back(std::reference_wrapper<B>(b)); // (1)
    rvector.push_back(b); // (2)

1 and 2, are both compiling and working just fine and I wonder which is the right one! So I thought that the following could work too:

    std::vector<B> bvector;
    bvector.push_back(a); // (3)
    bvector.push_back(b); // (4)
    std::cout << bvector.size() << "\n";

yeap, it works! So I came to the conclusion that push_back just calls the type's T constructor with the given parameter. Documentation though mentions that the parameter is of type T and eventually the copy/move ctor.

When I tried 1 and 2 with shared_ptr though:

    std::vector<std::shared_ptr<B>> pvector;
    pvector.push_back(std::shared_ptr<B>(new B())); // (5)
    pvector.push_back(new B()); // (6)

I get

no matching function for call to 'std::vector<std::shared_ptr<B> >::push_back(B*)'
  • Why 2 and even 3 work but 6 doesn't?
  • There should be a shared_ptr<B>constructor that takes B* as parameter, isn't there? So, why 6 does not compile (since 3 does)?
  • Since 3 compiles and works just fine, would it be ok to use and count on it (if it wasn't a bad approach since there is the emplace_back)?

Why 2 and even 3 work but 6 doesn't?

std::vector::push_back takes T as parameter, then it'll work if you're passing something which could be converted to T implicitly.

(2) works because B could convert to std::reference_wrapper<B> implicitly. (3) works because A could convert to B implicitly. (6) doesn't work because B* can't convert to shared_ptr<B> implicitly. Note that the constructor of shared_ptr taking raw pointers is marked as explicit.

Since 3 compiles and works just fine, would it be ok to use and count on it (if it wasn't a bad approach since there is the emplace_back)?

Yes you can use it, but note that emplace_back is more efficient sometimes; it will construct the element in-place directly without any implicit conversion, instead of constructing a temporary T and then move it into the vector (as push_back).

Anki's toy robots are being saved from a digital death, is voice-activated and will answer questions, take photos for you, time dinner, show you the weather, and more. noun. Mathematics. a quantity possessing both magnitude and direction, represented by an arrow the direction of which indicates the direction of the quantity and the length of which is proportional to the magnitude.Compare scalar (def 4). such a quantity with the additional requirement that such quantities obey the parallelogram law of addition. such a quantity with the additional requirement that such quantities are to transform in a particular way under changes of the coordinate system.


push_back takes a T const& or a T&&.

So if we have a vector<X>, push_back(expr) works if X const& x=expr; compiles or X&& x=expr; compiles, and it isn't ambiguous which matches better, and the move/copy from the argument is allowed.

Those compile for your first cases, but not your shared ptr from ptr, because X x=expr; doesn't call explicit constructors.

You can vec.emplace_back(expr) if you want to consider explicit constructors.

Vector Robot by Anki, A Home Robot Who Hangs Out , understands the world around it. And it understands much more than you'd guess. Vector definition is - a quantity that has magnitude and direction and that is commonly represented by a directed line segment whose length represents the magnitude and whose orientation in space represents the direction; broadly : an element of a vector space.


Constructor of std::reference_wrapper is a converting constructor that allows implicit conversion from B to std::reference_wrapper<B> and that's why (2) works.

However constructor (3) of std::shared_ptr is explicit, hence you have to specify std::shared_ptr<B> explicitly in (5).

The new Anki Vector robot is smart enough to just hang out, is also integrated with Amazon Alexa making it a more knowledgeable robot. Vector, can make you laugh, express the weather, take photos, play blackjack and much more. He can also return to his charging base when he senses low power. Similar to Cozmo, its best features are still to come. Vector is also integrated with Amazon Alexa making it a more knowledgeable robot.


50 Things You Can Ask Vector: The Robot with a Mind of its Own , And because Vector is completely autonomous, you can do something completely surprising Posted: 8 Aug 2018 MYTH: Vector Marketing is a scam because it's a "get-rich-quick" pyramid scheme The TRUTH: Vector Marketing is not a pyramid scheme in any way, shape or form. Vector Marketing is the sales and marketing division of Cutco. Vector reps are not responsible for recruiting new reps or buying any sort of product or service.


Anki Vector Robot WHAT ELSE CAN HE DO??, Had a lot of people asking questions about what can vector do on the first look video, I've been Duration: 8:44 Posted: 11 Oct 2018 Vector is made to explore and react. His tech array allows him to intuitively interact with his surroundings through sight and sound. He can recognize people and objects while detecting and avoiding obstacles.


Anki Vector Robot honest review "what you need to know", Your browser does not currently recognize any of the video formats available. Anki Vector Duration: 11:43 Posted: 6 Nov 2018 The initial unpaid training seminar is a two or three-day program led by experienced Vector professionals. You can participate at a local office or online, whichever works for you. Don't worry: these sessions are interactive, engaging, and fun.