Add a inplace_function constructor from a nullptr (#1336)

* Add a inplace_function constructor with a nullptr argument

* Add unit test for nullptr construction

---------

Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
This commit is contained in:
Bram Meijer 2026-03-28 10:16:00 +01:00 committed by GitHub
parent f718c54396
commit 2c2ce9a39f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -572,6 +572,16 @@ namespace etl
set(f);
}
//*************************************************************************
/// Construct from a nullptr.
/// Clears the inplace_function.
/// \param nullptr_t Null pointer
//*************************************************************************
inplace_function(etl::nullptr_t) noexcept
{
clear();
}
//*************************************************************************
/// Construct from object + non-const member function (runtime).
/// \tparam TObject The object type.

View File

@ -509,6 +509,16 @@ namespace
CHECK(function_called == FunctionCalled::Free_Void_Called);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_construct_from_nullptr)
{
etl::inplace_function<void(void)> ipf(nullptr);
CHECK_FALSE(ipf.is_valid());
CHECK_FALSE(ipf);
CHECK_THROW(ipf(), etl::inplace_function_uninitialized);
}
#if ETL_USING_CPP17
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_make_free_void_compile_time)