template function help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rex_chaos

    template function help

    Hi all,
    suppose A is an array. With the help of template function
    find_first_of and find_end, I got two desired elements of array. How
    can I tell the distance between these two elements?
  • Buster

    #2
    Re: template function help


    "Rex_chaos" <rex_chaos@21cn .com> wrote in message
    news:f7a7417.03 10021111.58cba3 e6@posting.goog le.com...[color=blue]
    > Hi all,
    > suppose A is an array. With the help of template function
    > find_first_of and find_end, I got two desired elements of array. How
    > can I tell the distance between these two elements?[/color]

    If two pointers both point to objects in the same array, you can
    subtract one from the other to get the distance. More generally,
    the same syntax works for any pair of random-access iterators
    to objects in the same container. Even more generally, look up
    the standard C++ function 'std::distance' .

    Regards,
    Buster.


    Comment

    • WW

      #3
      Re: template function help

      Rex_chaos wrote:[color=blue]
      > Hi all,
      > suppose A is an array. With the help of template function
      > find_first_of and find_end, I got two desired elements of array. How
      > can I tell the distance between these two elements?[/color]

      With the std::distance function for example. Or if it is an array and will
      always be an array you can simple subtract the begining from the end
      pointer.

      --
      WW aka Attila


      Comment

      Working...