From 01f7cf2b177ae6b98bc788a87de5f5cc242cea21 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 15 Apr 2025 19:50:31 +0100 Subject: [PATCH] C++11 compatibility updates --- include/etl/tuple.h | 20 ++++++++--------- test/test_tuple.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/include/etl/tuple.h b/include/etl/tuple.h index bcc5bf51..2b15e017 100644 --- a/include/etl/tuple.h +++ b/include/etl/tuple.h @@ -775,7 +775,7 @@ namespace etl using tuple_type = etl::nth_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward>>(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } //*************************************************************************** @@ -794,7 +794,7 @@ namespace etl using tuple_type = const etl::nth_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward>>(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } //*************************************************************************** @@ -811,10 +811,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = etl::private_tuple::tuple_type_base_t>&; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return static_cast(t).get_value(); } //*************************************************************************** @@ -831,10 +831,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = const etl::private_tuple::tuple_type_base_t>&; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return static_cast(t).get_value(); } //*************************************************************************** @@ -851,10 +851,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = etl::private_tuple::tuple_type_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } //*************************************************************************** @@ -871,10 +871,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = const etl::private_tuple::tuple_type_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } #if ETL_USING_CPP17 diff --git a/test/test_tuple.cpp b/test/test_tuple.cpp index d1a003a5..c794c116 100644 --- a/test/test_tuple.cpp +++ b/test/test_tuple.cpp @@ -239,7 +239,7 @@ namespace } //************************************************************************* - TEST(test_get) + TEST(test_get_using_index_lvalue) { etl::tuple data(Data("1"), DataM("3")); const etl::tuple const_data(Data("2"), DataM("4")); @@ -255,6 +255,57 @@ namespace CHECK_EQUAL(std::string("4"), d3.value); } + //************************************************************************* + TEST(test_get_using_index_rvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data&& d0 = etl::get<0>(etl::move(data)); + const Data&& d1 = etl::get<0>(etl::move(const_data)); + DataM&& d2 = etl::move(etl::get<1>(etl::move(data))); + const DataM&& d3 = etl::move(etl::get<1>(etl::move(const_data))); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_get_using_type_lvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data d0 = etl::get(data); + Data d1 = etl::get(const_data); + DataM d2 = etl::move(etl::get(data)); + DataM d3 = etl::move(etl::get(const_data)); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_get_using_type_rvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data&& d0 = etl::get(etl::move(data)); + const Data&& d1 = etl::get(etl::move(const_data)); + DataM&& d2 = etl::move(etl::get(etl::move(data))); + const DataM&& d3 = etl::move(etl::get(etl::move(const_data))); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + //************************************************************************* TEST(test_construct_from_pair) {