writting <> with every string_view type is non productive and also differs from what C++ Core Guidelines proposes

This commit is contained in:
Kosov Eugene 2015-09-29 11:50:14 +03:00
parent d023ad51a7
commit 5629a654e6
2 changed files with 17 additions and 24 deletions

View File

@ -57,17 +57,10 @@ using wzstring = wchar_t*;
template <class CharT, size_t Extent = dynamic_range>
using basic_string_view = array_view<CharT, Extent>;
template<size_t Extent = dynamic_range>
using string_view = basic_string_view<char, Extent>;
template<size_t Extent = dynamic_range>
using cstring_view = basic_string_view<const char, Extent>;
template<size_t Extent = dynamic_range>
using wstring_view = basic_string_view<wchar_t, Extent>;
template<size_t Extent = dynamic_range>
using cwstring_view = basic_string_view<const wchar_t, Extent>;
using string_view = basic_string_view<char>;
using cstring_view = basic_string_view<const char>;
using wstring_view = basic_string_view<wchar_t>;
using cwstring_view = basic_string_view<const wchar_t>;
//

View File

@ -27,26 +27,26 @@ SUITE(string_view_tests)
TEST(TestLiteralConstruction)
{
cwstring_view<> v = ensure_z(L"Hello");
cwstring_view v = ensure_z(L"Hello");
CHECK(5 == v.length());
#ifdef CONFIRM_COMPILATION_ERRORS
wstring_view<> v2 = ensure0(L"Hello");
wstring_view v2 = ensure0(L"Hello");
#endif
}
TEST(TestConstructFromStdString)
{
std::string s = "Hello there world";
cstring_view<> v = s;
cstring_view v = s;
CHECK(v.length() == s.length());
}
TEST(TestConstructFromStdVector)
{
std::vector<char> vec('h', 5);
string_view<> v = vec;
string_view v = vec;
CHECK(v.length() == vec.size());
}
@ -55,25 +55,25 @@ SUITE(string_view_tests)
wchar_t stack_string[] = L"Hello";
{
cwstring_view<> v = ensure_z(stack_string);
cwstring_view v = ensure_z(stack_string);
CHECK(v.length() == 5);
CHECK(v.used_length() == v.length());
}
{
cwstring_view<> v = stack_string;
cwstring_view v = stack_string;
CHECK(v.length() == 6);
CHECK(v.used_length() == v.length());
}
{
wstring_view<> v = ensure_z(stack_string);
wstring_view v = ensure_z(stack_string);
CHECK(v.length() == 5);
CHECK(v.used_length() == v.length());
}
{
wstring_view<> v = stack_string;
wstring_view v = stack_string;
CHECK(v.length() == 6);
CHECK(v.used_length() == v.length());
}
@ -82,18 +82,18 @@ SUITE(string_view_tests)
TEST(TestConversionToConst)
{
char stack_string[] = "Hello";
string_view<> v = ensure_z(stack_string);
cstring_view<> v2 = v;
string_view v = ensure_z(stack_string);
cstring_view v2 = v;
CHECK(v.length() == v2.length());
}
TEST(TestConversionFromConst)
{
char stack_string[] = "Hello";
cstring_view<> v = ensure_z(stack_string);
cstring_view v = ensure_z(stack_string);
#ifdef CONFIRM_COMPILATION_ERRORS
string_view<> v2 = v;
string_view<> v3 = "Hello";
string_view v2 = v;
string_view v3 = "Hello";
#endif
}
}