I need to create an iterator only for member element to iterate through container.
For example:
class A { int x; char y; };
std::vector<A> mycoll = {{10,'a'}, {20,'b'}, {30,'c'} };
Here mycoll.begin()
will give me iterator of type A
But I require to write iterator to iterate over specific member ( say x A.x
) and let int_ite
be the iterator for that integer.
Then I require
*(int_ite.begin() )
to return 10
*(++int_ite.begin() )
to return 20
and so on
also .end()
would give end of iteration.
Is there any elegant way to create such an iterator?
I require it to pass it to std::lower_bound()