How to create a lambda function that accepts iterators for vector,list,array?
Something like:
auto do_somthing=[](iterator beg,iterator end){
//code here
}
If you use C++14, generalized lambdas will solve your problem nicely.
auto do_something = [](auto begin, auto end) {
// code here
};
int x[]{ 1, 2, 3, 4 };
do_something(std::begin(x), std::end(x));
std::set<int> s{3, 4, 12, 55, 98 };
do_something(std::begin(s), std::end(s));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With