boost::iterator_castとauto_base

  • Boost.RangeExに含まれ、Boost.IteratorIterator adaptorの元になったiteratorを取り出します
    • auto_baseはcast先の型としてauto_baseを渡す関数の仮引数の型を使います
  • 実装は、「cast先の型と一致するまで、再帰的にbase()メンバ関数を呼び出す」ということをします
  • 元になったiteratorの型が分からない場合は使えません
    • そのような実装も書けますが、意図しないレベルまでbase()を辿ってしまう危険もあります
  • VC6では使えません
    • 使える実装を書きました・・・ここのutilityフォルダ (auto_baseはやはり使えません)


[]{[]
[]using[] []namespace[] []biscuit[][];[]

[]typedef[] []boost[][]::[][]range_iterator[][]<[][]std[][]::[][]string[][]>::[][]type[] []src_iter_t[][];[]
[]typedef[] []boost[][]::[][]transform_iterator[][]<[][]to_upper[][]<[][]char[][]>, [][]src_iter_t[][]> [][]dst_iter_t0[][];[]
[]typedef[] []boost[][]::[][]transform_iterator[][]<[][]to_lower[][]<[][]char[][]>, [][]dst_iter_t0[][]> [][]dst_iter_t1[][]; []
[]typedef[] []filter_iterator[][]<[][]not_[][]<[][]space[][]>, [][]dst_iter_t1[][], [][]null_state_type[][]> [][]dst_iter_t2[][]; []
[]typedef[] []boost[][]::[][]transform_iterator[][]<[][]to_lower[][]<[][]char[][]>, [][]dst_iter_t2[][]> [][]dst_iter_t3[][]; []

[]std[][]::[][]string[] []str[][]([][]"hello, base!"[][]);[]
[]src_iter_t[] []x[][] = [][]boost[][]::[][]begin[][]([][]str[][]);[]
[]dst_iter_t0[] []t0[][]([][]x[][]);[]
[]dst_iter_t1[] []t1[][]([][]t0[][]);[]
[]dst_iter_t2[] []t2[][]([][]t1[][], [][]t1[][], &[][]null_state[][]);[]
[]dst_iter_t3[] []t3[][]([][]t2[][]);[]

[]BOOST_ASSERT[][]( [][]x[][] == [][]boost[][]::[][]iterator_cast[][]<[][]src_iter_t[][]>([][]t3[][]) );[]
[]}[]