diff --git a/include/etl/atomic/atomic_gcc_sync.h b/include/etl/atomic/atomic_gcc_sync.h index c866d85e..2bdcea49 100644 --- a/include/etl/atomic/atomic_gcc_sync.h +++ b/include/etl/atomic/atomic_gcc_sync.h @@ -222,12 +222,12 @@ namespace etl } // Load - T load(etl::memory_order order = etl::memory_order_seq_cst) + 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) volatile + T load(etl::memory_order order = etl::memory_order_seq_cst) const volatile { return __sync_fetch_and_add(&value, 0); } @@ -429,7 +429,7 @@ namespace etl atomic& operator =(const atomic&); atomic& operator =(const atomic&) volatile; - volatile T value; + mutable volatile T value; }; template @@ -562,12 +562,12 @@ namespace etl } // Load - T* load(etl::memory_order order = etl::memory_order_seq_cst) + 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) volatile + T* load(etl::memory_order order = etl::memory_order_seq_cst) const volatile { return __sync_fetch_and_add(&value, 0); } @@ -736,7 +736,7 @@ namespace etl atomic& operator =(const atomic&); atomic& operator =(const atomic&) volatile; - volatile T* value; + mutable volatile T* value; }; typedef etl::atomic atomic_char; diff --git a/include/etl/atomic/atomic_std.h b/include/etl/atomic/atomic_std.h index 7c957cab..fe663ff1 100644 --- a/include/etl/atomic/atomic_std.h +++ b/include/etl/atomic/atomic_std.h @@ -210,12 +210,12 @@ namespace etl } // Load - T load(etl::memory_order order = etl::memory_order_seq_cst) + T load(etl::memory_order order = etl::memory_order_seq_cst) const { return value.load(order); } - T load(etl::memory_order order = etl::memory_order_seq_cst) volatile + T load(etl::memory_order order = etl::memory_order_seq_cst) const volatile { return value.load(order); } diff --git a/include/etl/memory.h b/include/etl/memory.h index 9a886af3..941b841f 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -5,7 +5,7 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com Copyright(c) 2017 jwellbelove @@ -120,7 +120,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value) + TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value) { return etl::uninitialized_fill(o_begin, o_begin + n, value); } @@ -131,7 +131,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count) + TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count) { count += n; @@ -207,7 +207,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin) + TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin) { return etl::uninitialized_copy(i_begin, i_begin + n, o_begin); } @@ -218,7 +218,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count) + TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count) { count += n; @@ -389,7 +389,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void create_value_at(T* p) + void create_value_at(T* p) { ::new (p) T(); } @@ -399,7 +399,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void create_value_at(T* p, TCounter& count) + void create_value_at(T* p, TCounter& count) { ::new (p) T(); ++count; @@ -410,7 +410,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void create_copy_at(T* p, const T& value) + void create_copy_at(T* p, const T& value) { ::new (p) T(value); } @@ -420,7 +420,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void create_copy_at(T* p, const T& value, TCounter& count) + void create_copy_at(T* p, const T& value, TCounter& count) { ::new (p) T(value); ++count; @@ -431,7 +431,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline T& make_default_at(T* p) + T& make_default_at(T* p) { ::new (p) T(); return *reinterpret_cast(p); @@ -442,7 +442,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline T& make_default_at(T* p, TCounter& count) + T& make_default_at(T* p, TCounter& count) { ::new (p) T(); ++count; @@ -454,7 +454,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline T& make_copy_at(T* p, const T& other) + T& make_copy_at(T* p, const T& other) { ::new (p) T(other); return *reinterpret_cast(p); @@ -465,7 +465,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline T& make_copy_at(T* p, const T& other, TCounter& count) + T& make_copy_at(T* p, const T& other, TCounter& count) { ::new (p) T(other); ++count; @@ -477,7 +477,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline T& make_value_at(T* p, const TParameter& value) + T& make_value_at(T* p, const TParameter& value) { ::new (p) T(value); return *reinterpret_cast(p); @@ -488,7 +488,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline T& make_value_at(T* p, const TParameter& value, TCounter& count) + T& make_value_at(T* p, const TParameter& value, TCounter& count) { ::new (p) T(value); ++count; @@ -767,6 +767,252 @@ namespace etl return *reinterpret_cast(p); } }; + + //***************************************************************************** + /// Unique pointer. + ///\tparam T The pointed to type type. + ///\ingroup memory + //***************************************************************************** + template + class unique_ptr + { + public: + + typedef T element_type; + typedef T* pointer; + typedef T& reference; + + ETL_CONSTEXPR unique_ptr() + : p(nullptr) + { + } + + ETL_CONSTEXPR explicit unique_ptr (pointer p_) + : p(p_) + { + } + +#if ETL_CPP11_SUPPORTED + unique_ptr (unique_ptr&& p_) + : p(p_.release()) + { + } +#endif + + ~unique_ptr() + { + delete p; + } + + ETL_CONSTEXPR pointer get() const + { + return p; + } + + pointer release() + { + pointer value = p; + p = nullptr; + + return value; + } + + void reset(pointer p_ = pointer()) + { + assert(p_ != p); + + pointer value = p; + p = p_; + delete value; + } + + void swap(unique_ptr& value) + { + std::swap(p, value.p); + } + + ETL_CONSTEXPR explicit operator bool() const + { + return (p != nullptr); + } + + unique_ptr& operator =(pointer p_) + { + reset(p_); + + return *this; + } + +#if ETL_CPP11_SUPPORTED + unique_ptr& operator =(unique_ptr&& p_) + { + reset(p_.release()); + + return *this; + } +#endif + + ETL_CONSTEXPR reference operator *() const + { + return *get(); + } + + ETL_CONSTEXPR pointer operator ->() const + { + return get(); + } + + ETL_CONSTEXPR reference operator [](size_t i) const + { + return get()[i]; + } + + ETL_CONSTEXPR bool operator== (const pointer p_) const + { + return p == p_; + } + + ETL_CONSTEXPR bool operator== (const unique_ptr& p_) const + { + return p == p_.p; + } + + ETL_CONSTEXPR bool operator< (const unique_ptr& p_) const + { + return p < p_.p; + } + + private: + + // Deleted. + unique_ptr(const unique_ptr&); + unique_ptr& operator =(const unique_ptr&); + + pointer p; + }; + + + //***************************************************************************** + /// Unique pointer for arrays. + ///\tparam T The pointed to type type. + ///\ingroup memory + //***************************************************************************** + template + class unique_ptr + { + public: + + typedef T element_type; + typedef T* pointer; + typedef T& reference; + + ETL_CONSTEXPR unique_ptr() + : p(nullptr) + { + } + + ETL_CONSTEXPR explicit unique_ptr(pointer p_) + : p(p_) + { + } + +#if ETL_CPP11_SUPPORTED + unique_ptr(unique_ptr&& p_) + : p(p_.release()) + { + } +#endif + + ~unique_ptr() + { + delete[] p; + } + + ETL_CONSTEXPR pointer get() const + { + return p; + } + + pointer release() + { + pointer value = p; + p = nullptr; + return value; + } + + void reset(pointer p_) + { + assert(p_ != p); + + pointer value = p; + p = p_; + delete[] value; + } + + void swap(unique_ptr& v) + { + std::swap(p, v.p); + } + + ETL_CONSTEXPR explicit operator bool() const + { + return (p != nullptr); + } + + unique_ptr& operator =(pointer p_) + { + reset(p_); + + return *this; + } + +#if ETL_CPP11_SUPPORTED + unique_ptr& operator =(unique_ptr&& p_) + { + reset(p_.release()); + + return *this; + } +#endif + + ETL_CONSTEXPR reference operator *() const + { + return *p; + } + + ETL_CONSTEXPR pointer operator ->() const + { + return p; + } + + ETL_CONSTEXPR reference operator [](size_t i) const + { + return p[i]; + } + + ETL_CONSTEXPR bool operator ==(const pointer p_) const + { + return (p == p_); + } + + ETL_CONSTEXPR bool operator ==(const unique_ptr& p_) const + { + return (p == p_.p); + } + + ETL_CONSTEXPR bool operator <(const unique_ptr& p_) const + { + return (p < p_.p); + } + + private: + + // Deleted. + unique_ptr(const unique_ptr&); + unique_ptr& operator =(const unique_ptr&); + + pointer p; + }; } #endif diff --git a/include/etl/version.h b/include/etl/version.h index fb81796b..c13c8c8e 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,10 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.12.0" +#define ETL_VERSION "11.12.1" #define ETL_VERSION_MAJOR 11 #define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 1 #endif diff --git a/support/Release notes.txt b/support/Release notes.txt index fc86ae10..7ef5910e 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +11.12.1 +Made atomic load const for non STL vesions + =============================================================================== 11.12.0 Renamed STATIC_ASSERT to ETL_STATIC_ASSERT diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index d866d331..d5fc33a3 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -39,7 +39,7 @@ Win32Proj unittest etl - 10.0.16299.0 + 10.0.17134.0