mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-27 21:08:44 +08:00
Regression fix: Support zero arguments emplace() in etl::optional (#1183)
* Added coderabbitai configuration * Added builtin mem function tests * Modified etl::typed_storage * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Added ETL_NOEXCEPT and ETL_NOEXCEPT_IF_NO_THROW * Added etl::typed_storage_ext and swap for same * Added etl::typed_storage_ext and swap for same # Conflicts: # include/etl/alignment.h * Added release notes * Fixes to GCC -O2 errors * Changed char* parameters to value_type* parameters * Fixed compilation issues for const containers unit tests * Added automatic selection of __builtin_memxxx functions for GCC and clang * Added enhanced coderabbit configuration * Updated version and release notes * Disabled constexpr const container tests for C++11 * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Updated version and release notes * feat: removed unreachable break statements (#1169) * Updated version and release notes * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Support zero arguments emplace() in etl::optional For non-fundamental types, a recent change in etl::optional was introduced that doesn't support zero arguments emplace() anymore. This change fixes it and adds the respective test. --------- Co-authored-by: John Wellbelove <john.wellbelove@asterconsulting.co.uk> Co-authored-by: Drew Rife <darife@jlg.com>
This commit is contained in:
parent
df30de2877
commit
ea91dabee5
@ -536,6 +536,17 @@ namespace etl
|
||||
|
||||
return storage.u.value;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Emplaces with zero arguments, i.e. default construct emplace.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR20_STL
|
||||
T& emplace()
|
||||
{
|
||||
storage.construct();
|
||||
|
||||
return storage.u.value;
|
||||
}
|
||||
#else
|
||||
//*************************************************************************
|
||||
/// Emplaces a value.
|
||||
|
||||
@ -218,15 +218,27 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_emplace_zero_parameters)
|
||||
TEST(test_emplace_zero_parameters_fundamental)
|
||||
{
|
||||
etl::optional<std::uint8_t> result = 1;
|
||||
result.emplace();
|
||||
CHECK_EQUAL(0, static_cast<int>(result.emplace()));
|
||||
|
||||
CHECK_TRUE(result.has_value());
|
||||
CHECK_EQUAL(0, int(result.value()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_emplace_zero_parameters_non_fundamental)
|
||||
{
|
||||
etl::optional<std::string> result = std::string("abc");
|
||||
|
||||
std::string& ref = result.emplace();
|
||||
CHECK_EQUAL(std::string(), ref);
|
||||
CHECK_EQUAL(&ref, &result.value());
|
||||
CHECK_TRUE(result.has_value());
|
||||
CHECK_EQUAL("", std::string(result.value()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_emplace_return)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user