mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Merge remote-tracking branch 'origin/development'
This commit is contained in:
parent
0b0ce2645b
commit
2e0980420b
@ -101,6 +101,8 @@
|
||||
<sRunDeb>0</sRunDeb>
|
||||
<sLrtime>0</sLrtime>
|
||||
<bEvRecOn>1</bEvRecOn>
|
||||
<bSchkAxf>0</bSchkAxf>
|
||||
<bTchkAxf>0</bTchkAxf>
|
||||
<nTsel>5</nTsel>
|
||||
<sDll></sDll>
|
||||
<sDllPa></sDllPa>
|
||||
|
||||
@ -10,13 +10,13 @@
|
||||
<TargetName>Target 1</TargetName>
|
||||
<ToolsetNumber>0x4</ToolsetNumber>
|
||||
<ToolsetName>ARM-ADS</ToolsetName>
|
||||
<pCCUsed>6070000::V6.7::.\ARMCLANG</pCCUsed>
|
||||
<uAC6>1</uAC6>
|
||||
<pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed>
|
||||
<uAC6>0</uAC6>
|
||||
<TargetOption>
|
||||
<TargetCommonOption>
|
||||
<Device>STM32F401RETx</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F4xx_DFP.2.11.0</PackID>
|
||||
<PackID>Keil.STM32F4xx_DFP.2.13.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack</PackURL>
|
||||
<Cpu>IRAM(0x20000000,0x18000) IROM(0x08000000,0x80000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
@ -311,7 +311,7 @@
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>7</Optim>
|
||||
<Optim>1</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
@ -320,10 +320,11 @@
|
||||
<PlainCh>1</PlainCh>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<wLevel>3</wLevel>
|
||||
<wLevel>2</wLevel>
|
||||
<uThumb>0</uThumb>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<uC99>1</uC99>
|
||||
<uGnu>0</uGnu>
|
||||
<useXO>0</useXO>
|
||||
<v6Lang>3</v6Lang>
|
||||
<v6LangP>3</v6LangP>
|
||||
@ -421,8 +422,8 @@
|
||||
</api>
|
||||
</apis>
|
||||
<components>
|
||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.0.2" condition="ARMv6_7_8-M Device">
|
||||
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.1.1"/>
|
||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.1.2" condition="ARMv6_7_8-M Device">
|
||||
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.4.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
@ -439,8 +440,8 @@
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.0" condition="STM32F4 CMSIS">
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.3" url="http://www.keil.com/pack" vendor="Keil" version="2.11.0"/>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.2" condition="STM32F4 CMSIS">
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.3" url="http://www.keil.com/pack" vendor="Keil" version="2.13.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
@ -449,16 +450,16 @@
|
||||
<files>
|
||||
<file attr="config" category="source" condition="STM32F401xE_ARMCC" name="Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\arm\startup_stm32f401xe.s" version="2.6.0">
|
||||
<instance index="0">RTE\Device\STM32F401RETx\startup_stm32f401xe.s</instance>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.0" condition="STM32F4 CMSIS"/>
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.3" url="http://www.keil.com/pack" vendor="Keil" version="2.11.0"/>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.2" condition="STM32F4 CMSIS"/>
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.3" url="http://www.keil.com/pack" vendor="Keil" version="2.13.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</file>
|
||||
<file attr="config" category="source" name="Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c" version="2.6.0">
|
||||
<instance index="0">RTE\Device\STM32F401RETx\system_stm32f4xx.c</instance>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.0" condition="STM32F4 CMSIS"/>
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.3" url="http://www.keil.com/pack" vendor="Keil" version="2.11.0"/>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.2" condition="STM32F4 CMSIS"/>
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.3" url="http://www.keil.com/pack" vendor="Keil" version="2.13.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
|
||||
@ -2,14 +2,13 @@
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
#define ETL_CHECK_PUSH_POP
|
||||
#define ETL_ISTRING_REPAIR_ENABLE
|
||||
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||
#define ETL_IN_UNIT_TEST
|
||||
#define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK
|
||||
#define ETL_NO_STL
|
||||
|
||||
#if (__CC_ARM == 1)
|
||||
// ARM5 compiler
|
||||
|
||||
@ -33,12 +33,14 @@ SOFTWARE.
|
||||
#include "../type_traits.h"
|
||||
#include "../static_assert.h"
|
||||
#include "../nullptr.h"
|
||||
#include "../char_traits.h"
|
||||
|
||||
//#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(ETL_COMPILER_GCC)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -785,6 +787,8 @@ namespace etl
|
||||
typedef etl::atomic<uintmax_t> atomic_uintmax_t;
|
||||
}
|
||||
|
||||
#if defined(ETL_COMPILER_GCC)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
785
include/etl/atomic/atomic_llvm_sync.h
Normal file
785
include/etl/atomic/atomic_llvm_sync.h
Normal file
@ -0,0 +1,785 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ATOMIC_LLVM_SYNC_INCLUDED
|
||||
#define ETL_ATOMIC_LLVM_SYNC_INCLUDED
|
||||
|
||||
//#include "../platform.h"
|
||||
//#include "../type_traits.h"
|
||||
//#include "../static_assert.h"
|
||||
//#include "../nullptr.h"
|
||||
//#include "../char_traits.h"
|
||||
//
|
||||
//#include <stdint.h>
|
||||
//
|
||||
//namespace etl
|
||||
//{
|
||||
// //***************************************************************************
|
||||
// // Atomic type for pre C++11 GCC compilers that support the builtin '__sync' functions.
|
||||
// // Only integral and pointer types are supported.
|
||||
// //***************************************************************************
|
||||
//
|
||||
// typedef enum memory_order
|
||||
// {
|
||||
// memory_order_relaxed,
|
||||
// memory_order_consume,
|
||||
// memory_order_acquire,
|
||||
// memory_order_release,
|
||||
// memory_order_acq_rel,
|
||||
// memory_order_seq_cst
|
||||
// } memory_order;
|
||||
//
|
||||
// template <typename T>
|
||||
// class atomic
|
||||
// {
|
||||
// public:
|
||||
//
|
||||
// ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
|
||||
//
|
||||
// atomic()
|
||||
// : value(0)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// atomic(T v)
|
||||
// : value(v)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// // Assignment
|
||||
// T operator =(T v)
|
||||
// {
|
||||
// store(v);
|
||||
//
|
||||
// return v;
|
||||
// }
|
||||
//
|
||||
// T operator =(T v) volatile
|
||||
// {
|
||||
// store(v);
|
||||
//
|
||||
// return v;
|
||||
// }
|
||||
//
|
||||
// // Pre-increment
|
||||
// T operator ++()
|
||||
// {
|
||||
// return fetch_add(1) + 1;
|
||||
// }
|
||||
//
|
||||
// T operator ++() volatile
|
||||
// {
|
||||
// return fetch_add(1) + 1;
|
||||
// }
|
||||
//
|
||||
// // Post-increment
|
||||
// T operator ++(int)
|
||||
// {
|
||||
// return fetch_add(1);
|
||||
// }
|
||||
//
|
||||
// T operator ++(int) volatile
|
||||
// {
|
||||
// return fetch_add(1);
|
||||
// }
|
||||
//
|
||||
// // Pre-decrement
|
||||
// T operator --()
|
||||
// {
|
||||
// return fetch_sub(1) + 1;
|
||||
// }
|
||||
//
|
||||
// T operator --() volatile
|
||||
// {
|
||||
// return fetch_sub(1) + 1;
|
||||
// }
|
||||
//
|
||||
// // Post-decrement
|
||||
// T operator --(int)
|
||||
// {
|
||||
// return fetch_sub(1);
|
||||
// }
|
||||
//
|
||||
// T operator --(int) volatile
|
||||
// {
|
||||
// return fetch_sub(1);
|
||||
// }
|
||||
//
|
||||
// // Add
|
||||
// T operator +=(T v)
|
||||
// {
|
||||
// return fetch_add(v) + v;
|
||||
// }
|
||||
//
|
||||
// T operator +=(T v) volatile
|
||||
// {
|
||||
// return fetch_add(v) + v;
|
||||
// }
|
||||
//
|
||||
// // Subtract
|
||||
// T operator -=(T v)
|
||||
// {
|
||||
// return fetch_sub(v) - v;
|
||||
// }
|
||||
//
|
||||
// T operator -=(T v) volatile
|
||||
// {
|
||||
// return fetch_sub(v) - v;
|
||||
// }
|
||||
//
|
||||
// // And
|
||||
// T operator &=(T v)
|
||||
// {
|
||||
// return fetch_and(v) & v;
|
||||
// }
|
||||
//
|
||||
// T operator &=(T v) volatile
|
||||
// {
|
||||
// return fetch_and(v) & v;
|
||||
// }
|
||||
//
|
||||
// // Or
|
||||
// T operator |=(T v)
|
||||
// {
|
||||
// return fetch_or(v) | v;
|
||||
// }
|
||||
//
|
||||
// T operator |=(T v) volatile
|
||||
// {
|
||||
// return fetch_or(v) | v;
|
||||
// }
|
||||
//
|
||||
// // Exclusive or
|
||||
// T operator ^=(T v)
|
||||
// {
|
||||
// return fetch_xor(v) ^ v;
|
||||
// }
|
||||
//
|
||||
// T operator ^=(T v) volatile
|
||||
// {
|
||||
// return fetch_xor(v) ^ v;
|
||||
// }
|
||||
//
|
||||
// // Conversion operator
|
||||
// operator T () const
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// operator T() volatile const
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// // Is lock free?
|
||||
// bool is_lock_free() const
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool is_lock_free() const volatile
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// // Store
|
||||
// void store(T v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// void store(T v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Load
|
||||
// T load(etl::memory_order order = etl::memory_order_seq_cst) const
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// T load(etl::memory_order order = etl::memory_order_seq_cst) const volatile
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// // Fetch add
|
||||
// T fetch_add(T v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, v);
|
||||
// }
|
||||
//
|
||||
// T fetch_add(T v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Fetch subtract
|
||||
// T fetch_sub(T v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_fetch_and_sub(&value, v);
|
||||
// }
|
||||
//
|
||||
// T fetch_sub(T v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_fetch_and_sub(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Fetch or
|
||||
// T fetch_or(T v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_fetch_and_or(&value, v);
|
||||
// }
|
||||
//
|
||||
// T fetch_or(T v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_fetch_and_or(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Fetch and
|
||||
// T fetch_and(T v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_fetch_and_and(&value, v);
|
||||
// }
|
||||
//
|
||||
// T fetch_and(T v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_fetch_and_and(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Fetch exclusive or
|
||||
// T fetch_xor(T v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_fetch_and_xor(&value, v);
|
||||
// }
|
||||
//
|
||||
// T fetch_xor(T v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_fetch_and_xor(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Exchange
|
||||
// T exchange(T v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// T exchange(T v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Compare exchange weak
|
||||
// bool compare_exchange_weak(T& expected, T desired, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// T old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_weak(T& expected, T desired, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// T old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_weak(T& expected, T desired, etl::memory_order success, etl::memory_order failure)
|
||||
// {
|
||||
// T old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_weak(T& expected, T desired, etl::memory_order success, etl::memory_order failure) volatile
|
||||
// {
|
||||
// T old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Compare exchange strong
|
||||
// bool compare_exchange_strong(T& expected, T desired, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// T old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_strong(T& expected, T desired, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// T old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_strong(T& expected, T desired, etl::memory_order success, etl::memory_order failure)
|
||||
// {
|
||||
// T old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_strong(T& expected, T desired, etl::memory_order success, etl::memory_order failure) volatile
|
||||
// {
|
||||
// T old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// private:
|
||||
//
|
||||
// atomic& operator =(const atomic&);
|
||||
// atomic& operator =(const atomic&) volatile;
|
||||
//
|
||||
// mutable volatile T value;
|
||||
// };
|
||||
//
|
||||
// template <typename T>
|
||||
// class atomic<T*>
|
||||
// {
|
||||
// public:
|
||||
//
|
||||
// atomic()
|
||||
// : value(nullptr)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// atomic(T* v)
|
||||
// : value(v)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// // Assignment
|
||||
// T* operator =(T* v)
|
||||
// {
|
||||
// store(v);
|
||||
//
|
||||
// return v;
|
||||
// }
|
||||
//
|
||||
// T* operator =(T* v) volatile
|
||||
// {
|
||||
// store(v);
|
||||
//
|
||||
// return v;
|
||||
// }
|
||||
//
|
||||
// // Pre-increment
|
||||
// T* operator ++()
|
||||
// {
|
||||
// return fetch_add(1) + 1;
|
||||
// }
|
||||
//
|
||||
// T* operator ++() volatile
|
||||
// {
|
||||
// return fetch_add(1) + 1;
|
||||
// }
|
||||
//
|
||||
// // Post-increment
|
||||
// T* operator ++(int)
|
||||
// {
|
||||
// return fetch_add(1);
|
||||
// }
|
||||
//
|
||||
// T* operator ++(int) volatile
|
||||
// {
|
||||
// return fetch_add(1);
|
||||
// }
|
||||
//
|
||||
// // Pre-decrement
|
||||
// T* operator --()
|
||||
// {
|
||||
// return fetch_sub(1) + 1;
|
||||
// }
|
||||
//
|
||||
// T* operator --() volatile
|
||||
// {
|
||||
// return fetch_sub(1) + 1;
|
||||
// }
|
||||
//
|
||||
// // Post-decrement
|
||||
// T* operator --(int)
|
||||
// {
|
||||
// return fetch_sub(1);
|
||||
// }
|
||||
//
|
||||
// T* operator --(int) volatile
|
||||
// {
|
||||
// return fetch_sub(1);
|
||||
// }
|
||||
//
|
||||
// // Add
|
||||
// T* operator +=(ptrdiff_t v)
|
||||
// {
|
||||
// return fetch_add(v) + v;
|
||||
// }
|
||||
//
|
||||
// T* operator +=(ptrdiff_t v) volatile
|
||||
// {
|
||||
// return fetch_add(v) + v;
|
||||
// }
|
||||
//
|
||||
// // Subtract
|
||||
// T* operator -=(ptrdiff_t v)
|
||||
// {
|
||||
// return fetch_sub(v) - v;
|
||||
// }
|
||||
//
|
||||
// T* operator -=(ptrdiff_t v) volatile
|
||||
// {
|
||||
// return fetch_sub(v) - v;
|
||||
// }
|
||||
//
|
||||
// // Conversion operator
|
||||
// operator T* () const
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// operator T*() volatile const
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// // Is lock free?
|
||||
// bool is_lock_free() const
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool is_lock_free() const volatile
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// // Store
|
||||
// void store(T* v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// void store(T* v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Load
|
||||
// T* load(etl::memory_order order = etl::memory_order_seq_cst) const
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// T* load(etl::memory_order order = etl::memory_order_seq_cst) const volatile
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, 0);
|
||||
// }
|
||||
//
|
||||
// // Fetch add
|
||||
// T* fetch_add(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, v);
|
||||
// }
|
||||
//
|
||||
// T* fetch_add(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_fetch_and_add(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Fetch subtract
|
||||
// T* fetch_sub(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_fetch_and_sub(&value, v);
|
||||
// }
|
||||
//
|
||||
// T* fetch_sub(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_fetch_and_sub(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Exchange
|
||||
// T* exchange(T* v, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// return __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// T* exchange(T* v, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// return __sync_lock_test_and_set(&value, v);
|
||||
// }
|
||||
//
|
||||
// // Compare exchange weak
|
||||
// bool compare_exchange_weak(T*& expected, T* desired, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// T* old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_weak(T*& expected, T* desired, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// T* old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_weak(T*& expected, T* desired, etl::memory_order success, etl::memory_order failure)
|
||||
// {
|
||||
// T* old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_weak(T*& expected, T* desired, etl::memory_order success, etl::memory_order failure) volatile
|
||||
// {
|
||||
// T* old = __sync_val_compare_and_swap(&value, expected, desired);
|
||||
//
|
||||
// if (old == expected)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Compare exchange strong
|
||||
// bool compare_exchange_strong(T*& expected, T* desired, etl::memory_order order = etl::memory_order_seq_cst)
|
||||
// {
|
||||
// T* old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T*)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_strong(T*& expected, T* desired, etl::memory_order order = etl::memory_order_seq_cst) volatile
|
||||
// {
|
||||
// T* old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T*)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_strong(T*& expected, T* desired, etl::memory_order success, etl::memory_order failure)
|
||||
// {
|
||||
// T* old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T*)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool compare_exchange_strong(T*& expected, T* desired, etl::memory_order success, etl::memory_order failure) volatile
|
||||
// {
|
||||
// T* old = expected;
|
||||
//
|
||||
// while (!compare_exchange_weak(old, desired))
|
||||
// {
|
||||
// if (memcmp(&old, &expected, sizeof(T*)))
|
||||
// {
|
||||
// expected = old;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// private:
|
||||
//
|
||||
// atomic& operator =(const atomic&);
|
||||
// atomic& operator =(const atomic&) volatile;
|
||||
//
|
||||
// mutable volatile T* value;
|
||||
// };
|
||||
//
|
||||
// typedef etl::atomic<char> atomic_char;
|
||||
// typedef etl::atomic<signed char> atomic_schar;
|
||||
// typedef etl::atomic<unsigned char> atomic_uchar;
|
||||
// typedef etl::atomic<short> atomic_short;
|
||||
// typedef etl::atomic<unsigned short> atomic_ushort;
|
||||
// typedef etl::atomic<int> atomic_int;
|
||||
// typedef etl::atomic<unsigned int> atomic_uint;
|
||||
// typedef etl::atomic<long> atomic_long;
|
||||
// typedef etl::atomic<unsigned long> atomic_ulong;
|
||||
// typedef etl::atomic<long long> atomic_llong;
|
||||
// typedef etl::atomic<unsigned long long> atomic_ullong;
|
||||
// typedef etl::atomic<wchar_t> atomic_wchar_t;
|
||||
// typedef etl::atomic<char16_t> atomic_char16_t;
|
||||
// typedef etl::atomic<char32_t> atomic_char32_t;
|
||||
// typedef etl::atomic<uint8_t> atomic_uint8_t;
|
||||
// typedef etl::atomic<int8_t> atomic_int8_t;
|
||||
// typedef etl::atomic<uint16_t> atomic_uint16_t;
|
||||
// typedef etl::atomic<int16_t> atomic_int16_t;
|
||||
// typedef etl::atomic<uint32_t> atomic_uint32_t;
|
||||
// typedef etl::atomic<int32_t> atomic_int32_t;
|
||||
// typedef etl::atomic<uint64_t> atomic_uint64_t;
|
||||
// typedef etl::atomic<int64_t> atomic_int64_t;
|
||||
// typedef etl::atomic<int_least8_t> atomic_int_least8_t;
|
||||
// typedef etl::atomic<uint_least8_t> atomic_uint_least8_t;
|
||||
// typedef etl::atomic<int_least16_t> atomic_int_least16_t;
|
||||
// typedef etl::atomic<uint_least16_t> atomic_uint_least16_t;
|
||||
// typedef etl::atomic<int_least32_t> atomic_int_least32_t;
|
||||
// typedef etl::atomic<uint_least32_t> atomic_uint_least32_t;
|
||||
// typedef etl::atomic<int_least64_t> atomic_int_least64_t;
|
||||
// typedef etl::atomic<uint_least64_t> atomic_uint_least64_t;
|
||||
// typedef etl::atomic<int_fast8_t> atomic_int_fast8_t;
|
||||
// typedef etl::atomic<uint_fast8_t> atomic_uint_fast8_t;
|
||||
// typedef etl::atomic<int_fast16_t> atomic_int_fast16_t;
|
||||
// typedef etl::atomic<uint_fast16_t> atomic_uint_fast16_t;
|
||||
// typedef etl::atomic<int_fast32_t> atomic_int_fast32_t;
|
||||
// typedef etl::atomic<uint_fast32_t> atomic_uint_fast32_t;
|
||||
// typedef etl::atomic<int_fast64_t> atomic_int_fast64_t;
|
||||
// typedef etl::atomic<uint_fast64_t> atomic_uint_fast64_t;
|
||||
// typedef etl::atomic<intptr_t> atomic_intptr_t;
|
||||
// typedef etl::atomic<uintptr_t> atomic_uintptr_t;
|
||||
// typedef etl::atomic<size_t> atomic_size_t;
|
||||
// typedef etl::atomic<ptrdiff_t> atomic_ptrdiff_t;
|
||||
// typedef etl::atomic<intmax_t> atomic_intmax_t;
|
||||
// typedef etl::atomic<uintmax_t> atomic_uintmax_t;
|
||||
//}
|
||||
|
||||
#endif
|
||||
@ -31,6 +31,7 @@ SOFTWARE.
|
||||
|
||||
#include "../platform.h"
|
||||
#include "../nullptr.h"
|
||||
#include "../char_traits.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <stdint.h>
|
||||
|
||||
@ -1922,7 +1922,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void repair(T* p_buffer_)
|
||||
void repair_buffer(T* p_buffer_)
|
||||
{
|
||||
p_buffer = p_buffer_;
|
||||
}
|
||||
|
||||
@ -30,9 +30,10 @@ SOFTWARE.
|
||||
#define ETL_CALLBACK_TIMER_INCLUDED
|
||||
|
||||
#include <stdint.h>
|
||||
#include "algorithm.h"
|
||||
#include <new>
|
||||
|
||||
#include "platform.h"
|
||||
#include "algorithm.h"
|
||||
#include "nullptr.h"
|
||||
#include "function.h"
|
||||
#include "static_assert.h"
|
||||
|
||||
@ -189,9 +189,12 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
virtual
|
||||
#endif
|
||||
void repair()
|
||||
{
|
||||
etl::istring::repair(buffer);
|
||||
etl::istring::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -1828,7 +1828,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void repair(pointer p_buffer_)
|
||||
void repair_buffer(pointer p_buffer_)
|
||||
{
|
||||
p_buffer = p_buffer_;
|
||||
|
||||
@ -2095,13 +2095,16 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
#ifdef ETL_IDEQUE_REPAIR_ENABLE
|
||||
virtual
|
||||
#endif
|
||||
void repair()
|
||||
{
|
||||
#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED
|
||||
ETL_ASSERT(std::is_trivially_copyable<T>::value, ETL_ERROR(etl::deque_incompatible_type));
|
||||
#endif
|
||||
|
||||
etl::ideque<T>::repair(reinterpret_cast<T*>(&buffer[0]));
|
||||
etl::ideque<T>::repair_buffer(reinterpret_cast<T*>(&buffer[0]));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -872,7 +872,7 @@ namespace etl
|
||||
std::swap(p, value.p);
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR explicit operator bool() const
|
||||
ETL_CONSTEXPR operator bool() const
|
||||
{
|
||||
return (p != nullptr);
|
||||
}
|
||||
@ -1006,7 +1006,7 @@ namespace etl
|
||||
std::swap(p, v.p);
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR explicit operator bool() const
|
||||
ETL_CONSTEXPR operator bool() const
|
||||
{
|
||||
return (p != nullptr);
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ namespace etl
|
||||
|
||||
void initialise();
|
||||
|
||||
void repair(void** p_buffer_);
|
||||
void repair_buffer(void** p_buffer_);
|
||||
|
||||
void** p_buffer;
|
||||
void** p_end;
|
||||
|
||||
@ -39,70 +39,30 @@ SOFTWARE.
|
||||
|
||||
#include "iterator.h"
|
||||
#include "functional.h"
|
||||
#include "utility.h"
|
||||
|
||||
#if defined(ETL_IN_UNIT_TEST)
|
||||
#define ETLSTD etlstd
|
||||
namespace etlstd
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD etlstd
|
||||
#endif
|
||||
namespace etlstd
|
||||
#else
|
||||
#define ETLSTD std
|
||||
namespace std
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD std
|
||||
#endif
|
||||
namespace std
|
||||
#endif
|
||||
{
|
||||
//***************************************************************************
|
||||
// distance
|
||||
template <typename TIterator>
|
||||
typename etl::enable_if<!etl::is_same<typename std::iterator_traits<TIterator>::iterator_category, std::random_access_iterator_tag>::value,
|
||||
typename std::iterator_traits<TIterator>::difference_type>::type
|
||||
distance(TIterator first, TIterator last)
|
||||
{
|
||||
typename std::iterator_traits<TIterator>::difference_type count = 0;
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
++count;
|
||||
++first;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
template <typename TIterator>
|
||||
typename etl::enable_if<etl::is_same<typename std::iterator_traits<TIterator>::iterator_category, std::random_access_iterator_tag>::value,
|
||||
typename std::iterator_traits<TIterator>::difference_type>::type
|
||||
distance(TIterator first, TIterator last)
|
||||
{
|
||||
return last - first;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// advance
|
||||
template <typename TIterator, typename TDistance>
|
||||
typename etl::enable_if<!etl::is_same<typename std::iterator_traits<TIterator>::iterator_tag, std::random_access_iterator_tag>::value, void>::type
|
||||
advance(TIterator itr, TDistance distance)
|
||||
{
|
||||
while (distance-- != 0)
|
||||
{
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TIterator, typename TDistance>
|
||||
typename etl::enable_if<etl::is_same<typename std::iterator_traits<TIterator>::iterator_tag, std::random_access_iterator_tag>::value, void>::type
|
||||
advance(TIterator itr, TDistance distance)
|
||||
{
|
||||
return itr += distance;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// copy
|
||||
// Pointer
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator1>::value_type value_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator1>::value_type value_t;
|
||||
|
||||
return TIterator2(memcpy(db, sb, sizeof(value_t) * (se - sb)));
|
||||
}
|
||||
@ -111,7 +71,7 @@ namespace std
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
!etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
{
|
||||
while (sb != se)
|
||||
@ -128,10 +88,10 @@ namespace std
|
||||
template <typename TIterator1, typename TSize, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_n(TIterator1 sb, TSize count, TIterator2 db)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator1>::value_type value_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator1>::value_type value_t;
|
||||
|
||||
return TIterator2(memcpy(db, sb, sizeof(value_t) * count));
|
||||
}
|
||||
@ -140,7 +100,7 @@ namespace std
|
||||
template <typename TIterator1, typename TSize, typename TIterator2>
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
!etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_n(TIterator1 sb, TSize count, TIterator2 db)
|
||||
{
|
||||
while (count != 0)
|
||||
@ -158,10 +118,10 @@ namespace std
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator1>::value_type value_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator1>::value_type value_t;
|
||||
|
||||
const size_t length = (se - sb);
|
||||
|
||||
@ -172,7 +132,7 @@ namespace std
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
!etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
{
|
||||
while (se != sb)
|
||||
@ -188,16 +148,16 @@ namespace std
|
||||
template<typename TIterator, typename TValue, typename TCompare>
|
||||
TIterator lower_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator>::difference_type difference_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::difference_type difference_t;
|
||||
|
||||
difference_t count = std::distance(first, last);
|
||||
difference_t count = ETLSTD::distance(first, last);
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
TIterator itr = first;
|
||||
difference_t step = count / 2;
|
||||
|
||||
std::advance(itr, step);
|
||||
ETLSTD::advance(itr, step);
|
||||
|
||||
if (compare(*itr, value))
|
||||
{
|
||||
@ -216,7 +176,7 @@ namespace std
|
||||
template<typename TIterator, typename TValue>
|
||||
TIterator lower_bound(TIterator first, TIterator last, const TValue& value)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type> compare;
|
||||
|
||||
return ETLSTD::lower_bound(first, last, value, compare());
|
||||
}
|
||||
@ -226,16 +186,16 @@ namespace std
|
||||
template<typename TIterator, typename TValue, typename TCompare>
|
||||
TIterator upper_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator>::difference_type difference_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::difference_type difference_t;
|
||||
|
||||
difference_t count = std::distance(first, last);
|
||||
difference_t count = ETLSTD::distance(first, last);
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
TIterator itr = first;
|
||||
difference_t step = count / 2;
|
||||
|
||||
std::advance(itr, step);
|
||||
ETLSTD::advance(itr, step);
|
||||
|
||||
if (!compare(value, *itr))
|
||||
{
|
||||
@ -254,7 +214,7 @@ namespace std
|
||||
template<typename TIterator, typename TValue>
|
||||
TIterator upper_bound(TIterator first, TIterator last, const TValue& value)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type> compare;
|
||||
|
||||
return ETLSTD::upper_bound(first, last, value, compare());
|
||||
}
|
||||
@ -262,19 +222,55 @@ namespace std
|
||||
//***************************************************************************
|
||||
// equal_range
|
||||
template<typename TIterator, typename TValue, typename TCompare>
|
||||
std::pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value, TCompare compare)
|
||||
ETLSTD::pair <TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value, TCompare compare)
|
||||
{
|
||||
return std::make_pair(ETLSTD::lower_bound(first, last, value, compare),
|
||||
return ETLSTD::make_pair(ETLSTD::lower_bound(first, last, value, compare),
|
||||
ETLSTD::upper_bound(first, last, value, compare));
|
||||
}
|
||||
|
||||
template<typename TIterator, typename TValue>
|
||||
std::pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value)
|
||||
ETLSTD::pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type> compare;
|
||||
|
||||
return std::make_pair(ETLSTD::lower_bound(first, last, value, compare()),
|
||||
ETLSTD::upper_bound(first, last, value, compare()));
|
||||
return ETLSTD::make_pair(ETLSTD::lower_bound(first, last, value, compare()),
|
||||
ETLSTD::upper_bound(first, last, value, compare()));
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// find_if
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
TIterator find_if(TIterator first, TIterator last, TUnaryPredicate predicate)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
if (predicate(*first))
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
++first;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// find
|
||||
template <typename TIterator, typename T>
|
||||
TIterator find(TIterator first, TIterator last, const T& value)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
if (*first == value)
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
++first;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -296,6 +292,67 @@ namespace std
|
||||
memset(first, value, last - first);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// fill_n
|
||||
template<typename TIterator, typename TSize, typename TValue>
|
||||
typename etl::enable_if<!(etl::is_same<char, TValue>::value || etl::is_same<unsigned char, TValue>::value) || !etl::is_pointer<TIterator>::value, TIterator>::type
|
||||
fill_n(TIterator first, TSize count, const TValue& value)
|
||||
{
|
||||
for (TSize i = 0; i < count; ++i)
|
||||
{
|
||||
*first++ = value;
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
template<typename TIterator, typename TSize, typename TValue>
|
||||
typename etl::enable_if<(etl::is_same<char, TValue>::value || etl::is_same<unsigned char, TValue>::value) && etl::is_pointer<TIterator>::value, void>::type
|
||||
fill_n(TIterator first, TSize count, const TValue& value)
|
||||
{
|
||||
memset(first, value, count);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// count
|
||||
template <typename TIterator, typename T>
|
||||
typename iterator_traits<TIterator>::difference_type count(TIterator first, TIterator last, const T& value)
|
||||
{
|
||||
typename iterator_traits<TIterator>::difference_type n = 0;
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
if (*first == value)
|
||||
{
|
||||
++n;
|
||||
}
|
||||
|
||||
++first;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// count
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
typename iterator_traits<TIterator>::difference_type count_if(TIterator first, TIterator last, TUnaryPredicate predicate)
|
||||
{
|
||||
typename iterator_traits<TIterator>::difference_type n = 0;
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
if (predicate(*first))
|
||||
{
|
||||
++n;
|
||||
}
|
||||
|
||||
++first;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// swap
|
||||
template <typename T>
|
||||
@ -311,7 +368,7 @@ namespace std
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
void iter_swap(TIterator1 a, TIterator2 b)
|
||||
{
|
||||
typename std::iterator_traits<TIterator1>::value_type c = *a;
|
||||
typename ETLSTD::iterator_traits<TIterator1>::value_type c = *a;
|
||||
*a = *b;
|
||||
*b = c;
|
||||
}
|
||||
@ -319,7 +376,7 @@ namespace std
|
||||
//***************************************************************************
|
||||
// equal
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value || !etl::is_pointer<TIterator2>::value || !etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value || !etl::is_pointer<TIterator2>::value || !etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
|
||||
{
|
||||
while (first1 != last1)
|
||||
@ -334,10 +391,10 @@ namespace std
|
||||
}
|
||||
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value && etl::is_pointer<TIterator2>::value && etl::is_pod<typename std::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value && etl::is_pointer<TIterator2>::value && etl::is_pod<typename ETLSTD::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator1>::value_type value_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator1>::value_type value_t;
|
||||
|
||||
return (memcmp(first1, first2, sizeof(value_t) * (last1 - last1)) == 0);
|
||||
}
|
||||
@ -374,7 +431,7 @@ namespace std
|
||||
bool lexicographical_compare(TIterator1 first1, TIterator1 last1,
|
||||
TIterator2 first2, TIterator2 last2)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator1>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator1>::value_type> compare;
|
||||
|
||||
return ETLSTD::lexicographical_compare(first1, last1, first2, last2, compare());
|
||||
}
|
||||
@ -390,7 +447,7 @@ namespace std
|
||||
template <typename T>
|
||||
const T& min(const T& a, const T& b)
|
||||
{
|
||||
typedef std::less<T> compare;
|
||||
typedef ETLSTD::less<T> compare;
|
||||
|
||||
return ETLSTD::min(a, b, compare());
|
||||
}
|
||||
@ -406,11 +463,35 @@ namespace std
|
||||
template <typename T>
|
||||
const T& max(const T& a, const T& b)
|
||||
{
|
||||
typedef std::less<T> compare;
|
||||
typedef ETLSTD::less<T> compare;
|
||||
|
||||
return ETLSTD::max(a, b, compare());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// transform
|
||||
template <typename TIteratorIn, typename TIteratorOut, typename TUnaryOperation>
|
||||
TIteratorOut transform(TIteratorIn first1, TIteratorIn last1, TIteratorOut d_first, TUnaryOperation unary_operation)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
*d_first++ = unary_operation(*first1++);
|
||||
}
|
||||
|
||||
return d_first;
|
||||
}
|
||||
|
||||
template <typename TIteratorIn1, typename TIteratorIn2, typename TIteratorOut, typename TBinaryOperation>
|
||||
TIteratorOut transform(TIteratorIn1 first1, TIteratorIn1 last1, TIteratorIn2 first2, TIteratorOut d_first, TBinaryOperation binary_operation)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
*d_first++ = binary_operation(*first1++, *first2++);
|
||||
}
|
||||
|
||||
return d_first;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Heap
|
||||
namespace private_heap
|
||||
@ -486,8 +567,8 @@ namespace std
|
||||
template <typename TIterator, typename TCompare>
|
||||
void pop_heap(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator>::value_type value_t;
|
||||
typedef typename std::iterator_traits<TIterator>::difference_type distance_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::value_type value_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::difference_type distance_t;
|
||||
|
||||
value_t value = last[-1];
|
||||
last[-1] = first[0];
|
||||
@ -499,7 +580,7 @@ namespace std
|
||||
template <typename TIterator>
|
||||
void pop_heap(TIterator first, TIterator last)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type> compare;
|
||||
|
||||
ETLSTD::pop_heap(first, last, compare());
|
||||
}
|
||||
@ -508,8 +589,8 @@ namespace std
|
||||
template <typename TIterator, typename TCompare>
|
||||
void push_heap(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator>::difference_type difference_t;
|
||||
typedef typename std::iterator_traits<TIterator>::value_type value_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::difference_type difference_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::value_type value_t;
|
||||
|
||||
private_heap::push_heap(first, difference_t(last - first - 1), difference_t(0), value_t(*(last - 1)), compare);
|
||||
}
|
||||
@ -518,7 +599,7 @@ namespace std
|
||||
template <typename TIterator>
|
||||
void push_heap(TIterator first, TIterator last)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type> compare;
|
||||
|
||||
ETLSTD::push_heap(first, last, compare());
|
||||
}
|
||||
@ -527,7 +608,7 @@ namespace std
|
||||
template <typename TIterator, typename TCompare>
|
||||
void make_heap(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
typedef typename std::iterator_traits<TIterator>::difference_type difference_t;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::difference_type difference_t;
|
||||
|
||||
if ((last - first) < 2)
|
||||
{
|
||||
@ -554,7 +635,7 @@ namespace std
|
||||
template <typename TIterator>
|
||||
void make_heap(TIterator first, TIterator last)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type> compare;
|
||||
|
||||
ETLSTD::make_heap(first, last, compare());
|
||||
}
|
||||
@ -563,7 +644,7 @@ namespace std
|
||||
template <typename TIterator>
|
||||
bool is_heap(TIterator first, TIterator last)
|
||||
{
|
||||
typedef std::less<typename std::iterator_traits<TIterator>::value_type> compare;
|
||||
typedef ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type> compare;
|
||||
|
||||
return private_heap::is_heap(first, last - first, compare());
|
||||
}
|
||||
@ -615,7 +696,7 @@ namespace std
|
||||
template<typename TIterator1, class TIterator2>
|
||||
TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last)
|
||||
{
|
||||
typedef std::equal_to<typename std::iterator_traits<TIterator1>::value_type> compare;
|
||||
typedef ETLSTD::equal_to<typename ETLSTD::iterator_traits<TIterator1>::value_type> compare;
|
||||
|
||||
return ETLSTD::search(first, last, search_first, search_last, compare());
|
||||
}
|
||||
|
||||
@ -5,9 +5,15 @@
|
||||
#include "../../platform.h"
|
||||
|
||||
#if defined(ETL_IN_UNIT_TEST)
|
||||
namespace etlstd
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD etlstd
|
||||
#endif
|
||||
namespace etlstd
|
||||
#else
|
||||
namespace std
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD std
|
||||
#endif
|
||||
namespace std
|
||||
#endif
|
||||
{
|
||||
//***************************************************************************
|
||||
@ -72,7 +78,7 @@ namespace std
|
||||
//***************************************************************************
|
||||
|
||||
template <typename TFunction>
|
||||
class binder1st : public etlstd::unary_function<typename TFunction::second_argument_type, typename TFunction::result_type>
|
||||
class binder1st : public ETLSTD::unary_function<typename TFunction::second_argument_type, typename TFunction::result_type>
|
||||
{
|
||||
protected:
|
||||
|
||||
@ -106,7 +112,7 @@ namespace std
|
||||
//***************************************************************************
|
||||
|
||||
template <typename TFunction >
|
||||
class binder2nd : public etlstd::unary_function<typename TFunction::first_argument_type, typename TFunction::result_type>
|
||||
class binder2nd : public ETLSTD::unary_function<typename TFunction::first_argument_type, typename TFunction::result_type>
|
||||
{
|
||||
protected:
|
||||
TFunction operation;
|
||||
@ -135,4 +141,4 @@ namespace std
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -38,8 +38,14 @@ SOFTWARE.
|
||||
#include "../../type_traits.h"
|
||||
|
||||
#if defined(ETL_IN_UNIT_TEST)
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD etlstd
|
||||
#endif
|
||||
namespace etlstd
|
||||
#else
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD std
|
||||
#endif
|
||||
namespace std
|
||||
#endif
|
||||
{
|
||||
@ -82,7 +88,7 @@ namespace std
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
typedef random_access_iterator_tag iterator_category ;
|
||||
typedef random_access_iterator_tag iterator_category;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@ -92,14 +98,19 @@ namespace std
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
typedef random_access_iterator_tag iterator_category ;
|
||||
typedef random_access_iterator_tag iterator_category;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// advance
|
||||
template <typename TIterator, typename TDistance>
|
||||
typename etl::enable_if<etl::is_same<typename iterator_traits<TIterator>::iterator_catagory, input_iterator_tag>::value, void>::type
|
||||
advance(TIterator& itr, TDistance n)
|
||||
void advance(TIterator& itr, TDistance n)
|
||||
{
|
||||
advance_helper(itr, n, typename ETLSTD::iterator_traits<TIterator>::iterator_category());
|
||||
}
|
||||
|
||||
template <typename TIterator, typename TDistance>
|
||||
void advance_helper(TIterator& itr, TDistance n, ETLSTD::input_iterator_tag)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
@ -108,8 +119,7 @@ namespace std
|
||||
}
|
||||
|
||||
template <typename TIterator, typename TDistance>
|
||||
typename etl::enable_if<etl::is_same<typename iterator_traits<TIterator>::iterator_catagory, output_iterator_tag>::value, void>::type
|
||||
advance(TIterator& itr, TDistance n)
|
||||
void advance_helper(TIterator& itr, TDistance n, ETLSTD::output_iterator_tag)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
@ -118,8 +128,7 @@ namespace std
|
||||
}
|
||||
|
||||
template <typename TIterator, typename TDistance>
|
||||
typename etl::enable_if<etl::is_same<typename iterator_traits<TIterator>::iterator_catagory, forward_iterator_tag>::value, void>::type
|
||||
advance(TIterator& itr, TDistance n)
|
||||
void advance_helper(TIterator& itr, TDistance n, ETLSTD::forward_iterator_tag)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
@ -128,8 +137,7 @@ namespace std
|
||||
}
|
||||
|
||||
template <typename TIterator, typename TDistance>
|
||||
typename etl::enable_if<etl::is_same<typename iterator_traits<TIterator>::iterator_catagory, bidirectional_iterator_tag>::value, void>::type
|
||||
advance(TIterator& itr, TDistance n)
|
||||
void advance_helper(TIterator& itr, TDistance n, ETLSTD::bidirectional_iterator_tag)
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
@ -140,7 +148,7 @@ namespace std
|
||||
}
|
||||
else
|
||||
{
|
||||
while (n--)
|
||||
while (n++)
|
||||
{
|
||||
--itr;
|
||||
}
|
||||
@ -148,8 +156,7 @@ namespace std
|
||||
}
|
||||
|
||||
template <typename TIterator, typename TDistance>
|
||||
typename etl::enable_if<etl::is_same<typename iterator_traits<TIterator>::iterator_catagory, random_access_iterator_tag>::value, void>::type
|
||||
advance(TIterator& itr, TDistance n)
|
||||
void advance_helper(TIterator& itr, TDistance n, ETLSTD::random_access_iterator_tag)
|
||||
{
|
||||
itr += n;
|
||||
}
|
||||
@ -157,24 +164,55 @@ namespace std
|
||||
//***************************************************************************
|
||||
// distance
|
||||
template<typename TIterator>
|
||||
typename etl::enable_if<!etl::is_same<typename iterator_traits<TIterator>::iterator_catagory, random_access_iterator_tag>::value,
|
||||
typename iterator_traits<TIterator>::difference_type>::type
|
||||
distance(TIterator first, TIterator last)
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type distance(TIterator first, TIterator last)
|
||||
{
|
||||
typename iterator_traits<TIterator>::difference_type d = 0;
|
||||
return distance_helper(first, last, typename ETLSTD::iterator_traits<TIterator>::iterator_category());
|
||||
}
|
||||
|
||||
template<typename TIterator>
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETLSTD::input_iterator_tag)
|
||||
{
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type d = 0;
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
++d;
|
||||
++first;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
template<typename TIterator>
|
||||
typename etl::enable_if<etl::is_same<typename iterator_traits<TIterator>::iterator_catagory, random_access_iterator_tag>::value,
|
||||
typename iterator_traits<TIterator>::difference_type>::type
|
||||
distance(TIterator first, TIterator last)
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETLSTD::forward_iterator_tag)
|
||||
{
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type d = 0;
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
++d;
|
||||
++first;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
template<typename TIterator>
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETLSTD::bidirectional_iterator_tag)
|
||||
{
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type d = 0;
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
++d;
|
||||
++first;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
template<typename TIterator>
|
||||
typename ETLSTD::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETLSTD::random_access_iterator_tag)
|
||||
{
|
||||
return last - first;
|
||||
}
|
||||
@ -186,11 +224,11 @@ namespace std
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename iterator_traits<TIterator>::difference_type difference_type;
|
||||
typedef typename iterator_traits<TIterator>::value_type value_type;
|
||||
typedef typename iterator_traits<TIterator>::pointer pointer;
|
||||
typedef typename iterator_traits<TIterator>::reference reference;
|
||||
typedef typename iterator_traits<TIterator>::iterator_category iterator_category;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::difference_type difference_type;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::value_type value_type;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::pointer pointer;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::reference reference;
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::iterator_category iterator_category;
|
||||
|
||||
reverse_iterator()
|
||||
{
|
||||
@ -229,69 +267,69 @@ namespace std
|
||||
return current;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reference operator *() const
|
||||
reference operator *() const
|
||||
{
|
||||
TIterator temp = current;
|
||||
--temp;
|
||||
return *temp;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR pointer operator ->() const
|
||||
pointer operator ->() const
|
||||
{
|
||||
TIterator temp = current;
|
||||
--temp;
|
||||
return &(*temp);
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator>& operator ++()
|
||||
reverse_iterator<TIterator>& operator ++()
|
||||
{
|
||||
--current;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator> operator ++(int)
|
||||
reverse_iterator<TIterator> operator ++(int)
|
||||
{
|
||||
reverse_iterator<TIterator> temp = *this;
|
||||
--current;
|
||||
return temp;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator>& operator --()
|
||||
reverse_iterator<TIterator>& operator --()
|
||||
{
|
||||
++current;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator> operator --(int)
|
||||
reverse_iterator<TIterator> operator --(int)
|
||||
{
|
||||
reverse_iterator<TIterator> temp = *this;
|
||||
++current;
|
||||
return temp;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator> operator +(difference_type n) const
|
||||
reverse_iterator<TIterator> operator +(difference_type n) const
|
||||
{
|
||||
return reverse_iterator<TIterator>(current - n);
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator>& operator +=(difference_type n)
|
||||
reverse_iterator<TIterator>& operator +=(difference_type n)
|
||||
{
|
||||
current -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator> operator -(difference_type n) const
|
||||
reverse_iterator<TIterator> operator -(difference_type n) const
|
||||
{
|
||||
return reverse_iterator<TIterator>(current + n);
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reverse_iterator<TIterator>& operator -=(difference_type n)
|
||||
reverse_iterator<TIterator>& operator -=(difference_type n)
|
||||
{
|
||||
current += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR reference operator [](difference_type n) const
|
||||
reference operator [](difference_type n) const
|
||||
{
|
||||
return *(*this + n);
|
||||
}
|
||||
@ -302,43 +340,43 @@ namespace std
|
||||
};
|
||||
|
||||
template <class TIterator>
|
||||
inline ETL_CONSTEXPR bool operator <(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
inline bool operator <(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
{
|
||||
return rhs.base() < lhs.base();
|
||||
}
|
||||
|
||||
template <class TIterator>
|
||||
inline ETL_CONSTEXPR bool operator !=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
inline bool operator !=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template <class TIterator>
|
||||
inline ETL_CONSTEXPR bool operator >(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
inline bool operator >(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
template <class TIterator>
|
||||
inline ETL_CONSTEXPR bool operator <=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
inline bool operator <=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
template <class TIterator>
|
||||
inline ETL_CONSTEXPR bool operator >=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
inline bool operator >=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
template <class TIterator>
|
||||
inline ETL_CONSTEXPR typename reverse_iterator<TIterator>::difference_type operator -(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
inline typename reverse_iterator<TIterator>::difference_type operator -(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
|
||||
{
|
||||
return rhs.base() - lhs.base();
|
||||
}
|
||||
|
||||
template <class TIterator, class TDifference>
|
||||
inline ETL_CONSTEXPR reverse_iterator<TIterator> operator +(TDifference n, const reverse_iterator<TIterator>& itr)
|
||||
inline reverse_iterator<TIterator> operator +(TDifference n, const reverse_iterator<TIterator>& itr)
|
||||
{
|
||||
return itr.operator +(n);
|
||||
}
|
||||
|
||||
@ -43,11 +43,15 @@ SOFTWARE.
|
||||
#define ETL_LOG2(x) (((x) * 301) / 1000)
|
||||
|
||||
#if defined(ETL_IN_UNIT_TEST)
|
||||
#define ETLSTD etlstd
|
||||
namespace etlstd
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD etlstd
|
||||
#endif
|
||||
namespace etlstd
|
||||
#else
|
||||
#define ETLSTD std
|
||||
namespace std
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD std
|
||||
#endif
|
||||
namespace std
|
||||
#endif
|
||||
{
|
||||
template<class T> class numeric_limits;
|
||||
|
||||
@ -32,14 +32,17 @@ SOFTWARE.
|
||||
#define ETL_STL_ALTERNATE_UTILITY_INCLUDED
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "algorithm.h"
|
||||
|
||||
#if defined(ETL_IN_UNIT_TEST)
|
||||
#define ETLSTD etlstd
|
||||
namespace etlstd
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD etlstd
|
||||
#endif
|
||||
namespace etlstd
|
||||
#else
|
||||
#define ETLSTD std
|
||||
namespace std
|
||||
#if !defined(ETLSTD)
|
||||
#define ETLSTD std
|
||||
#endif
|
||||
namespace std
|
||||
#endif
|
||||
{
|
||||
//******************************************************************************
|
||||
@ -79,8 +82,12 @@ namespace std
|
||||
|
||||
void swap(pair<T1, T2>& other)
|
||||
{
|
||||
ETLSTD::swap(first, other.first);
|
||||
ETLSTD::swap(second, other.second);
|
||||
T1 temp1 = first;
|
||||
T2 temp2 = second;
|
||||
first = other.first;
|
||||
second = other.second;
|
||||
other.first = temp1;
|
||||
other.second = temp2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -193,9 +193,12 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
virtual
|
||||
#endif
|
||||
void repair()
|
||||
{
|
||||
etl::iu16string::repair(buffer);
|
||||
etl::iu16string::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -193,9 +193,12 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
virtual
|
||||
#endif
|
||||
void repair()
|
||||
{
|
||||
etl::iu32string::repair(buffer);
|
||||
etl::iu32string::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -868,7 +868,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void repair(T* p_buffer_)
|
||||
void repair_buffer(T* p_buffer_)
|
||||
{
|
||||
uintptr_t length = p_end - p_buffer;
|
||||
p_buffer = p_buffer_;
|
||||
@ -1112,13 +1112,16 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
#ifdef ETL_IVECTOR_REPAIR_ENABLE
|
||||
virtual
|
||||
#endif
|
||||
void repair()
|
||||
{
|
||||
#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED
|
||||
ETL_ASSERT(std::is_trivially_copyable<T>::value, ETL_ERROR(etl::vector_incompatible_type));
|
||||
#endif
|
||||
|
||||
etl::ivector<T>::repair(buffer);
|
||||
etl::ivector<T>::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -1222,7 +1225,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void repair()
|
||||
{
|
||||
etl::ivector<T*>::repair(buffer);
|
||||
etl::ivector<T*>::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -37,13 +37,13 @@ SOFTWARE.
|
||||
/// Definitions of the ETL version
|
||||
///\ingroup utilities
|
||||
|
||||
#define ETL_VERSION "11.16.2"
|
||||
#define ETL_VERSION_W L"11.16.2"
|
||||
#define ETL_VERSION_U16 u"11.16.2"
|
||||
#define ETL_VERSION_U32 U"11.16.2"
|
||||
#define ETL_VERSION "11.16.3"
|
||||
#define ETL_VERSION_W L"11.16.3"
|
||||
#define ETL_VERSION_U16 u"11.16.3"
|
||||
#define ETL_VERSION_U32 U"11.16.3"
|
||||
#define ETL_VERSION_MAJOR 11
|
||||
#define ETL_VERSION_MINOR 16
|
||||
#define ETL_VERSION_PATCH 2
|
||||
#define ETL_VERSION_PATCH 3
|
||||
#define ETL_VERSION_VALUE ((ETL_VERSION_MAJOR * 10000) + (ETL_VERSION_MINOR * 100) + ETL_VERSION_PATCH)
|
||||
|
||||
#endif
|
||||
|
||||
@ -194,9 +194,12 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
virtual
|
||||
#endif
|
||||
void repair()
|
||||
{
|
||||
etl::iwstring::repair(buffer);
|
||||
etl::iwstring::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -479,7 +479,7 @@ void etl::pvoidvector::initialise()
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void etl::pvoidvector::repair(void** p_buffer_)
|
||||
void etl::pvoidvector::repair_buffer(void** p_buffer_)
|
||||
{
|
||||
uintptr_t length = p_end - p_buffer;
|
||||
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
===============================================================================
|
||||
11.16.3
|
||||
Fixed missing algorithms for No STL option.
|
||||
Improved Keil compatibility.
|
||||
|
||||
===============================================================================
|
||||
11.15.1
|
||||
io_port_test Fixed unaligned access error.
|
||||
|
||||
@ -337,6 +337,7 @@
|
||||
<Unit filename="../main.cpp" />
|
||||
<Unit filename="../murmurhash3.cpp" />
|
||||
<Unit filename="../murmurhash3.h" />
|
||||
<Unit filename="../no_stl_test_iterators.h" />
|
||||
<Unit filename="../test_algorithm.cpp" />
|
||||
<Unit filename="../test_alignment.cpp" />
|
||||
<Unit filename="../test_array.cpp" />
|
||||
|
||||
206
test/no_stl_test_iterators.h
Normal file
206
test/no_stl_test_iterators.h
Normal file
@ -0,0 +1,206 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2018 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_NO_STL_TEST_ITERATORS_INCLUDED
|
||||
#define ETL_NO_STL_TEST_ITERATORS_INCLUDED
|
||||
|
||||
#include "etl/stl/alternate/iterator.h"
|
||||
|
||||
template <typename T>
|
||||
struct non_random_iterator : public etlstd::iterator<etlstd::bidirectional_iterator_tag, T>
|
||||
{
|
||||
non_random_iterator()
|
||||
: ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
non_random_iterator(T* v)
|
||||
: ptr(v)
|
||||
{
|
||||
}
|
||||
|
||||
non_random_iterator(const non_random_iterator& other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
}
|
||||
|
||||
T& operator *()
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
const T& operator *() const
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
non_random_iterator& operator ++()
|
||||
{
|
||||
++ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
non_random_iterator operator ++(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
++ptr;
|
||||
return non_random_iterator(temp);
|
||||
}
|
||||
|
||||
non_random_iterator& operator --()
|
||||
{
|
||||
--ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
non_random_iterator operator --(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
--ptr;
|
||||
return non_random_iterator(temp);
|
||||
}
|
||||
|
||||
non_random_iterator& operator =(T* other)
|
||||
{
|
||||
ptr = other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
operator const T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T* ptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator !=(const non_random_iterator<T>& lhs, const non_random_iterator<T>& rhs)
|
||||
{
|
||||
return lhs.ptr != rhs.ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct random_iterator : public etlstd::iterator<etlstd::random_access_iterator_tag, T>
|
||||
{
|
||||
random_iterator()
|
||||
: ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
random_iterator(T* v)
|
||||
: ptr(v)
|
||||
{
|
||||
}
|
||||
|
||||
random_iterator(const random_iterator& other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
}
|
||||
|
||||
T& operator *()
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
const T& operator *() const
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
random_iterator& operator ++()
|
||||
{
|
||||
++ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator operator ++(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
++ptr;
|
||||
return random_iterator(temp);
|
||||
}
|
||||
|
||||
random_iterator& operator --()
|
||||
{
|
||||
--ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator operator --(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
--ptr;
|
||||
return random_iterator(temp);
|
||||
}
|
||||
|
||||
random_iterator& operator +=(int n)
|
||||
{
|
||||
ptr += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator& operator -=(int n)
|
||||
{
|
||||
ptr -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator& operator =(T* other)
|
||||
{
|
||||
ptr = other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
operator const T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T* ptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
ptrdiff_t operator -(const random_iterator<T>& lhs, const random_iterator<T>& rhs)
|
||||
{
|
||||
return lhs.ptr - rhs.ptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -37,15 +37,19 @@ SOFTWARE.
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "no_stl_test_iterators.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
int dataEQ[10] = { 1, 1, 3, 3, 5, 5, 7, 7, 9, 9 };
|
||||
const size_t SIZE = 10;
|
||||
|
||||
int dataEQ[SIZE] = { 1, 1, 3, 3, 5, 5, 7, 7, 9, 9 };
|
||||
std::list<int> dataEQL = { 1, 1, 3, 3, 5, 5, 7, 7, 9, 9 };
|
||||
|
||||
int dataS[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
int dataS[SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
std::list<int> dataSL = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
|
||||
int dataA[10] = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 };
|
||||
int dataA[SIZE] = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 };
|
||||
|
||||
typedef std::vector<int> Vector;
|
||||
Vector dataV = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 };
|
||||
@ -53,6 +57,9 @@ namespace
|
||||
typedef std::list<int> List;
|
||||
List dataL = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 };
|
||||
|
||||
int dataD1[SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
int dataD2[SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
@ -112,48 +119,6 @@ namespace
|
||||
|
||||
SUITE(test_no_stl_algorithm)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(distance_non_random)
|
||||
{
|
||||
ptrdiff_t d1 = std::distance(dataL.begin(), dataL.end());
|
||||
ptrdiff_t d2 = etlstd::distance(dataL.begin(), dataL.end());
|
||||
|
||||
CHECK_EQUAL(d1, d2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(distance_random)
|
||||
{
|
||||
ptrdiff_t d1 = std::distance(dataV.begin(), dataV.end());
|
||||
ptrdiff_t d2 = etlstd::distance(dataV.begin(), dataV.end());
|
||||
|
||||
CHECK_EQUAL(d1, d2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(advance_non_random)
|
||||
{
|
||||
List::const_iterator itr1 = dataL.begin();
|
||||
List::const_iterator itr2 = dataL.begin();
|
||||
|
||||
std::advance(itr1, 4);
|
||||
std::advance(itr2, 4);
|
||||
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(advance_random)
|
||||
{
|
||||
Vector::const_iterator itr1 = dataV.begin();
|
||||
Vector::const_iterator itr2 = dataV.begin();
|
||||
|
||||
std::advance(itr1, 4);
|
||||
std::advance(itr2, 4);
|
||||
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(min)
|
||||
{
|
||||
@ -317,7 +282,7 @@ namespace
|
||||
for (int i = 0; i < 11; ++i)
|
||||
{
|
||||
int* lb1 = std::lower_bound(std::begin(dataS), std::end(dataS), i);
|
||||
int* lb2 = etlstd::lower_bound(std::begin(dataS), std::end(dataS), i);
|
||||
int* lb2 = etlstd::lower_bound(random_iterator<int>(std::begin(dataS)), random_iterator<int>(std::end(dataS)), i);
|
||||
|
||||
CHECK_EQUAL(lb1, lb2);
|
||||
}
|
||||
@ -328,10 +293,10 @@ namespace
|
||||
{
|
||||
for (int i = 0; i < 11; ++i)
|
||||
{
|
||||
std::list<int>::iterator lb1 = std::lower_bound(std::begin(dataSL), std::end(dataSL), i);
|
||||
std::list<int>::iterator lb2 = etlstd::lower_bound(std::begin(dataSL), std::end(dataSL), i);
|
||||
int* lb1 = std::lower_bound(std::begin(dataS), std::end(dataS), i);
|
||||
int* lb2 = etlstd::lower_bound(non_random_iterator<int>(std::begin(dataS)), non_random_iterator<int>(std::end(dataS)), i);
|
||||
|
||||
CHECK_EQUAL(std::distance(std::begin(dataSL), lb1), std::distance(std::begin(dataSL), lb2));
|
||||
CHECK_EQUAL(std::distance(std::begin(dataS), lb1), std::distance(std::begin(dataS), lb2));
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,7 +306,7 @@ namespace
|
||||
for (int i = 0; i < 11; ++i)
|
||||
{
|
||||
int* lb1 = std::upper_bound(std::begin(dataS), std::end(dataS), i);
|
||||
int* lb2 = etlstd::upper_bound(std::begin(dataS), std::end(dataS), i);
|
||||
int* lb2 = etlstd::upper_bound(random_iterator<int>(std::begin(dataS)), random_iterator<int>(std::end(dataS)), i);
|
||||
|
||||
CHECK_EQUAL(std::distance(std::begin(dataS), lb1), std::distance(std::begin(dataS), lb2));
|
||||
}
|
||||
@ -352,10 +317,10 @@ namespace
|
||||
{
|
||||
for (int i = 0; i < 11; ++i)
|
||||
{
|
||||
std::list<int>::iterator lb1 = std::upper_bound(std::begin(dataSL), std::end(dataSL), i);
|
||||
std::list<int>::iterator lb2 = etlstd::upper_bound(std::begin(dataSL), std::end(dataSL), i);
|
||||
int* lb1 = std::upper_bound(std::begin(dataS), std::end(dataS), i);
|
||||
int* lb2 = etlstd::upper_bound(non_random_iterator<int>(std::begin(dataS)), non_random_iterator<int>(std::end(dataS)), i);
|
||||
|
||||
CHECK_EQUAL(std::distance(std::begin(dataSL), lb1), std::distance(std::begin(dataSL), lb2));
|
||||
CHECK_EQUAL(std::distance(std::begin(dataS), lb1), std::distance(std::begin(dataS), lb2));
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,11 +329,11 @@ namespace
|
||||
{
|
||||
for (int i = 0; i < 11; ++i)
|
||||
{
|
||||
std::pair<int*, int*> lb1 = std::equal_range(std::begin(dataEQ), std::end(dataEQ), i);
|
||||
std::pair<int*, int*> lb2 = etlstd::equal_range(std::begin(dataEQ), std::end(dataEQ), i);
|
||||
std::pair<int*, int*> lb1 = std::equal_range(std::begin(dataEQ), std::end(dataEQ), i);
|
||||
etlstd::pair<random_iterator<int>, random_iterator<int>> lb2 = etlstd::equal_range(random_iterator<int>(std::begin(dataEQ)), random_iterator<int>(std::end(dataEQ)), i);
|
||||
|
||||
CHECK_EQUAL(std::distance(std::begin(dataEQ), lb1.first), std::distance(std::begin(dataEQ), lb2.first));
|
||||
CHECK_EQUAL(std::distance(lb1.first, lb1.second), std::distance(lb2.first, lb2.second));
|
||||
CHECK_EQUAL(std::distance(std::begin(dataEQ), lb1.first), std::distance<int*>(std::begin(dataEQ), lb2.first));
|
||||
CHECK_EQUAL(std::distance(lb1.first, lb1.second), std::distance<int*>(lb2.first, lb2.second));
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,11 +342,11 @@ namespace
|
||||
{
|
||||
for (int i = 0; i < 11; ++i)
|
||||
{
|
||||
std::pair<std::list<int>::iterator, std::list<int>::iterator> lb1 = std::equal_range(std::begin(dataEQL), std::end(dataEQL), i);
|
||||
std::pair<std::list<int>::iterator, std::list<int>::iterator> lb2 = etlstd::equal_range(std::begin(dataEQL), std::end(dataEQL), i);
|
||||
std::pair<int*, int*> lb1 = std::equal_range(std::begin(dataEQ), std::end(dataEQ), i);
|
||||
etlstd::pair<non_random_iterator<int>, non_random_iterator<int>> lb2 = etlstd::equal_range(non_random_iterator<int>(std::begin(dataEQ)), non_random_iterator<int>(std::end(dataEQ)), i);
|
||||
|
||||
CHECK_EQUAL(std::distance(std::begin(dataEQL), lb1.first), std::distance(std::begin(dataEQL), lb2.first));
|
||||
CHECK_EQUAL(std::distance(lb1.first, lb1.second), std::distance(lb2.first, lb2.second));
|
||||
CHECK_EQUAL(std::distance(std::begin(dataEQ), lb1.first), std::distance<int*>(std::begin(dataEQ), lb2.first));
|
||||
CHECK_EQUAL(std::distance(lb1.first, lb1.second), std::distance<int*>(lb2.first, lb2.second));
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,5 +542,109 @@ namespace
|
||||
isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2));
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(find)
|
||||
{
|
||||
int* itr1 = std::find(std::begin(dataA), std::end(dataA), 5);
|
||||
int* itr2 = etlstd::find(std::begin(dataA), std::end(dataA), 5);
|
||||
|
||||
CHECK(itr1 == itr2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(find_if)
|
||||
{
|
||||
struct predicate
|
||||
{
|
||||
bool operator()(int i) const
|
||||
{
|
||||
return (i == 5);
|
||||
}
|
||||
};
|
||||
|
||||
int* itr1 = std::find_if(std::begin(dataA), std::end(dataA), predicate());
|
||||
int* itr2 = etlstd::find_if(std::begin(dataA), std::end(dataA), predicate());
|
||||
|
||||
CHECK(itr1 == itr2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(count)
|
||||
{
|
||||
size_t c1 = std::count(std::begin(dataEQ), std::end(dataEQ), 5);
|
||||
size_t c2 = etlstd::count(std::begin(dataEQ), std::end(dataEQ), 5);
|
||||
|
||||
CHECK(c1 == c2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(count_if)
|
||||
{
|
||||
struct predicate
|
||||
{
|
||||
bool operator()(int i) const
|
||||
{
|
||||
return (i == 5);
|
||||
}
|
||||
};
|
||||
|
||||
size_t c1 = std::count_if(std::begin(dataEQ), std::end(dataEQ), predicate());
|
||||
size_t c2 = etlstd::count_if(std::begin(dataEQ), std::end(dataEQ), predicate());
|
||||
|
||||
CHECK(c1 == c2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(fill_n)
|
||||
{
|
||||
int* p1 = std::fill_n(std::begin(dataD1), SIZE, 5);
|
||||
int* p2 = etlstd::fill_n(std::begin(dataD2), SIZE, 5);
|
||||
|
||||
CHECK(p2 == std::end(dataD2));
|
||||
|
||||
bool isEqual = std::equal(std::begin(dataD1), std::end(dataD1), std::begin(dataD2));
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(transform1)
|
||||
{
|
||||
struct Function
|
||||
{
|
||||
int operator()(int d) const
|
||||
{
|
||||
return d * 2;
|
||||
}
|
||||
};
|
||||
|
||||
int* p1 = std::transform(std::begin(dataS), std::end(dataS), std::begin(dataD1), Function());
|
||||
int* p2 = etlstd::transform(std::begin(dataS), std::end(dataS), std::begin(dataD2), Function());
|
||||
|
||||
CHECK(p2 == std::end(dataD2));
|
||||
|
||||
bool isEqual = std::equal(std::begin(dataD1), std::end(dataD1), std::begin(dataD2));
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(transform2)
|
||||
{
|
||||
struct Function
|
||||
{
|
||||
int operator()(int d1, int d2) const
|
||||
{
|
||||
return d1 + d2;
|
||||
}
|
||||
};
|
||||
|
||||
int* p1 = std::transform(std::begin(dataS), std::end(dataS), std::begin(dataA), std::begin(dataD1), Function());
|
||||
int* p2 = etlstd::transform(std::begin(dataS), std::end(dataS), std::begin(dataA), std::begin(dataD2), Function());
|
||||
|
||||
CHECK(p2 == std::end(dataD2));
|
||||
|
||||
bool isEqual = std::equal(std::begin(dataD1), std::end(dataD1), std::begin(dataD2));
|
||||
CHECK(isEqual);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
96
test/test_no_stl_iterator.cpp
Normal file
96
test/test_no_stl_iterator.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2018 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "UnitTest++.h"
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
#include "etl/stl/alternate/iterator.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "no_stl_test_iterators.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
|
||||
int dataA[SIZE] = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 };
|
||||
|
||||
SUITE(test_no_stl_iterator)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(distance_non_random)
|
||||
{
|
||||
ptrdiff_t d = etlstd::distance(non_random_iterator<int>(&dataA[0]), non_random_iterator<int>(&dataA[SIZE]));
|
||||
|
||||
CHECK_EQUAL(SIZE, d);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(distance_random)
|
||||
{
|
||||
ptrdiff_t d = etlstd::distance(random_iterator<int>(&dataA[0]), random_iterator<int>(&dataA[SIZE]));
|
||||
|
||||
CHECK_EQUAL(SIZE, d);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(advance_non_random)
|
||||
{
|
||||
int* itr1 = std::begin(dataA);
|
||||
non_random_iterator<int> itr2 = std::begin(dataA);
|
||||
|
||||
std::advance(itr1, 4);
|
||||
etlstd::advance(itr2, 4);
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
|
||||
std::advance(itr1, -3);
|
||||
etlstd::advance(itr2, -3);
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(advance_random)
|
||||
{
|
||||
int* itr1 = std::begin(dataA);
|
||||
random_iterator<int> itr2 = std::begin(dataA);
|
||||
|
||||
std::advance(itr1, 4);
|
||||
etlstd::advance(itr2, 4);
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
|
||||
std::advance(itr1, -3);
|
||||
etlstd::advance(itr2, -3);
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -360,6 +360,7 @@
|
||||
<ClInclude Include="..\..\include\etl\atomic.h" />
|
||||
<ClInclude Include="..\..\include\etl\atomic\atomic_arm.h" />
|
||||
<ClInclude Include="..\..\include\etl\atomic\atomic_gcc_sync.h" />
|
||||
<ClInclude Include="..\..\include\etl\atomic\atomic_llvm_sync.h" />
|
||||
<ClInclude Include="..\..\include\etl\atomic\atomic_std.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer.h" />
|
||||
<ClInclude Include="..\..\include\etl\combinations.h" />
|
||||
@ -525,6 +526,7 @@
|
||||
<ClInclude Include="..\ecl_user.h" />
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
<ClInclude Include="..\murmurhash3.h" />
|
||||
<ClInclude Include="..\no_stl_test_iterators.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\unittest-cpp\UnitTest++\AssertException.cpp" />
|
||||
@ -688,6 +690,7 @@
|
||||
<ClCompile Include="..\test_multiset.cpp" />
|
||||
<ClCompile Include="..\test_murmur3.cpp" />
|
||||
<ClCompile Include="..\test_no_stl_functional.cpp" />
|
||||
<ClCompile Include="..\test_no_stl_iterator.cpp" />
|
||||
<ClCompile Include="..\test_no_stl_limits.cpp" />
|
||||
<ClCompile Include="..\test_no_stl_utility.cpp" />
|
||||
<ClCompile Include="..\test_numeric.cpp" />
|
||||
|
||||
@ -687,6 +687,12 @@
|
||||
<ClInclude Include="..\..\include\etl\math_constants.h">
|
||||
<Filter>ETL\Maths</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\no_stl_test_iterators.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\atomic\atomic_llvm_sync.h">
|
||||
<Filter>ETL\Utilities\Atomic</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\main.cpp">
|
||||
@ -1127,6 +1133,9 @@
|
||||
<ClCompile Include="..\test_list_shared_pool.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_no_stl_iterator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user