unique_ptr
nullptr_t コンストラクターがある理由を理解しようとしています
constexpr unique_ptr::unique_ptr( nullptr_t );
これは、通常の 1 つの引数コンストラクターが明示的であり、nullptr 値を拒否するためであると想定していました。
explicit unique_ptr::unique_ptr( pointer p );
しかし、例をビルドすると、コンパイラは正常に動作します:
namespace ThorsAnvil
{
template<typename T>
class SmartPointer
{
public:
SmartPointer() {}
explicit SmartPointer(T*){}
};
}
template<typename T>
using SP = ThorsAnvil::SmartPointer<T>;
int main()
{
SP<int> data1;
SP<int> data2(new int); // fine
SP<int> data3(nullptr); // fine
}
出力は次のとおりです。
> g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
> g++ -Wall -Wextra -std=c++11 SP1.cpp
std::unique_ptr に nullptr_t 引数を取る追加のコンストラクタが必要なのはなぜですか?