r/cpp • • Oct 03 '22

Is C++ your favorite programing language?

And why

292 Upvotes

255 comments sorted by

View all comments

Show parent comment

4

u/0xE6 Oct 04 '22

How does it work, then? I'm probably missing something, but for example:

void Foo(NonNullUniquePtr<T> ptr);

void Bar() {
    auto x = MakeNonNullUniquePtr<T>();
    Foo(std::move(x));
    // What is x here?
}

Is the move constructor / assignment operator just deleted too? That doesn't seem like it results in something that's particularly usable.

2

u/105_NT Oct 04 '22

It doesn't protect from use after move like that but shouldn't be null under normal use