Boost.Rangeにタグディスパッチを付ける

  • Boost.RangeやBoost.Serializationのカスタマイズは同じような型がたくさんある場合、無駄に大変だ
  • マクロで何とかしてみてはどうだろう・・・ダウンロード
  • 使い方は以下のような感じで

[]struct[] []std_container_tag[]
[]{ };[]

[]struct[] []my_string_tag[]
[]{ };[]


[]struct[] []my_string[][] : [][]std[][]::[][]string[]
[]{ };[]

[]namespace[] []pstade[][] { [][]namespace[] []oven[][] { [][]namespace[] []customize[][] {[]


[]template[][]< [][]class[] []T[][], [][]class[] []Allocator[][] >[]
[]struct[] []tag[][]< [][]std[][]::[][]vector[][]<[][]T[][], [][]Allocator[][]> > :[]
[]boost[][]::[][]mpl[][]::[][]identity[][]<[][]std_container_tag[][]>[]
[]{ };[]

[]template[][]< [][]class[] []T[][], [][]class[] []Allocator[][] >[]
[]struct[] []tag[][]< [][]std[][]::[][]list[][]<[][]T[][], [][]Allocator[][]> > :[]
[]boost[][]::[][]mpl[][]::[][]identity[][]<[][]std_container_tag[][]>[]
[]{ };[]

[]template[][]< [][]class[] []Container[][] >[]
[]struct[] []metafunctions[][]<[][]std_container_tag[][], [][]Container[][]>[]
[]{[]
[]typedef[] []typename[] []Container[][]::[][]iterator[] []mutable_iterator[][];[]
[]typedef[] []typename[] []Container[][]::[][]const_iterator[] []const_iterator[][];[]
[]typedef[] []typename[] []Container[][]::[][]size_type[] []size_type[][];[]
[]};[]

[]template[][]< >[]
[]struct[] []functions[][]<[][]std_container_tag[][]>[]
[]{[]
[]template[][]< [][]class[] []Container[][]>[]
[]typename[] []iterator[][]<[][]Container[][]>::[][]type[] []begin[][]([][]Container[][]& [][]c[][])[]
[] {[]
[]return[] []c[][].[][]begin[][]();[]
[] }[]

[]template[][]< [][]class[] []Container[][]>[]
[]typename[] []iterator[][]<[][]Container[][]>::[][]type[] []end[][]([][]Container[][]& [][]c[][])[]
[] {[]
[]return[] []c[][].[][]end[][]();[]
[] }[]

[]template[][]< [][]class[] []Container[][]>[]
[]typename[] []size_type[][]<[][]Container[][]>::[][]type[] []size[][]([][]Container[][]& [][]c[][])[]
[] {[]
[]return[] []c[][].[][]size[][]();[]
[] }[]
[]};[]


[]template[][]< >[]
[]struct[] []tag[][]< [][]my_string[][] > :[]
[]boost[][]::[][]mpl[][]::[][]identity[][]<[][]my_string_tag[][]>[]
[]{ };[]

[]template[][]< [][]class[] []StringT[][] >[]
[]struct[] []metafunctions[][]<[][]my_string_tag[][], [][]StringT[][]>[]
[]{[]
[]typedef[] []typename[] []StringT[][]::[][]iterator[] []mutable_iterator[][];[]
[]typedef[] []typename[] []StringT[][]::[][]const_iterator[] []const_iterator[][];[]
[]typedef[] []typename[] []StringT[][]::[][]size_type[] []size_type[][];[]
[]};[]

[]template[][]< >[]
[]struct[] []functions[][]<[][]my_string_tag[][]>[]
[]{[]
[]template[][]< [][]class[] []StringT[][]>[]
[]typename[] []iterator[][]<[][]StringT[][]>::[][]type[] []begin[][]([][]StringT[][]& [][]c[][])[]
[] {[]
[]return[] []c[][].[][]begin[][]();[]
[] }[]

[]template[][]< [][]class[] []StringT[][]>[]
[]typename[] []iterator[][]<[][]StringT[][]>::[][]type[] []end[][]([][]StringT[][]& [][]c[][])[]
[] {[]
[]return[] []c[][].[][]end[][]();[]
[] }[]

[]template[][]< [][]class[] []StringT[][]>[]
[]typename[] []size_type[][]<[][]StringT[][]>::[][]type[] []size[][]([][]StringT[][]& [][]c[][])[]
[] {[]
[]return[] []c[][].[][]size[][]();[]
[] }[]
[]};[]


[]} } } [][]// namespace pstade::oven::customize[]


[]PSTADE_OVEN_CUSTOMIZE_TEMPLATE[][](([][]std[][], [][]BOOST_PP_NIL[][]), [][]vector[][], ([][]class[][])([][]class[][]))[]
[]PSTADE_OVEN_CUSTOMIZE_TEMPLATE[][](([][]std[][], [][]BOOST_PP_NIL[][]), [][]list[][], ([][]class[][])([][]class[][]))[]
[]PSTADE_OVEN_CUSTOMIZE_TYPE[][]([][]BOOST_PP_NIL[][], [][]my_string[][]) []