From f4344818a384c85606ca50504f3fbb9f363cb8fb Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 21 Jun 2016 21:37:20 +0100 Subject: [PATCH] Removed template functions with default templare aurguments. Not compatible with C++ 03 --- src/hash.h | 202 ++++++++++++++--------------------- src/intrusive_forward_list.h | 157 ++++++++------------------- src/intrusive_list.h | 128 +++++++--------------- 3 files changed, 163 insertions(+), 324 deletions(-) diff --git a/src/hash.h b/src/hash.h index 1cb310df..1802d311 100644 --- a/src/hash.h +++ b/src/hash.h @@ -215,20 +215,17 @@ namespace etl struct hash { // If it fits into a size_t. - template - typename etl::enable_if= sizeof(T), size_t>::type - operator ()(T v) const + size_t operator ()(long v) const { - return static_cast(v); - } - - // If it doesn't fit into a size_t. - template - typename etl::enable_if::type - operator ()(T v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) >= sizeof(v)) + { + return static_cast(v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; @@ -240,20 +237,17 @@ namespace etl struct hash { // If it fits into a size_t. - template - typename etl::enable_if= sizeof(T), size_t>::type - operator ()(T v) const + size_t operator ()(long long v) const { - return static_cast(v); - } - - // If it doesn't fit into a size_t. - template - typename etl::enable_if::type - operator ()(T v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) >= sizeof(v)) + { + return static_cast(v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; @@ -265,20 +259,17 @@ namespace etl struct hash { // If it fits into a size_t. - template - typename etl::enable_if= sizeof(T), size_t>::type - operator ()(T v) const + size_t operator ()(unsigned long v) const { - return static_cast(v); - } - - // If it doesn't fit into a size_t. - template - typename etl::enable_if::type - operator ()(T v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) >= sizeof(v)) + { + return static_cast(v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; @@ -290,20 +281,17 @@ namespace etl struct hash { // If it fits into a size_t. - template - typename etl::enable_if= sizeof(T), size_t>::type - operator ()(T v) const + size_t operator ()(unsigned long long v) const { - return static_cast(v); - } - - // If it doesn't fit into a size_t. - template - typename etl::enable_if::type - operator ()(T v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) >= sizeof(v)) + { + return static_cast(v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; @@ -315,20 +303,17 @@ namespace etl struct hash { // If it's the same size as a size_t. - template - typename etl::enable_if::type - operator ()(T v) const + size_t operator ()(float v) const { - return *reinterpret_cast(&v); - } - - // If it's not the same size as a size_t. - template - typename etl::enable_if::type - operator ()(T v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) == sizeof(v)) + { + return *reinterpret_cast(&v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; @@ -340,20 +325,17 @@ namespace etl struct hash { // If it's the same size as a size_t. - template - typename etl::enable_if::type - operator ()(T v) const + size_t operator ()(double v) const { - return *reinterpret_cast(&v); - } - - // If it's not the same size as a size_t. - template - typename etl::enable_if::type - operator ()(T v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) == sizeof(v)) + { + return *reinterpret_cast(&v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; @@ -365,20 +347,17 @@ namespace etl struct hash { // If it's the same size as a size_t. - template - typename etl::enable_if::type - operator ()(T v) const + size_t operator ()(long double v) const { - return *reinterpret_cast(&v); - } - - // If it's not the same size as a size_t. - template - typename etl::enable_if::type - operator ()(T v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) == sizeof(v)) + { + return *reinterpret_cast(&v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; @@ -389,38 +368,17 @@ namespace etl template struct hash { - // If it's the same size as a size_t. - template - typename etl::enable_if::type - operator ()(U* v) const + size_t operator ()(const T* v) const { - return reinterpret_cast(v); - } - - // If it's the same size as a size_t. - template - typename etl::enable_if::type - operator ()(const U* v) const - { - return reinterpret_cast(v); - } - - // If it's not the same size as a size_t. - template - typename etl::enable_if::type - operator ()(U* v) const - { - uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); - } - - // If it's not the same size as a size_t. - template - typename etl::enable_if::type - operator ()(const U* v) const - { - const uint8_t* p = reinterpret_cast(&v); - return __private_hash__::generic_hash(p, p + sizeof(v)); + if (sizeof(size_t) == sizeof(T*)) + { + return reinterpret_cast(v); + } + else + { + uint8_t* p = reinterpret_cast(&v); + return __private_hash__::generic_hash(p, p + sizeof(v)); + } } }; } diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 4546b8a7..401b77dc 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -31,7 +31,9 @@ SOFTWARE. #ifndef __ETL_INTRUSIVE_FORWARD_LIST__ #define __ETL_INTRUSIVE_FORWARD_LIST__ -#if WIN32 +#include "platform.h" + +#ifdef ETL_COMPILER_MICROSOFT #undef min #endif @@ -494,55 +496,32 @@ namespace etl //************************************************************************* /// Inserts a value to the intrusive_forward_list after the specified position. + /// Checks that the value is unlinked if CHECKED. //************************************************************************* - template - typename etl::enable_if::type - insert_after(iterator position, value_type& value) + iterator insert_after(iterator position, value_type& value) { - insert_link_after(*position.p_value, value); - return iterator(value); - } - - //************************************************************************* - /// Inserts a value to the intrusive_forward_list after the specified position. - /// Checks that the value is unlinked. - //************************************************************************* - template - typename etl::enable_if::type - insert_after(iterator position, value_type& value) - { - ETL_ASSERT(!value.TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); - - insert_link_after(*position.p_value, value); - return iterator(value); - } - - //************************************************************************* - /// Inserts a range of values to the intrusive_forward_list after the specified position. - //************************************************************************* - template - typename etl::enable_if::type - insert_after(iterator position, TIterator first, TIterator last) - { - while (first != last) + if (TLink::OPTION == etl::link_option::CHECKED) { - // Set up the next free link. - insert_link_after(*position.p_value, *first++); - ++position; + ETL_ASSERT(!value.TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); } + + insert_link_after(*position.p_value, value); + return iterator(value); } //************************************************************************* /// Inserts a range of values to the intrusive_forward_list after the specified position. - /// Checks that the values are unlinked. + /// Checks that the values are unlinked if CHECKED. //************************************************************************* - template - typename etl::enable_if::type - insert_after(iterator position, TIterator first, TIterator last) + template + void insert_after(iterator position, TIterator first, TIterator last) { while (first != last) { - ETL_ASSERT(!position.p_value->TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); + if (TLink::OPTION == etl::link_option::CHECKED) + { + ETL_ASSERT(!position.p_value->TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); + } // Set up the next free link. insert_link_after(*position.p_value, *first++); @@ -552,81 +531,29 @@ namespace etl //************************************************************************* /// Erases the value at the specified position. + /// Clears the link after erasing if CHECKED. //************************************************************************* - template - typename etl::enable_if::type - erase_after(iterator position) + iterator erase_after(iterator position) { iterator next(position); ++next; ++next; remove_link_after(*position.p_value); - - return next; - } - - //************************************************************************* - /// Erases the value at the specified position. - /// Clears the link after erasing. - //************************************************************************* - template - typename etl::enable_if::type - erase_after(iterator position) - { - iterator next(position); - ++next; - ++next; - - remove_link_after(*position.p_value); - position.p_value->TLink::clear(); + + if (TLink::OPTION == etl::link_option::CHECKED) + { + position.p_value->TLink::clear(); + } return next; } //************************************************************************* /// Erases a range of elements. + /// Clears the links after erasing if CHECKED. //************************************************************************* - template - typename etl::enable_if::type - erase_after(iterator first, iterator last) - { - link_type* p_first = first.p_value; - link_type* p_last = last.p_value; - link_type* p_next = p_first->etl_next; - - // Join the ends. - etl::link(p_first, p_last); - - p_first = p_next; - - // Erase the ones in between. - while (p_first != p_last) - { - // One less. - --current_size; - - p_next = p_first->etl_next; // Remember the next link. - p_first = p_next; // Move to the next link. - } - - if (p_next == nullptr) - { - return end(); - } - else - { - return iterator(*static_cast(p_last)); - } - } - - //************************************************************************* - /// Erases a range of elements. - /// Clears the links after erasing. - //************************************************************************* - template - typename etl::enable_if::type - erase_after(iterator first, iterator last) + iterator erase_after(iterator first, iterator last) { link_type* p_first = first.p_value; link_type* p_last = last.p_value; @@ -644,7 +571,12 @@ namespace etl --current_size; p_next = p_first->etl_next; // Remember the next link. - p_first->TLink::clear(); // Clear the link. + + if (TLink::OPTION == etl::link_option::CHECKED) + { + p_first->TLink::clear(); // Clear the link. + } + p_first = p_next; // Move to the next link. } @@ -871,21 +803,16 @@ namespace etl //************************************************************************* /// Returns the number of elements. //************************************************************************* - template - typename etl::enable_if::type - size() const + size_t size() const { - return current_size.count; - } - - //************************************************************************* - /// Returns the number of elements. - //************************************************************************* - template - typename etl::enable_if::type - size() const - { - return std::distance(cbegin(), cend()); + if (COUNT_OPTION == etl::count_option::SLOW_COUNT) + { + return std::distance(cbegin(), cend()); + } + else + { + return current_size.count; + } } //************************************************************************* @@ -1216,7 +1143,7 @@ namespace etl }; } -#if WIN32 +#ifdef ETL_COMPILER_MICROSOFT #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif diff --git a/src/intrusive_list.h b/src/intrusive_list.h index e08c3a49..19f66a77 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -31,7 +31,9 @@ SOFTWARE. #ifndef __ETL_INTRUSIVE_LIST__ #define __ETL_INTRUSIVE_LIST__ -#if WIN32 +#include "platform.h" + +#ifdef ETL_COMPILER_MICROSOFT #undef min #endif @@ -532,54 +534,32 @@ namespace etl //************************************************************************* /// Inserts a value to the intrusive_list before the specified position. + /// Checks that the value is unlinked if CHECKED //************************************************************************* - template - typename etl::enable_if<(T::OPTION == etl::link_option::DEFAULT) || (T::OPTION == etl::link_option::AUTO), iterator>::type - insert(iterator position, value_type& value) + iterator insert(iterator position, value_type& value) { + if (TLink::OPTION == etl::link_option::CHECKED) + { + ETL_ASSERT(!value.TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); + } + insert_link(position.p_value->link_type::etl_previous, value); return iterator(value); } - //************************************************************************* - /// Inserts a value to the intrusive_list before the specified position. - /// Checks that the value is unlinked. - //************************************************************************* - template - typename etl::enable_if::type - insert(iterator position, value_type& value) - { - ETL_ASSERT(!value.TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); - - insert_link(position.p_value->etl_previous, value); - return iterator(value); - } - - //************************************************************************* - /// Inserts a range of values to the intrusive_list before the specified position. - //************************************************************************* - template - typename etl::enable_if<(T::OPTION == etl::link_option::DEFAULT) || (T::OPTION == etl::link_option::AUTO), void>::type - insert(iterator position, TIterator first, TIterator last) - { - while (first != last) - { - // Set up the next free link. - insert_link(*position.p_value->link_type::etl_previous, *first++); - } - } - //************************************************************************* /// Inserts a range of values to the intrusive_list after the specified position. - /// Checks that the values are unlinked. + /// Checks that the values are unlinked if CHECKED. //************************************************************************* - template - typename etl::enable_if::type - insert(iterator position, TIterator first, TIterator last) + template + void insert(iterator position, TIterator first, TIterator last) { while (first != last) { - ETL_ASSERT(!position.p_value->TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); + if (TLink::OPTION == etl::link_option::CHECKED) + { + ETL_ASSERT(!position.p_value->TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); + } // Set up the next free link. insert_link(*position.p_value->link_type::etl_previous, *first++); @@ -601,10 +581,9 @@ namespace etl //************************************************************************* /// Erases a range of elements. + /// Clears the links after erasing if AUTO or CHECKED. //************************************************************************* - template - typename etl::enable_if::type - erase(iterator first, iterator last) + iterator erase(iterator first, iterator last) { link_type* p_first = first.p_value; link_type* p_last = last.p_value; @@ -617,41 +596,21 @@ namespace etl current_size -= std::distance(first, last); } - if (p_last == &terminal_link) + if ((TLink::OPTION == etl::link_option::AUTO) || + (TLink::OPTION == etl::link_option::CHECKED)) { - return end(); - } - else - { - return iterator(*static_cast(p_last)); - } - } + // Clear the ones in between. + link_type* p_next; - //************************************************************************* - /// Erases a range of elements. - /// Clears the links after erasing. - //************************************************************************* - template - typename etl::enable_if<(T::OPTION == etl::link_option::AUTO) || (T::OPTION == etl::link_option::CHECKED), iterator>::type - erase(iterator first, iterator last) - { - link_type* p_first = first.p_value; - link_type* p_last = last.p_value; + while (p_first != p_last) + { + // One less. + --current_size; - // Join the ends. - etl::link(p_first->etl_previous, p_last); - - // Clear the ones in between. - link_type* p_next; - - while (p_first != p_last) - { - // One less. - --current_size; - - p_next = p_first->etl_next; // Remember the next link. - p_first->TLink::clear(); // Clear the link. - p_first = p_next; // Move to the next link. + p_next = p_first->etl_next; // Remember the next link. + p_first->TLink::clear(); // Clear the link. + p_first = p_next; // Move to the next link. + } } if (p_last == &terminal_link) @@ -867,21 +826,16 @@ namespace etl //************************************************************************* /// Returns the number of elements. //************************************************************************* - template - typename etl::enable_if::type - size() const + size_t size() const { - return current_size.count; - } - - //************************************************************************* - /// Returns the number of elements. - //************************************************************************* - template - typename etl::enable_if::type - size() const - { - return std::distance(cbegin(), cend()); + if (COUNT_OPTION == etl::count_option::SLOW_COUNT) + { + return std::distance(cbegin(), cend()); + } + else + { + return current_size.count; + } } //************************************************************************* @@ -1237,7 +1191,7 @@ namespace etl }; } -#if WIN32 +#ifdef ETL_COMPILER_MICROSOFT #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif