mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
refactor usage of CONSTEXPR and NO_EXCEPT
This commit is contained in:
parent
90d2a424e5
commit
d83367c172
@ -499,7 +499,7 @@ namespace etl
|
||||
/// Returns a reference to the indexed value.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_bounds if the index is out of bounds.
|
||||
//*************************************************************************
|
||||
reference operator[](const size_t i) ETL_NOEXCEPT_INDEX_OPERATOR
|
||||
reference operator[](const size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(array_view_bounds));
|
||||
|
||||
@ -511,7 +511,7 @@ namespace etl
|
||||
/// Returns a const reference to the indexed value.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_bounds if the index is out of bounds.
|
||||
//*************************************************************************
|
||||
const_reference operator[](const size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR
|
||||
const_reference operator[](const size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(array_view_bounds));
|
||||
|
||||
|
||||
@ -270,7 +270,7 @@ namespace etl
|
||||
/// Returns a reference to the indexed value.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_wrapper_bounds if the index is out of bounds.
|
||||
//*************************************************************************
|
||||
reference operator[](size_t i) ETL_NOEXCEPT_INDEX_OPERATOR
|
||||
reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
|
||||
return ARRAY_[i];
|
||||
@ -280,10 +280,15 @@ 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_OR_ASSERT const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR
|
||||
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
// Throwing from c++11 constexpr requires special syntax
|
||||
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR
|
||||
return i < SIZE ? ARRAY_[i] : throw(ETL_ERROR(etl::array_wrapper_bounds));
|
||||
#else
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
|
||||
return ARRAY_[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -364,16 +364,6 @@ 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)
|
||||
@ -388,12 +378,10 @@ namespace etl
|
||||
#define ETL_CHECKING_INDEX_OPERATOR 1
|
||||
#define ETL_NOT_CHECKING_INDEX_OPERATOR 0
|
||||
#define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e) ETL_ASSERT(b,e)
|
||||
#define ETL_NOEXCEPT_INDEX_OPERATOR
|
||||
#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
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
|
||||
@ -191,20 +191,28 @@ 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_OR_ASSERT const_reference front() const
|
||||
ETL_CONSTEXPR const_reference front() const
|
||||
{
|
||||
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_EXTRA
|
||||
return !empty() ? *mbegin : throw(ETL_ERROR(string_view_empty));
|
||||
#else
|
||||
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(string_view_empty));
|
||||
return *mbegin;
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// 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_OR_ASSERT const_reference back() const
|
||||
ETL_CONSTEXPR const_reference back() const
|
||||
{
|
||||
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_EXTRA
|
||||
return !empty() ? *(mend - 1) : throw(ETL_ERROR(string_view_empty));
|
||||
#else
|
||||
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(string_view_empty));
|
||||
return *(mend - 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -347,10 +355,14 @@ 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_OR_ASSERT const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR
|
||||
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR
|
||||
return i < size() ? mbegin[i] : throw(ETL_ERROR(string_view_bounds));
|
||||
#else
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(string_view_bounds));
|
||||
return mbegin[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user