diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 8f438602..c58adc42 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -126,6 +126,12 @@ namespace etl assign((void*)(&instance), const_lambda_stub); } + //************************************************************************* + // Delete construction from rvalue reference lambda or functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate(TLambda&& instance) = delete; + //************************************************************************* /// Create from function (Compile time). //************************************************************************* diff --git a/test/test_base64_RFC2152_decoder.cpp b/test/test_base64_RFC2152_decoder.cpp index 2428095e..64cc11ca 100644 --- a/test/test_base64_RFC2152_decoder.cpp +++ b/test/test_base64_RFC2152_decoder.cpp @@ -64,7 +64,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -76,6 +76,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC2152_encoder.cpp b/test/test_base64_RFC2152_encoder.cpp index bd4c2b13..f463da39 100644 --- a/test/test_base64_RFC2152_encoder.cpp +++ b/test/test_base64_RFC2152_encoder.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC3501_decoder.cpp b/test/test_base64_RFC3501_decoder.cpp index 60915724..2e3c2faf 100644 --- a/test/test_base64_RFC3501_decoder.cpp +++ b/test/test_base64_RFC3501_decoder.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC3501_encoder.cpp b/test/test_base64_RFC3501_encoder.cpp index de54cbe6..0acc36a3 100644 --- a/test/test_base64_RFC3501_encoder.cpp +++ b/test/test_base64_RFC3501_encoder.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp index bf8e177e..c1c9280d 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp index 96bd3c74..ab75c182 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp b/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp index 0b97f8c9..56835228 100644 --- a/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_encoder_with_padding.cpp b/test/test_base64_RFC4648_URL_encoder_with_padding.cpp index 90a95527..9c9f2e21 100644 --- a/test/test_base64_RFC4648_URL_encoder_with_padding.cpp +++ b/test/test_base64_RFC4648_URL_encoder_with_padding.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_decoder_with_no_padding.cpp index ea21ebcc..8fbde338 100644 --- a/test/test_base64_RFC4648_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_no_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_decoder_with_padding.cpp b/test/test_base64_RFC4648_decoder_with_padding.cpp index 6d910ecd..fef5112a 100644 --- a/test/test_base64_RFC4648_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_encoder_with_no_padding.cpp b/test/test_base64_RFC4648_encoder_with_no_padding.cpp index 2d964d80..eefe003f 100644 --- a/test/test_base64_RFC4648_encoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_encoder_with_no_padding.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_encoder_with_padding.cpp b/test/test_base64_RFC4648_encoder_with_padding.cpp index 148b1fe4..50b48b3b 100644 --- a/test/test_base64_RFC4648_encoder_with_padding.cpp +++ b/test/test_base64_RFC4648_encoder_with_padding.cpp @@ -61,8 +61,8 @@ namespace std::string encoded_output; bool received_final_block = false; - - codec::callback_type callback = [](const codec::span_type& sp) + + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_byte_stream.cpp b/test/test_byte_stream.cpp index 13d4eaaa..4d63068d 100644 --- a/test/test_byte_stream.cpp +++ b/test/test_byte_stream.cpp @@ -1318,10 +1318,12 @@ namespace static std::vector result; - etl::byte_stream_writer::callback_type callback([&](etl::byte_stream_writer::callback_parameter_type sp) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(result)); - }); + auto lambda = [&](etl::byte_stream_writer::callback_parameter_type sp) + { + std::copy(sp.begin(), sp.end(), std::back_inserter(result)); + }; + + etl::byte_stream_writer::callback_type callback(lambda); etl::byte_stream_writer writer(storage.data(), storage.size(), etl::endian::big, callback); diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index 0f9d29a8..852627e7 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -287,7 +287,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_is_valid_true) { - etl::delegate d([] {}); + auto lambda = [] {}; + + etl::delegate d(lambda); CHECK(d.is_valid()); CHECK(d); @@ -297,7 +299,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_is_valid_after_clear) { - etl::delegate d([] {}); + auto lambda = [] {}; + + etl::delegate d(lambda); CHECK_TRUE(d.is_valid()); d.clear(); @@ -413,7 +417,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_lambda_int) { - etl::delegate d([](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }); + auto lambda = [](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }; + + etl::delegate d(lambda); d(VALUE1, VALUE2);