Declare a function accepting generic iterator

后端 未结 4 700
慢半拍i
慢半拍i 2021-01-31 10:17

Given this code, is it possible to change dumpStrings() to be able to iterate over any container of string, like say a list

4条回答
  •  独厮守ぢ
    2021-01-31 10:48

    yes

    http://www.boost.org/doc/libs/1_45_0/libs/utility/enable_if.html

    http://www.cplusplus.com/reference/std/iterator/iterator_traits/

    http://www.boost.org/doc/libs/1_44_0/libs/type_traits/doc/html/boost_typetraits/reference/is_same.html

    template
    typename enable_if<
        is_same::value_type, string>
        >::type
    function(...
    

提交回复
热议问题