Answer the question
In order to leave comments, you need to log in
How to specify a lambda function as a parameter in a template function?
There is a task where you need to decompose one container into 2 others according to a condition that will be set by a lambda function.
How can I specify in the template as a parameter that this is a lambda function?
template<typename inputType,typename leftContainer,typename rightContainer>
void OddEven(inputType input,leftContainer left,rightContainer right,лямбда функция){
for(auto key:input){
if(лямбда функция(key)){
left.insert(left.end(),key);
}else{
right.insert(right.end(),key);
}
}
}
{
//Например:
std::vector<int> v{ 1,2,3,4,5 };
std::list<int> l; //сюда четные
std::deque<int> d; //а сюда нечетные
OddEven(v, l, d, [](const auto &val){val>0?true:false;});
asm("nop");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question