Using std::function with lambda captures in C++20 leads to compilation errors with template deduction
I'm building a feature where I'm relatively new to this, so bear with me... I'm writing unit tests and Quick question that's been bugging me - I've searched everywhere and can't find a clear answer..... I'm trying to use `std::function` with a lambda that captures variables, but I'm running into compilation errors in C++20. Here's a simplified version of what I've written: ```cpp #include <iostream> #include <functional> #include <vector> template <typename T> void process(std::vector<T> data, std::function<void(T)> func) { for (auto& item : data) { func(item); } } int main() { int factor = 2; std::vector<int> numbers = {1, 2, 3, 4}; auto lambda = [factor](int& n) { n *= factor; }; process(numbers, lambda); for (auto n : numbers) { std::cout << n << '\n'; } return 0; } ``` When I try to compile this code with g++ 10.2.0 using the command `g++ -std=c++20 main.cpp`, I get the following behavior: ``` incompatible type for argument of 'process': 'void (int)' instead of 'void (int&)' ``` The behavior suggests that there is a type mismatch due to the lambda capturing a variable. I've tried changing the lambda to capture by reference using `[&factor]`, but that doesn't resolve the behavior either. I also considered using `std::bind`, but I'd like to keep the lambda for simplicity. Is there a way to fix this without changing my signature for `process`? I want to continue using reference semantics for the integer, while still capturing external variables in my lambda. Any insights or workarounds would be appreciated! Any help would be greatly appreciated! For context: I'm using C++ on Windows. Any help would be greatly appreciated! Thanks, I really appreciate it! Thanks, I really appreciate it! My development environment is CentOS. My development environment is macOS. Any suggestions would be helpful.