diff --git a/include/etl/generate_smallest.bat b/include/etl/generate_smallest.bat index fe53e938..65e4edf9 100644 --- a/include/etl/generate_smallest.bat +++ b/include/etl/generate_smallest.bat @@ -1 +1 @@ -python -m cogapp -d -e -olargest.h -DNTypes=16 largest_generator.h +python -m cogapp -d -e -osmallest.h -DNTypes=16 smallest_generator.h diff --git a/include/etl/smallest.h b/include/etl/smallest.h index 8b1337e1..b0e79020 100644 --- a/include/etl/smallest.h +++ b/include/etl/smallest.h @@ -63,6 +63,53 @@ SOFTWARE. namespace etl { +#if ETL_CPP11_SUPPORTED && !defined(ETL_SMALLEST_TYPE_FORCE_CPP03) + //*************************************************************************** + /// Template to determine the largest type and size. + /// Defines 'value_type' which is the type of the largest parameter. + /// Defines 'size' which is the size of the largest parameter. + ///\ingroup largest + //*************************************************************************** + template + class smallest_type + { + private: + + // Define 'smallest_other' as 'smallest_type' with all but the first parameter. + using smallest_other = typename smallest_type::type; + + public: + + // Set 'type' to be the smallest of the first parameter and any of the others. + // This is recursive. + using type = typename etl::conditional<(etl::size_of() < etl::size_of()), // Boolean + T1, // TrueType + smallest_other> // FalseType + ::type; // The smallest type of the two. + + // The size of the smallest type. + enum + { + size = etl::size_of() + }; + }; + + //*************************************************************************** + // Specialisation for one template parameter. + //*************************************************************************** + template + class smallest_type + { + public: + + using type = T1; + + enum + { + size = etl::size_of() + }; + }; +#else //*************************************************************************** /// Template to determine the smallest type and size. /// Supports up to 16 types. @@ -131,7 +178,8 @@ namespace etl size = sizeof(type) }; }; - +#endif + namespace private_smallest { //************************************************************************* @@ -139,7 +187,7 @@ namespace etl //************************************************************************* template struct best_fit_uint_type; - + //************************************************************************* // Less than or equal to 8 bits. //************************************************************************* @@ -220,7 +268,7 @@ namespace etl } //*************************************************************************** - /// Template to determine the smallest unsigned int type that can contain a + /// Template to determine the smallest unsigned int type that can contain a /// value with the specified number of bits. /// Defines 'type' which is the type of the smallest unsigned integer. ///\ingroup smallest @@ -229,9 +277,9 @@ namespace etl struct smallest_uint_for_bits { private: - + // Determines the index of the best unsigned type for the required number of bits. - static const int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + + static const int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + ((NBITS > 16) ? 1 : 0) + ((NBITS > 32) ? 1 : 0); @@ -241,7 +289,7 @@ namespace etl }; //*************************************************************************** - /// Template to determine the smallest signed int type that can contain a + /// Template to determine the smallest signed int type that can contain a /// value with the specified number of bits. /// Defines 'type' which is the type of the smallest signed integer. ///\ingroup smallest @@ -274,7 +322,7 @@ namespace etl // Determines the index of the best unsigned type for the required value. static const int TYPE_INDEX = ((VALUE > UINT_LEAST8_MAX) ? 1 : 0) + - ((VALUE > UINT16_MAX) ? 1 : 0) + + ((VALUE > UINT16_MAX) ? 1 : 0) + ((VALUE > UINT32_MAX) ? 1 : 0); public: @@ -294,7 +342,7 @@ namespace etl private: // Determines the index of the best signed type for the required value. - static const int TYPE_INDEX = (((VALUE > INT_LEAST8_MAX) || (VALUE < INT_LEAST8_MIN)) ? 1 : 0) + + static const int TYPE_INDEX = (((VALUE > INT_LEAST8_MAX) || (VALUE < INT_LEAST8_MIN)) ? 1 : 0) + (((VALUE > INT16_MAX) || (VALUE < INT16_MIN)) ? 1 : 0) + (((VALUE > INT32_MAX) || (VALUE < INT32_MIN)) ? 1 : 0); diff --git a/include/etl/version.h b/include/etl/version.h index 4d6f366a..970ebd80 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 24 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_MINOR 25 +#define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) diff --git a/support/Release notes.txt b/support/Release notes.txt index 1578bab8..0d23f4a8 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +14.25.0 +Added variadic template versions of etl::largest, etl::largest_type, +etl::largest_alignment and etl::smallest + =============================================================================== 14.24.2 Fixed bug in 'vector of pointers' move constructor.