Skip to content

Commit

Permalink
Sync to 20.35.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jwellbelove committed Dec 8, 2022
1 parent a41f53f commit 88d0881
Show file tree
Hide file tree
Showing 151 changed files with 10,732 additions and 2,514 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Embedded Template Library - Arduino",
"version": "20.32.1",
"version": "20.35.5",
"authors": {
"name": "John Wellbelove",
"email": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Embedded Template Library - Arduino
version=20.32.1
version=20.35.5
author= John Wellbelove <[email protected]>
maintainer=John Wellbelove <[email protected]>
license=MIT
Expand Down
4 changes: 2 additions & 2 deletions src/etl/absolute.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ namespace etl
ETL_CONSTEXPR typename etl::enable_if<etl::is_signed<T>::value, TReturn>::type
absolute_unsigned(T value)
{
return (value == etl::integral_limits<T>::min) ? etl::integral_limits<TReturn>::max / 2U
: (value < T(0)) ? TReturn(-value) : TReturn(value);
return (value == etl::integral_limits<T>::min) ? (etl::integral_limits<TReturn>::max / 2U) + 1U
: (value < T(0)) ? TReturn(-value) : TReturn(value);
}

//***************************************************************************
Expand Down
46 changes: 24 additions & 22 deletions src/etl/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ SOFTWARE.
/// Additional new variants of certain algorithms.
///\ingroup utilities

#include <stdint.h>
#include <string.h>

#include "platform.h"
#include "type_traits.h"
#include "iterator.h"
#include "functional.h"
#include "utility.h"

#include <stdint.h>
#include <string.h>

#include "private/minmax_push.h"

#if ETL_USING_STL
Expand Down Expand Up @@ -183,13 +183,6 @@ namespace etl
{
return std::copy_n(sb, count, db);
}
#elif ETL_USING_STL && ETL_USING_CPP11 && !ETL_FORCE_CONSTEXPR_ALGORITHMS
// Use the STL implementation
template <typename TIterator1, typename TSize, typename TIterator2>
TIterator2 copy_n(TIterator1 sb, TSize count, TIterator2 db)
{
return std::copy_n(sb, count, db);
}
#else
// Non-pointer or not trivially copyable or not using builtin memcpy.
template <typename TIterator1, typename TSize, typename TIterator2>
Expand Down Expand Up @@ -236,12 +229,6 @@ namespace etl
{
return std::move(sb, se, db);
}
#elif ETL_USING_STL && ETL_USING_CPP11 && !ETL_FORCE_CONSTEXPR_ALGORITHMS
template <typename TIterator1, typename TIterator2>
TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db)
{
return std::move(sb, se, db);
}
#else
// non-pointer or not trivially copyable
template <typename TIterator1, typename TIterator2>
Expand All @@ -267,12 +254,6 @@ namespace etl
{
return std::move_backward(sb, se, de);
}
#elif ETL_USING_STL && ETL_USING_CPP11 && !ETL_FORCE_CONSTEXPR_ALGORITHMS
template <typename TIterator1, typename TIterator2>
TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
{
return std::move_backward(sb, se, de);
}
#else
// non-pointer or not trivially copyable
template <typename TIterator1, typename TIterator2>
Expand Down Expand Up @@ -424,6 +405,27 @@ namespace etl
etl::upper_bound(first, last, value, compare()));
}

//***************************************************************************
// binary_search
//***************************************************************************
template <typename TIterator, typename T, typename Compare>
ETL_NODISCARD
bool binary_search(TIterator first, TIterator last, const T& value, Compare compare)
{
first = etl::lower_bound(first, last, value, compare);

return (!(first == last) && !(compare(value, *first)));
}

template <typename TIterator, typename T>
ETL_NODISCARD
bool binary_search(TIterator first, TIterator last, const T& value)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;

return binary_search(first, last, value, compare());
}

//***************************************************************************
// find_if
//***************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/etl/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ SOFTWARE.
#ifndef ETL_ALIGNMENT_INCLUDED
#define ETL_ALIGNMENT_INCLUDED

#include <stdint.h>

#include "platform.h"
#include "type_traits.h"
#include "static_assert.h"

#include <stdint.h>

///\defgroup alignment alignment
/// Creates a variable of the specified type at the specified alignment.
/// \ingroup utilities
Expand Down
5 changes: 2 additions & 3 deletions src/etl/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ SOFTWARE.
#ifndef ETL_ARRAY_INCLUDED
#define ETL_ARRAY_INCLUDED

#include <stddef.h>

#include "platform.h"

#include "algorithm.h"
#include "iterator.h"
#include "functional.h"
Expand All @@ -46,6 +43,8 @@ SOFTWARE.
#include "nth_type.h"
#include "initializer_list.h"

#include <stddef.h>

///\defgroup array array
/// A replacement for std::array if you haven't got C++0x11.
///\ingroup containers
Expand Down
13 changes: 6 additions & 7 deletions src/etl/array_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ SOFTWARE.
#include "nullptr.h"
#include "hash.h"
#include "algorithm.h"
#include "memory.h"
#include "type_traits.h"

#if ETL_USING_CPP11 && ETL_USING_STL
#if ETL_USING_STL && ETL_USING_CPP11
#include <array>
#endif

Expand Down Expand Up @@ -155,7 +154,7 @@ namespace etl
/// Construct from etl::array.
//*************************************************************************
template <typename U, size_t N>
ETL_CONSTEXPR array_view(etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
ETL_CONSTEXPR array_view(etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
{
Expand All @@ -165,14 +164,14 @@ namespace etl
/// Construct from etl::array.
//*************************************************************************
template <typename U, size_t N>
ETL_CONSTEXPR array_view(const etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
ETL_CONSTEXPR array_view(const etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
{
}
#endif

#if ETL_USING_CPP11 && ETL_USING_STL
#if ETL_USING_STL && ETL_USING_CPP11
//*************************************************************************
/// Construct from std::array.
//*************************************************************************
Expand Down Expand Up @@ -215,7 +214,7 @@ namespace etl
template <typename TContainer>
ETL_CONSTEXPR array_view(TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
!etl::is_array<TContainer>::value &&
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type) ETL_NOEXCEPT
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
{
Expand All @@ -228,7 +227,7 @@ namespace etl
template <typename TContainer>
ETL_CONSTEXPR array_view(const TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
!etl::is_array<TContainer>::value &&
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type) ETL_NOEXCEPT
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
{
Expand Down
14 changes: 14 additions & 0 deletions src/etl/atomic/atomic_gcc_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ SOFTWARE.
#include <stdint.h>
#include <string.h>

// Select the amtomic builtins based on the ARM5 version of the GCC compiler.
#if defined(ETL_COMPILER_ARM5)
#define ETL_USE_SYNC_BUILTINS
#endif

// Select the amtomic builtins based on the ARM6 version of the GCC compiler.
#if defined(ETL_COMPILER_ARM6)
#if ETL_COMPILER_FULL_VERSION >= 40700
#define ETL_USE_ATOMIC_BUILTINS
#else
#define ETL_USE_SYNC_BUILTINS
#endif
#endif

// Select the amtomic builtins based on the version of the GCC compiler.
#if defined(ETL_COMPILER_GCC)
#if ETL_COMPILER_FULL_VERSION >= 40700
Expand Down
9 changes: 4 additions & 5 deletions src/etl/basic_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ SOFTWARE.
#ifndef ETL_BASIC_STRING_INCLUDED
#define ETL_BASIC_STRING_INCLUDED

#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include "platform.h"

#include "algorithm.h"
#include "iterator.h"
#include "functional.h"
Expand All @@ -53,6 +48,10 @@ SOFTWARE.
#include "binary.h"
#include "flags.h"

#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include "private/minmax_push.h"

//*****************************************************************************
Expand Down
39 changes: 37 additions & 2 deletions src/etl/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ namespace etl
ETL_CONSTEXPR14 bool has_zero_byte(TValue value)
{
typedef typename etl::make_unsigned<TValue>::type unsigned_t;
const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU);
ETL_CONSTEXPR14 const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU);
const unsigned_t temp = unsigned_t(~((((unsigned_t(value) & mask) + mask) | unsigned_t(value)) | mask));

return (temp != 0U);
Expand All @@ -455,7 +455,7 @@ namespace etl
ETL_CONSTEXPR14 bool has_zero_byte()
{
typedef typename etl::make_unsigned<TValue>::type unsigned_t;
const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU);
ETL_CONSTEXPR14 const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU);
const unsigned_t temp = unsigned_t(~((((unsigned_t(N) & mask) + mask) | unsigned_t(N)) | mask));

return (temp != 0U);
Expand Down Expand Up @@ -2181,6 +2181,41 @@ namespace etl
return ((static_cast<typename etl::make_unsigned<T>::type>(value) & 1U) == 0U);
}

//***********************************
template <typename T, size_t NBits>
class lsb_mask
{
public:

static ETL_CONSTANT T value = static_cast<T>(etl::max_value_for_nbits<NBits>::value);
};

//***********************************
template <typename T>
ETL_CONSTEXPR14 T make_lsb_mask(size_t nbits)
{
typedef typename etl::make_unsigned<T>::type type;

return (nbits == etl::integral_limits<type>::bits) ? static_cast<T>(etl::integral_limits<type>::max)
: static_cast<T>((static_cast<type>(1U) << nbits) - 1U);
};

//***********************************
template <typename T, size_t NBits>
class msb_mask
{
public:

static ETL_CONSTANT T value = static_cast<T>(etl::reverse_bits_const<T, lsb_mask<T, NBits>::value>::value);
};

//***********************************
template <typename T>
ETL_CONSTEXPR T make_msb_mask(size_t nbits)
{
return static_cast<T>(etl::reverse_bits(make_lsb_mask<T>(nbits)));
};

//***************************************************************************
/// 8 bit binary byte constants.
///\ingroup binary
Expand Down
6 changes: 3 additions & 3 deletions src/etl/bip_buffer_spsc_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ SOFTWARE.
#ifndef ETL_BIP_BUFFER_SPSC_ATOMIC_INCLUDED
#define ETL_BIP_BUFFER_SPSC_ATOMIC_INCLUDED

#include <stddef.h>
#include <stdint.h>

#include "platform.h"
#include "alignment.h"
#include "parameter_type.h"
Expand All @@ -53,6 +50,9 @@ SOFTWARE.
#include "span.h"
#include "file_error_numbers.h"

#include <stddef.h>
#include <stdint.h>

#if ETL_HAS_ATOMIC

namespace etl
Expand Down
28 changes: 21 additions & 7 deletions src/etl/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,30 @@ SOFTWARE.
#ifndef ETL_BIT_INCLUDED
#define ETL_BIT_INCLUDED

#include <string.h>

#include "platform.h"
#include "type_traits.h"
#include "binary.h"
#include "integral_limits.h"
#include "endianness.h"
#include "type_traits.h"

#include <string.h>

#if ETL_USING_CPP20 && ETL_USING_STL
#include <bit>
#endif

namespace etl
{
//***************************************************************************
/// bit_cast
/// bit_cast - Type to different type.
//***************************************************************************
template <typename TDestination, typename TSource>
ETL_CONSTEXPR14
typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) &&
etl::is_trivially_copyable<TSource>::value &&
etl::is_trivially_copyable<TDestination>::value, TDestination>::type
ETL_NODISCARD
typename etl::enable_if<!(etl::is_integral<TDestination>::value&& etl::is_integral<TSource>::value) &&
(sizeof(TDestination) == sizeof(TSource)) &&
etl::is_trivially_copyable<TSource>::value &&
etl::is_trivially_copyable<TDestination>::value, TDestination>::type
bit_cast(const TSource& source) ETL_NOEXCEPT
{
TDestination destination;
Expand All @@ -63,6 +64,19 @@ namespace etl
return destination;
}

//***************************************************************************
/// bit_cast - Integral to integral
//***************************************************************************
template <typename TDestination, typename TSource>
ETL_NODISCARD
ETL_CONSTEXPR14
typename etl::enable_if<(etl::is_integral<TDestination>::value && etl::is_integral<TSource>::value) &&
(sizeof(TDestination) == sizeof(TSource)), TDestination>::type
bit_cast(const TSource& source) ETL_NOEXCEPT
{
return static_cast<TDestination>(source);
}

//***************************************************************************
/// byteswap
//***************************************************************************
Expand Down
Loading

0 comments on commit 88d0881

Please sign in to comment.