さよなら関数

  • Boost.Sequenceを少し覗いてみましたが、ショッキングなことになっている
  • 汎用関数においては生の関数がdeprecatedになるのかもしれない
    • 関数に見えるものが実は関数オブジェクト
    • Forwarding問題を解決するクラスを利用できる(実装はそのクラスから呼んでもらう)
    • 古いコンパイラの呼び出しのあいまいさも局所化できる
  • iteratorから直接値を取り出すのではなくなるらしい
    • const_iteratorはなくなるようだ
  • 以下、Boost.Sequenceのポリモーフィズムの概要
    • template template parameterのないコンパイラにも対応できる(detail::functionをMetafunctionClassを取るように変える)

[]#include[] []<boost/mpl/apply.hpp>[]
[]#include[] []<boost/mpl/placeholders.hpp>[]
[]#include[] []<boost/type_traits.hpp>[]

[]namespace[] []pstade[][] {[]

[]namespace[] []customization[][] {[]

[]template[][]< [][]class[] []Range[][] >[]
[]struct[] []tag[][];[]

[]template[][]< [][]class[] []Range[][], [][]class[] []Tag[][] = [][]typename[] []tag[][]<[][]Range[][]>::[][]type[][] >[]
[]struct[] []operations[][];[]

[] } [][]// namespace customization[]

[]namespace[] []detail[][] {[]

[]template[][]< [][]class[] []Range[][] >[]
[]struct[] []operations[][] :[]
[]customization[][]::[][]operations[][]<[]
[]typename[] []boost[][]::[][]remove_cv[][]<[][]Range[][]>::[][]type[]
[] >[]
[] { };[]

[] } [][]// namespace detail[]

[]namespace[] []meta[][] {[]

[]template[][]< [][]class[] []Range[][] >[]
[]struct[] []begin[][] : [][]detail[][]::[][]operations[][]<[][]Range[][]>::[][]begin[][] { };[]

[]template[][]< [][]class[] []Range[][] >[]
[]struct[] []end[][] : [][]detail[][]::[][]operations[][]<[][]Range[][]>::[][]end[][] { };[]

[] } [][]// namespace meta[]

[]namespace[] []detail[][] {[]

[]template[][]< [][]template[][]< [][]class[][] > [][]class[] []F[][] >[]
[]struct[] []function[]
[] {[]
[]template[][]< [][]class[] []X0[][] >[]
[]typename[] []F[][]<[][]const[] []X0[][]>::[][]type[]
[]operator[][]()([][]const[] []X0[][]& [][]a0[][]) [][]const[]
[] {[]
[]return[] []F[][]<[][]const[] []X0[][]>()([][]a0[][]);[]
[] }[]

[]template[][]< [][]class[] []X0[][] >[]
[]typename[] []F[][]<[][]X0[][]>::[][]type[]
[]operator[][]()([][]X0[][]& [][]a0[][]) [][]const[]
[] {[]
[]return[] []F[][]<[][]X0[][]>()([][]a0[][]);[]
[] }[]
[] };[]

[] } [][]// namespace detail[]

[]namespace[][] {[]
[]// ODRが怪しい[]
[]const[] []detail[][]::[][]function[][]<[][]meta[][]::[][]begin[][]> [][]begin[][] = { };[]
[]const[] []detail[][]::[][]function[][]<[][]meta[][]::[][]end[][]> [][]end[][] = { };[]
[] }[]

[]} [][]// namespace pstade[]


[]#include[] []<vector>[]

[]struct[] []vector_tag[][] { };[]

[]namespace[] []pstade[][] { [][]namespace[] []customization[][] {[]

[]template[][]< [][]class[] []ValueT[][] >[]
[]struct[] []tag[][]< [][]std[][]::[][]vector[][]<[][]ValueT[][]> >[]
[] {[]
[]typedef[][] ::[][]vector_tag[] []type[][];[]
[] };[]

[]template[][]< [][]class[] []VectorT[][] >[]
[]struct[] []operations[][]< [][]VectorT[][], ::[][]vector_tag[][] >[]
[] {[]
[]struct[] []begin[]
[] {[]
[]typedef[] []typename[] []VectorT[][]::[][]iterator[] []type[][];[]

[]type[] []operator[][]()([][]VectorT[][]& [][]vec[][]) [][]const[]
[] {[]
[]return[] []vec[][].[][]begin[][]();[]
[] }[]
[] };[]

[]struct[] []end[]
[] {[]
[]typedef[] []typename[] []VectorT[][]::[][]iterator[] []type[][];[]

[]type[] []operator[][]()([][]VectorT[][]& [][]vec[][]) [][]const[]
[] {[]
[]return[] []vec[][].[][]end[][]();[]
[] }[]
[] };[]
[] };[]

[]} } [][]// namespace pstade::customization[]

[]#include[] []<iostream>[]

[]void[] []polym_test[][]()[]
[]{[]
[]using[] []namespace[] []pstade[][];[]

[]std[][]::[][]vector[][]<[][]int[][]> [][]vec[][]; {[]
[]vec[][].[][]push_back[][]([][]1[][]), [][]vec[][].[][]push_back[][]([][]2[][]), [][]vec[][].[][]push_back[][]([][]3[][]);[]
[] }[]

[]typedef[] []meta[][]::[][]begin[][]< [][]std[][]::[][]vector[][]<[][]int[][]> >::[][]type[] []iter_t[][];[]
[]for[][] ([][]iter_t[] []it[][] = [][]begin[][]([][]vec[][]), [][]last[][] = [][]end[][]([][]vec[][]); [][]it[][] != [][]last[][]; ++[][]it[][]) {[]
[]std[][]::[][]cout[][] << *[][]it[][] << [][]std[][]::[][]endl[][];[]
[] }[]
[]}[]