File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313#include < boost/core/lightweight_test.hpp>
1414#include < boost/core/lightweight_test_trait.hpp>
1515
16- #include < functional>
16+ #include < array>
17+ #include < cstdint>
1718#include < memory>
1819#include < type_traits>
1920
@@ -845,11 +846,39 @@ static void test_conv()
845846 }
846847}
847848
849+ static void test_mutable_lambda ()
850+ {
851+ {
852+ // Within SBO limits.
853+ int captured = 0 ;
854+ move_only_function<int ()> func = [captured]() mutable { return ++captured; };
855+
856+ BOOST_TEST_EQ ( func (), 1 );
857+ BOOST_TEST_EQ ( func (), 2 );
858+
859+ move_only_function<int ()> func2 (std::move (func));
860+ BOOST_TEST_EQ ( func2 (), 3 );
861+ }
862+
863+ {
864+ // Too large for SBO.
865+ std::array<std::uint8_t , 256 > captured = {{}};
866+ move_only_function<int ()> func = [captured]() mutable { return ++captured[0 ]; };
867+
868+ BOOST_TEST_EQ ( func (), 1 );
869+ BOOST_TEST_EQ ( func (), 2 );
870+
871+ move_only_function<int ()> func2 (std::move (func));
872+ BOOST_TEST_EQ ( func2 (), 3 );
873+ }
874+ }
875+
848876int main ()
849877{
850878 test_call ();
851879 test_traits ();
852880 test_conv ();
881+ test_mutable_lambda ();
853882
854883 return boost::report_errors ();
855884}
You can’t perform that action at this time.
0 commit comments