Comment on The missing C++ smart pointerComments−jbandela13yA 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.−kccqzy3yNot 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.−fluoridation3yT && gets you the semantics you're looking for.EDIT: Why are you booing me? I'm right.−devit3yT&& doesn't run the T destructor when it's destroyed, which is the whole point of unique_ptr.
Comments
A
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.