mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-29 22:08:45 +08:00
Merge remote-tracking branch 'origin/feature/size_of' into development
This commit is contained in:
commit
1986e8344e
@ -335,7 +335,7 @@ namespace etl
|
||||
struct conditional_integral_constant<false, T, TRUE_VALUE, FALSE_VALUE>
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
|
||||
static const T value = FALSE_VALUE;
|
||||
static const T value = FALSE_VALUE;
|
||||
};
|
||||
|
||||
/// make_signed
|
||||
@ -485,14 +485,14 @@ namespace etl
|
||||
///\ingroup types
|
||||
//***************************************************************************
|
||||
template <typename T,
|
||||
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void,
|
||||
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void,
|
||||
typename T17 = void>
|
||||
struct is_one_of
|
||||
{
|
||||
static const bool value =
|
||||
static const bool value =
|
||||
etl::is_same<T, T1>::value ||
|
||||
etl::is_same<T, T2>::value ||
|
||||
etl::is_same<T, T3>::value ||
|
||||
@ -586,6 +586,21 @@ namespace etl
|
||||
typedef const type_t* const_pointer;
|
||||
typedef const type_t* const const_pointer_const;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// size_of
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
struct size_of
|
||||
{
|
||||
static const size_t size = sizeof(T);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct size_of<void>
|
||||
{
|
||||
static const size_t size = 1;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -598,6 +598,21 @@ namespace etl
|
||||
typedef const type_t* const_pointer;
|
||||
typedef const type_t* const const_pointer_const;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// size_of
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
struct size_of
|
||||
{
|
||||
static const size_t size = sizeof(T);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct size_of<void>
|
||||
{
|
||||
static const size_t size = 1;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -41,6 +41,20 @@ namespace std
|
||||
#include "etl/type_traits.h"
|
||||
#include <type_traits>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct TestData { };
|
||||
}
|
||||
|
||||
namespace etl
|
||||
{
|
||||
template <>
|
||||
struct etl::size_of<TestData>
|
||||
{
|
||||
static const size_t size = 20;
|
||||
};
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
// A class to test non-fundamental types.
|
||||
@ -728,4 +742,14 @@ namespace
|
||||
CHECK_EQUAL(1, v1);
|
||||
CHECK_EQUAL(2, v2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(size_of)
|
||||
{
|
||||
CHECK_EQUAL(1, etl::size_of<void>::size);
|
||||
CHECK_EQUAL(1, etl::size_of<char>::size);
|
||||
CHECK_EQUAL(2, etl::size_of<short>::size);
|
||||
CHECK_EQUAL(4, etl::size_of<int>::size);
|
||||
CHECK_EQUAL(20, etl::size_of<TestData>::size);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user