Skip to content

lungsdude/unique-ptr-deduction-guides

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Deduction guides for std::unique_ptr

deduction_guides.h — deduction guides with some helper metafunctions.

examples.cpp — examples on how it is meant to be used.

How it works

If you provide a deleter, the compiler trusts you that you provided the right deleter and sets the type of the unique ptr either the type of the pointer or the type of the first argument of the deleter.

No deduction is provided if no deleter is given (i.e std::unique_ptr{ new Foo{} }; and std::unique_ptr{ new Foo[N]{} }). It will give a compile-time error, because you cannot make a difference between a pointer and a C array - both are pointers. So use std::make_unique<Foo>() instead.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%