rename new constexpr macro and make it global

This commit is contained in:
danielsbsantos 2026-03-09 18:01:22 +00:00
parent b7c4ad03c3
commit edd0512fda
No known key found for this signature in database
3 changed files with 14 additions and 8 deletions

View File

@ -280,7 +280,7 @@ namespace etl
/// Returns a const reference to the indexed value.
/// If asserts or exceptions are enabled, throws an etl::array_wrapper_bounds if the index is out of bounds.
//*************************************************************************
ETL_CONSTEXPR_INDEX_OPERATOR const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR
ETL_CONSTEXPR_OR_ASSERT const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR
{
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
return ARRAY_[i];

View File

@ -364,6 +364,16 @@ namespace etl
#endif
#endif
//*************************************
// ETL_CONSTEXPR_INDEX_OPERATOR: constexpr if asserts are no-ops, constexpr14 when they contain statements.
#if defined(ETL_NO_CHECKS)
#define ETL_CONSTEXPR_OR_ASSERT ETL_CONSTEXPR
#elif defined(ETL_USE_ASSERT_FUNCTION) || ETL_USING_EXCEPTIONS || defined(ETL_LOG_ERRORS) || ETL_IS_DEBUG_BUILD
#define ETL_CONSTEXPR_OR_ASSERT ETL_CONSTEXPR14
#else
#define ETL_CONSTEXPR_OR_ASSERT ETL_CONSTEXPR
#endif
//*************************************
#if defined(ETL_CHECK_PUSH_POP)
#define ETL_ASSERT_CHECK_PUSH_POP(b, e) ETL_ASSERT(b, e)
@ -379,13 +389,11 @@ namespace etl
#define ETL_NOT_CHECKING_INDEX_OPERATOR 0
#define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e) ETL_ASSERT(b,e)
#define ETL_NOEXCEPT_INDEX_OPERATOR
#define ETL_CONSTEXPR_INDEX_OPERATOR ETL_CONSTEXPR14
#else
#define ETL_CHECKING_INDEX_OPERATOR 0
#define ETL_NOT_CHECKING_INDEX_OPERATOR 1
#define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e)
#define ETL_NOEXCEPT_INDEX_OPERATOR ETL_NOEXCEPT
#define ETL_CONSTEXPR_INDEX_OPERATOR ETL_CONSTEXPR
#endif
//*************************************
@ -393,12 +401,10 @@ namespace etl
#define ETL_CHECKING_EXTRA 1
#define ETL_NOT_CHECKING_EXTRA 0
#define ETL_ASSERT_CHECK_EXTRA(b, e) ETL_ASSERT(b,e)
#define ETL_CONSTEXPR_CHECK_EXTRA ETL_CONSTEXPR14
#else
#define ETL_CHECKING_EXTRA 0
#define ETL_NOT_CHECKING_EXTRA 1
#define ETL_ASSERT_CHECK_EXTRA(b, e)
#define ETL_CONSTEXPR_CHECK_EXTRA ETL_CONSTEXPR
#endif
//*************************************

View File

@ -191,7 +191,7 @@ namespace etl
/// Returns a const reference to the first element.
/// If asserts or exceptions are enabled, throws an etl::string_view_empty if the view is empty.
//*************************************************************************
ETL_CONSTEXPR_CHECK_EXTRA const_reference front() const
ETL_CONSTEXPR_OR_ASSERT const_reference front() const
{
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(string_view_empty));
return *mbegin;
@ -201,7 +201,7 @@ namespace etl
/// Returns a const reference to the last element.
/// If asserts or exceptions are enabled, throws an etl::string_view_empty if the view is empty.
//*************************************************************************
ETL_CONSTEXPR_CHECK_EXTRA const_reference back() const
ETL_CONSTEXPR_OR_ASSERT const_reference back() const
{
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(string_view_empty));
return *(mend - 1);
@ -347,7 +347,7 @@ namespace etl
/// Returns a const reference to the indexed value.
/// If asserts or exceptions are enabled, throws an etl::string_view_bounds if the index is out of bounds.
//*************************************************************************
ETL_CONSTEXPR_INDEX_OPERATOR const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR
ETL_CONSTEXPR_OR_ASSERT const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR
{
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(string_view_bounds));
return mbegin[i];