Skip to content

Commit

Permalink
Sync to 20.38.10
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Jan 13, 2024
1 parent 241e140 commit f3c6a31
Show file tree
Hide file tree
Showing 55 changed files with 2,053 additions and 211 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Embedded Template Library - ETL",
"name": "Embedded Template Library - Arduino",
"version": "20.38.10",
"authors": {
"name": "John Wellbelove",
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Embedded Template Library ETL
version=20.38.2
name=Embedded Template Library - Arduino
version=20.38.10
author= John Wellbelove <[email protected]>
maintainer=John Wellbelove <[email protected]>
license=MIT
Expand Down
47 changes: 45 additions & 2 deletions src/etl/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ namespace etl
//*****************************************************************************
namespace etl
{
namespace private_algorithm
{
template <bool use_swap>
struct swap_impl;

// Generic swap
template <>
struct swap_impl<false>
{
template <typename TIterator1, typename TIterator2>
static void do_swap(TIterator1 a, TIterator2 b)
{
typename etl::iterator_traits<TIterator1>::value_type tmp = *a;
*a = *b;
*b = tmp;
}
};

// Specialised swap
template <>
struct swap_impl<true>
{
template <typename TIterator1, typename TIterator2>
static void do_swap(TIterator1 a, TIterator2 b)
{
using ETL_OR_STD::swap; // Allow ADL
swap(*a, *b);
}
};
}

//***************************************************************************
// iter_swap
//***************************************************************************
Expand All @@ -99,8 +130,20 @@ namespace etl
#endif
void iter_swap(TIterator1 a, TIterator2 b)
{
using ETL_OR_STD::swap; // Allow ADL
swap(*a, *b);
typedef etl::iterator_traits<TIterator1> traits1;
typedef etl::iterator_traits<TIterator2> traits2;

typedef typename traits1::value_type v1;
typedef typename traits2::value_type v2;

typedef typename traits1::reference r1;
typedef typename traits2::reference r2;

const bool use_swap = etl::is_same<v1, v2>::value &&
etl::is_reference<r1>::value &&
etl::is_reference<r2>::value;

private_algorithm::swap_impl<use_swap>::do_swap(a, b);
}

//***************************************************************************
Expand Down
22 changes: 16 additions & 6 deletions src/etl/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ namespace etl
//*****************************************************************************
inline bool is_aligned(void* p, size_t required_alignment)
{
uintptr_t alignment = static_cast<uintptr_t>(required_alignment);
uintptr_t address = reinterpret_cast<uintptr_t>(p);
return (address % alignment) == 0U;
return (address % required_alignment) == 0U;
}

//*****************************************************************************
Expand All @@ -88,7 +87,7 @@ namespace etl
bool is_aligned(void* p)
{
uintptr_t address = reinterpret_cast<uintptr_t>(p);
return (address % static_cast<uintptr_t>(Alignment)) == 0U;
return (address % Alignment) == 0U;
}

//*****************************************************************************
Expand Down Expand Up @@ -204,13 +203,24 @@ namespace etl
{
public:

#if ETL_NOT_USING_64BIT_TYPES
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type;
#if ETL_USING_CPP11
typedef struct { alignas(Alignment) char dummy; } type;
#else
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type type;
#if ETL_NOT_USING_64BIT_TYPES
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type;
#else
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type type;
#endif
#endif

ETL_STATIC_ASSERT(etl::alignment_of<type>::value == Alignment, "Unable to create the type with the specified alignment");
};

#if ETL_USING_CPP11
template <size_t Alignment>
using type_with_alignment_t = typename type_with_alignment<Alignment>::type;
#endif

//***************************************************************************
/// Aligned storage
/// Length should be determined in terms of sizeof()
Expand Down
8 changes: 4 additions & 4 deletions src/etl/array_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,23 +421,23 @@ namespace etl
//*************************************************************************
/// Returns <b>true</b> if the array size is zero.
//*************************************************************************
bool empty() const
ETL_CONSTEXPR bool empty() const
{
return (mbegin == mend);
}

//*************************************************************************
/// Returns the size of the array.
//*************************************************************************
size_t size() const
ETL_CONSTEXPR size_t size() const
{
return (mend - mbegin);
return static_cast<size_t>(mend - mbegin);
}

//*************************************************************************
/// Returns the maximum possible size of the array.
//*************************************************************************
size_t max_size() const
ETL_CONSTEXPR size_t max_size() const
{
return size();
}
Expand Down
Loading

0 comments on commit f3c6a31

Please sign in to comment.