template function help

R

Rex_chaos

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?
 
B

Buster

Rex_chaos said:
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?

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.
 
W

WW

Rex_chaos said:
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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top