- 431 名前:デフォルトの名無しさん [2024/08/27(火) 17:33:30.75 ID:K7dNHCWQ0.net]
- #include <iostream>
#include <complex> template <class T> decltype(auto) f(T x) { decltype(abs(std::declval<T>())) w; w=abs(x); return w; } int main() { using namespace std; cout<<f(-1) << endl; cout<<f(2.f)<< endl; complex<double> z=complex<double>(1.0,1.0); cout<<f(z)<<endl; cin.get(); return 0; } いちかばちかでやったら、通りました。abs! Who are you? sizeof演算子と同じくコンパイル時に評価されるんですか? というか、地味だけど declval が凄い。
|

|