次のコードが出力として「0」を出力するのはなぜですか?
#include <functional>
#include <iostream>
int main()
{
typedef void (*fp_t)();
fp_t fp = nullptr;
std::function<void()> f = fp;
std::cout << (f == nullptr) << '\n';
}
gcc 4.7.2 と MSVC-11.0 の両方でテストしました。
標準からの次の引用のため、「1」を出力する必要があると思います。
ISO/IEC 14882:2011
20.8.11.2.1 関数の構築/コピー/破棄 [func.wrap.func.con]
template<class F> function(F f);
template<class F, class A> function(allocator_arg_t, const A& a, F f);
...
8事後条件: 次のいずれかが
!*this
成り立つ場合: — 関数ポインタです。—メンバーへのポインターです。—関数クラス テンプレートのインスタンスであり、f
NULL
f
NULL
F
!f