Work in progress

This commit is contained in:
John Wellbelove 2023-01-26 11:43:49 +00:00
parent f4dd3c3363
commit f1a9705d88
14 changed files with 111 additions and 32 deletions

View File

@ -105,6 +105,11 @@ namespace etl
template <typename T, const T VALUE>
const T integral_constant<T, VALUE>::value;
#if ETL_USING_CPP17
template <typename T, T VALUE>
inline constexpr T integral_constant_v = std::integral_constant<T, VALUE>::value;
#endif
#if ETL_USING_CPP11
template <bool B>
using bool_constant = integral_constant<bool, B>;
@ -113,6 +118,11 @@ namespace etl
struct bool_constant : etl::integral_constant<bool, B> { };
#endif
#if ETL_USING_CPP17
template <bool B>
inline constexpr bool bool_constant_v = std::bool_constant<B>::value;
#endif
//***************************************************************************
/// negation
template <typename T>
@ -806,7 +816,7 @@ namespace etl
//***************************************************************************
/// integral_constant
///\ingroup type_traits
template <typename T, const T VALUE>
template <typename T, T VALUE>
struct integral_constant : std::integral_constant<T, VALUE> {};
/// integral_constant specialisations
@ -815,8 +825,8 @@ namespace etl
typedef integral_constant<bool, true> true_type;
#if ETL_USING_CPP17
template <typename T>
using integral_constant_v = std::integral_constant<T>::value;
template <typename T, T VALUE>
inline constexpr T integral_constant_v = std::integral_constant<T, VALUE>::value;
#endif
#if ETL_USING_CPP17
@ -827,6 +837,11 @@ namespace etl
struct bool_constant : std::integral_constant<bool, B> { };
#endif
#if ETL_USING_CPP17
template <bool B>
inline constexpr bool bool_constant_v = std::bool_constant<B>::value;
#endif
//***************************************************************************
/// negation
///\ingroup type_traits

View File

@ -290,7 +290,7 @@ namespace
std::string inner;
};
std::array results
std::array<result, 64U> results
{
result{ 0, 2, "zero" }, result{ 0, 2, "one" }, result{ 0, 2, "two" }, result{ 0, 2, "three" },
result{ 0, 1, "zero" }, result{ 0, 1, "one" }, result{ 0, 1, "two" }, result{ 0, 1, "three" },
@ -373,7 +373,7 @@ namespace
std::string inner;
};
std::array results
std::array<result, 16U> results
{
result{ 0, 2, "zero" }, result{ 0, 2, "one" }, result{ 0, 2, "two" }, result{ 0, 2, "three" },
result{ 0, 1, "zero" }, result{ 0, 1, "one" }, result{ 0, 1, "two" }, result{ 0, 1, "three" },

View File

@ -103,7 +103,7 @@ namespace
{
Data data("Hello");
etl::optional opt{ data };
etl::optional<Data> opt{ data };
CHECK(opt.has_value());
CHECK(bool(opt));

View File

@ -65,7 +65,7 @@ namespace
//*************************************************************************
TEST(integral_signed_average_positive_via_iterator)
{
std::array data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 };
std::array<int, 10> data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 };
using CMA = etl::pseudo_moving_average<int, SAMPLE_SIZE, SCALING>;
CMA cma(0);
@ -101,7 +101,7 @@ namespace
//*************************************************************************
TEST(integral_signed_average_negative_via_iterator)
{
std::array data{ -9, -1, -8, -2, -7, -3, -6, -4, -5 };
std::array<int, 10> data{ -9, -1, -8, -2, -7, -3, -6, -4, -5 };
using CMA = etl::pseudo_moving_average<int, SAMPLE_SIZE, SCALING>;
CMA cma(0);
@ -137,7 +137,7 @@ namespace
//*************************************************************************
TEST(integral_unsigned_average_positive_via_iterator)
{
std::array data{ 9U, 1U, 8U, 2U, 7U, 3U, 6U, 4U, 5U };
std::array<unsigned int, 10> data{ 9U, 1U, 8U, 2U, 7U, 3U, 6U, 4U, 5U };
using CMA = etl::pseudo_moving_average<unsigned int, SAMPLE_SIZE, SCALING>;
CMA cma(0U);
@ -175,7 +175,7 @@ namespace
//*************************************************************************
TEST(integral_signed_average_positive_runtime_sample_size_via_iterator)
{
std::array data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 };
std::array<int, 10> data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 };
using CMA = etl::pseudo_moving_average<int, 0U, SCALING>;
CMA cma(0, SAMPLE_SIZE * 2U);
@ -215,7 +215,7 @@ namespace
//*************************************************************************
TEST(integral_signed_average_negative_runtime_sample_size_via_iterator)
{
std::array data{ -9, -1, -8, -2, -7, -3, -6, -4, -5 };
std::array<int, 10> data{ -9, -1, -8, -2, -7, -3, -6, -4, -5 };
using CMA = etl::pseudo_moving_average<int, 0U, SCALING>;
CMA cma(0, SAMPLE_SIZE * 2U);
@ -255,7 +255,7 @@ namespace
//*************************************************************************
TEST(integral_unsigned_average_positive_runtime_sample_size_via_iterator)
{
std::array data{ 9U, 1U, 8U, 2U, 7U, 3U, 6U, 4U, 5U };
std::array<unsigned int, 10> data{ 9U, 1U, 8U, 2U, 7U, 3U, 6U, 4U, 5U };
using CMA = etl::pseudo_moving_average<int, 0U, SCALING>;
CMA cma(0U, SAMPLE_SIZE * 2U);
@ -293,7 +293,7 @@ namespace
//*************************************************************************
TEST(floating_point_average_via_iterator)
{
std::array data{ 9.0, 1.0, 8.0, 2.0, 7.0, 3.0, 6.0, 4.0, 5.0 };
std::array<double, 10> data{ 9.0, 1.0, 8.0, 2.0, 7.0, 3.0, 6.0, 4.0, 5.0 };
using CMA = etl::pseudo_moving_average<double, SAMPLE_SIZE>;
CMA cma(0);
@ -331,7 +331,7 @@ namespace
//*************************************************************************
TEST(floating_point_average_runtime_sample_size_via_iterator)
{
std::array data{ 9.0, 1.0, 8.0, 2.0, 7.0, 3.0, 6.0, 4.0, 5.0 };
std::array<double, 10> data{ 9.0, 1.0, 8.0, 2.0, 7.0, 3.0, 6.0, 4.0, 5.0 };
using CMA = etl::pseudo_moving_average<double, 0U>;
CMA cma(0, SAMPLE_SIZE * 2);

View File

@ -55,22 +55,24 @@ namespace
CHECK(type);
}
//*************************************************************************
TEST(test_pod_vt)
{
size_t size;
bool type;
#if ETL_USING_CPP17
size = etl::smallest_type_v<char, short, int>;
type = etl::is_same<char, etl::smallest_type_t<char, short, int>>::value;
CHECK_EQUAL(sizeof(char), size);
#endif
type = etl::is_same<char, etl::smallest_type_t<char, short, int>>::value;
CHECK(type);
size = etl::smallest_type<int, char, short>::size;
type = etl::is_same<char, etl::smallest_type<char, short, int>::type>::value;
CHECK_EQUAL(sizeof(char), size);
type = etl::is_same<char, etl::smallest_type<char, short, int>::type>::value;
CHECK(type);
}
@ -107,16 +109,20 @@ namespace
struct S2 { char a; short b; char c; };
struct S3 { int a; short b; char c; };
#if ETL_USING_CPP17
size = etl::smallest_type_v<S1, S2, S3>;
type = etl::is_same<S1, etl::smallest_type_t<S1, S2, S3>>::value;
CHECK_EQUAL(sizeof(S1), size);
#endif
type = etl::is_same<S1, etl::smallest_type_t<S1, S2, S3>>::value;
CHECK(type);
#if ETL_USING_CPP17
size = etl::smallest_type_v<S2, S3, S1>;
type = etl::is_same<S1, etl::smallest_type_t<S2, S3, S1>>::value;
CHECK_EQUAL(sizeof(S1), size);
#endif
type = etl::is_same<S1, etl::smallest_type_t<S2, S3, S1>>::value;
CHECK(type);
}

View File

@ -38,6 +38,9 @@ SOFTWARE.
#undef STR
#define STR(x) x
#undef STR_PTR
#define STR_PTR const char*
namespace
{
SUITE(test_string_utilities_char)
@ -51,7 +54,11 @@ namespace
using Vector = etl::vector<String, 15>;
using SizeType = etl::istring::size_type;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -40,6 +40,9 @@ SOFTWARE.
#undef STR
#define STR(x) x
#undef STR_PTR
#define STR_PTR const char*
namespace
{
SUITE(test_string_utilities_std_char)
@ -50,7 +53,11 @@ namespace
using Char = std::string::value_type;
using Vector = std::vector<String>;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -36,7 +36,10 @@ SOFTWARE.
#include "etl/string_utilities.h"
#undef STR
#define STR(x) L##x
#define STR(x) u##x
#undef STR_PTR
#define STR_PTR const char16_t*
namespace
{
@ -50,13 +53,19 @@ namespace
SUITE(test_string_utilities_std_u16)
{
using String = std::wstring;
using IString = std::wstring;
using StringView = std::wstring_view;
using Char = std::wstring::value_type;
using String = std::u16string;
using IString = std::u16string;
#if ETL_USING_CPP17
using StringView = std::u16string_view;
#endif
using Char = std::u16string::value_type;
using Vector = std::vector<String>;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -38,6 +38,9 @@ SOFTWARE.
#undef STR
#define STR(x) U##x
#undef STR_PTR
#define STR_PTR const char32_t*
namespace
{
//***********************************
@ -56,7 +59,11 @@ namespace
using Char = std::u32string::value_type;
using Vector = std::vector<String>;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -38,6 +38,9 @@ SOFTWARE.
#undef STR
#define STR(x) L##x
#undef STR_PTR
#define STR_PTR const wchar_t*
namespace
{
//***********************************
@ -56,7 +59,11 @@ namespace
using Char = std::wstring::value_type;
using Vector = std::vector<String>;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -36,6 +36,9 @@ SOFTWARE.
#undef STR
#define STR(x) u##x
#undef STR_PTR
#define STR_PTR const char16_t*
namespace
{
//***********************************
@ -56,7 +59,11 @@ namespace
using Char = etl::iu16string::value_type;
using Vector = etl::vector<String, 15>;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -36,6 +36,9 @@ SOFTWARE.
#undef STR
#define STR(x) U##x
#undef STR_PTR
#define STR_PTR const char32_t*
namespace
{
//***********************************
@ -56,7 +59,11 @@ namespace
using Char = etl::iu32string::value_type;
using Vector = etl::vector<String, 15>;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -36,6 +36,9 @@ SOFTWARE.
#undef STR
#define STR(x) L##x
#undef STR_PTR
#define STR_PTR const wchar_t*
namespace
{
//***********************************
@ -56,7 +59,11 @@ namespace
using Char = etl::iwstring::value_type;
using Vector = etl::vector<String, 15>;
#if ETL_USING_CPP17
constexpr auto Whitespace = etl::whitespace_v<String::value_type>;
#else
STR_PTR Whitespace = etl::whitespace<String::value_type>::value();
#endif
//*************************************************************************
TEST(test_trim_whitespace_left_empty)

View File

@ -1041,15 +1041,15 @@ namespace
{
#if ETL_USING_CPP17
CHECK_EQUAL(1, (etl::integral_constant_v<int, 1>));
CHECK((std::is_same<int, etl::integral_constant_v<int, 1>>));
CHECK((std::is_same_v<int, etl::integral_constant<int, 1>::value_type>));
CHECK_EQUAL(false, (etl::bool_constant_v<false>));
CHECK_EQUAL(true, (etl::bool_constant_v<true>));
CHECK((std::is_same<bool, etl::bool_constant<true>::value_type>));
CHECK_EQUAL(false, etl::bool_constant_v<false>);
CHECK_EQUAL(true, etl::bool_constant_v<true>);
CHECK((std::is_same_v<bool, etl::bool_constant<true>::value_type>));
CHECK_EQUAL(true, etl::negation_v<etl::bool_constant<false>>);
CHECK_EQUAL(false, etl::negation_v<etl::bool_constant<true>>);
CHECK((std::is_same<bool, etl::bool_constant<true>::value_type>));
CHECK((std::is_same_v<bool, etl::bool_constant<false>::value_type>));
#else
CHECK_EQUAL(1, (etl::integral_constant<int, 1>::value));
CHECK((std::is_same<int, etl::integral_constant<int, 1>::value_type>::value));