Skip to content

Comment on The missing C++ smart pointer

Comments

A

    non_null_unique_ptr<T>
that is enforced at compile time would be far more valuable for me. That would mean some kind of destructive move where the compiler guarantees that you can not access a moved from object.

Not the compiler but today you can already have a ClangTidy check: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-...

If your build system respects ClangTidy checks and turn them into errors, it's effectively the same as a compiler guarantee.

T && gets you the semantics you're looking for.

EDIT: Why are you booing me? I'm right.

T&& doesn't run the T destructor when it's destroyed, which is the whole point of unique_ptr.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.