Added non-const string pointer overload

This commit is contained in:
John Wellbelove 2021-11-06 16:45:06 +00:00
parent b5e5c5ecca
commit 1b7a59be92
7 changed files with 93 additions and 18 deletions

View File

@ -561,14 +561,14 @@ namespace etl
-> array<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
#endif
#if ETL_CPP11_SUPPORTED
template <typename... T>
constexpr auto make_array(T&&... t)
-> etl::array<std::common_type_t<T...>, sizeof...(T)>
{
return { { etl::forward<T>(t)... } };
}
#endif
//#if ETL_CPP11_SUPPORTED
// template <typename... T>
// constexpr auto make_array(T&&... t)
// -> etl::array<std::common_type_t<T...>, sizeof...(T)>
// {
// return { { etl::forward<T>(t)... } };
// }
//#endif
//*************************************************************************
/// Overloaded swap for etl::array<T, SIZE>

View File

@ -46,6 +46,7 @@ namespace etl
typedef TFormat format_spec_type;
typedef TIString istring_type;
typedef typename TIString::value_type value_type;
typedef typename TIString::pointer pointer;
typedef typename TIString::const_pointer const_pointer;
//*************************************************************************
@ -218,7 +219,17 @@ namespace etl
}
//*********************************
/// From a const pointer to a string
/// From a character pointer to a string
//*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, pointer p)
{
TStringView view(p);
ss << view;
return ss;
}
//*********************************
/// From a const character pointer to a string
//*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, const_pointer p)
{

View File

@ -646,12 +646,12 @@ namespace
}
//*************************************************************************
TEST(test_make_array)
{
auto data = etl::make_array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
//TEST(test_make_array)
//{
// auto data = etl::make_array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
CHECK_EQUAL(5, data[5]);
}
// CHECK_EQUAL(5, data[5]);
//}
};
}

View File

@ -80,7 +80,7 @@ namespace
SUITE(test_string_stream)
{
//*************************************************************************
TEST(test_default_format)
TEST(test_default_format_from_const_char)
{
String str;
@ -95,6 +95,22 @@ namespace
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_default_format_from_char)
{
String str;
Stream ss(str);
int value = 123;
String hello(STR("Hello"));
ss << hello << const_cast<char*>(STR(" World ")) << value;
String result = ss.str();
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_custom_format)
{

View File

@ -80,7 +80,7 @@ namespace
SUITE(test_string_stream)
{
//*************************************************************************
TEST(test_default_format)
TEST(test_default_format_from_const_char)
{
String str;
@ -95,6 +95,22 @@ namespace
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_default_format_from_char)
{
String str;
Stream ss(str);
int value = 123;
String hello(STR("Hello"));
ss << hello << const_cast<char16_t*>(STR(" World ")) << value;
String result = ss.str();
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_custom_format)
{

View File

@ -80,7 +80,7 @@ namespace
SUITE(test_string_stream)
{
//*************************************************************************
TEST(test_default_format)
TEST(test_default_format_from_const_char)
{
String str;
@ -95,6 +95,22 @@ namespace
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_default_format_from_char)
{
String str;
Stream ss(str);
int value = 123;
String hello(STR("Hello"));
ss << hello << const_cast<char32_t*>(STR(" World ")) << value;
String result = ss.str();
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_custom_format)
{

View File

@ -81,7 +81,7 @@ namespace
SUITE(test_string_stream)
{
//*************************************************************************
TEST(test_default_format)
TEST(test_default_format_from_const_char)
{
String str;
@ -96,6 +96,22 @@ namespace
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_default_format_from_char)
{
String str;
Stream ss(str);
int value = 123;
String hello(STR("Hello"));
ss << hello << const_cast<wchar_t*>(STR(" World ")) << value;
String result = ss.str();
CHECK_EQUAL(String(STR("Hello World 123")), result);
}
//*************************************************************************
TEST(test_custom_format)
{