mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-30 06:18:50 +08:00
Added size_of<>
This commit is contained in:
parent
8fb468e708
commit
e3fa5b912c
@ -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