This code:
unique_ptr<int> a;
if (a) {
cout << "ASSIGNED" << endl;
}
and even this code:
unique_ptr<int> a;
if (static_cast<bool>(a)) {
cout << "ASSIGNED" << endl;
}
cause this warning:
warning C4800: 'void (__cdecl *)(std::_Bool_struct<_Ty> &)' : forcing value to bool 'true' or 'false' (performance warning)
with
[
_Ty=std::unique_ptr<int>
]
in Visual Studio 2012 on warning level 3. After the first comments I found out that it only happens if common language runtime support /clr is switched on. How should I avoid it?
if (a.get() != nullptr)
should work, but I think that is not how unique_ptr was designed, was it?
You may use directly
if (a != nullptr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With