Conversion Member Templateを使った戻り値型の指定の省略
- 一時的なクラスを用意して、戻り値の型の指定を省略できるようにする
- 使いどころが多くて面白いです・・・参照
- xxx_castのような関数にも全部用意してはどうだろう・・・boost::lexical_castの場合
[]#include[] []<pstade/lexical_cast.hpp>[]
[]template[][]< [][]class[] []T[][] >[]
[]void[] []foo[][]([][]T[][]& [][]x[][])[]
[]{[]
[]std[][]::[][]string[] []str[][] = [][]x[][];[]
[]BOOST_CHECK[][]( [][]str[][] == [][]"12"[][] );[]
[]}[]
[]void[] []bar[][]([][]const[] []std[][]::[][]string[][]& [][]str[][])[]
[]{[]
[]BOOST_CHECK[][]( [][]str[][] == [][]"12"[][] );[]
[]}[]
[]void[] []test[][]()[]
[]{[]
[]using[] []namespace[] []pstade[][];[][]std[][]::[][]string[] []str[][] = [][]pstade[][]::[][]lexical[][]([][]12[][]);[]
[]BOOST_CHECK[][]( [][]str[][] == [][]"12"[][] );[][]int[] []n[][] = [][]pstade[][]::[][]lexical[][]([][]str[][]);[]
[]BOOST_CHECK[][]( [][]n[][] == [][]12[][] );[][]BOOST_CHECK[][](([]
[]boost[][]::[][]lexical_cast[][]<[][]int[][], [][]std[][]::[][]string[][]>([]
[]pstade[][]::[][]lexical[][]([]
[]boost[][]::[][]lexical_cast[][]<[][]int[][], [][]std[][]::[][]string[][]>([]
[]pstade[][]::[][]lexical[][]([][]12[][])[]
[] )[]
[] )[]
[] ) == [][]12[]
[] ));[]
[] ::[][]foo[][]([][]pstade[][]::[][]lexical[][]([][]12[][]));[]
[] ::[][]bar[][]([][]pstade[][]::[][]lexical[][]([][]12[][]));[]
[]}[]