mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Variadic template etl::smallest
This commit is contained in:
parent
c01262b5b5
commit
0df67fa154
@ -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
|
||||
|
||||
@ -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 <typename T1, typename... TRest>
|
||||
class smallest_type
|
||||
{
|
||||
private:
|
||||
|
||||
// Define 'smallest_other' as 'smallest_type' with all but the first parameter.
|
||||
using smallest_other = typename smallest_type<TRest...>::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<T1>() < etl::size_of<smallest_other>()), // Boolean
|
||||
T1, // TrueType
|
||||
smallest_other> // FalseType
|
||||
::type; // The smallest type of the two.
|
||||
|
||||
// The size of the smallest type.
|
||||
enum
|
||||
{
|
||||
size = etl::size_of<type>()
|
||||
};
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for one template parameter.
|
||||
//***************************************************************************
|
||||
template <typename T1>
|
||||
class smallest_type<T1>
|
||||
{
|
||||
public:
|
||||
|
||||
using type = T1;
|
||||
|
||||
enum
|
||||
{
|
||||
size = etl::size_of<type>()
|
||||
};
|
||||
};
|
||||
#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 <const int index>
|
||||
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);
|
||||
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user