2013-04-16から1日間の記事一覧

暗黙変換の結果によって生まれた一時オブジェクトに気をつけて

次に示される関数 implicit_cast について考える. #include <type_traits> #include <utility> template<class To, class From, typename std::enable_if< std::is_convertible<From, To>::value >::type* = nullptr > To implicit_cast(From && x) { return std::forward<From>(x); } この関数は,引数として渡された値を,型 To に暗黙変換して返すものであり,例えば</from></class></utility></type_traits>…