-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
boost::compat::move_only_function appears to differ from std::move_only_function when used with a mutable lamba that modifies captured variables. Specifically, the captured value appears to revert to its initial state each time the wrapped function is called, instead of preserving the new state as one would expect.
This can be demonstrated with the following program:
#include <boost/compat/move_only_function.hpp>
#include <iostream>
template<typename Sig>
using move_only_function = boost::compat::move_only_function<Sig>;
// For comparison:
// using move_only_function = std::move_only_function<Sig>;
int main()
{
int captured = 0;
move_only_function<int()> func = [captured]() mutable { return ++captured; };
int result = func();
std::cout << "Result 1: " << result << "\n";
result = func();
std::cout << "Result 2: " << result << "\n";
}
Output with the Boost version:
Result 1: 1
Result 2: 1
Output with the std version:
Result 1: 1
Result 2: 2
Tested with Boost 1.90.0 using gcc 13.3.0 on Ubuntu 24.04.
Metadata
Metadata
Assignees
Labels
No labels