Merge remote-tracking branch 'Microsoft/master'

This commit is contained in:
Kris 2016-09-07 22:16:19 +01:00
commit d5847ceef0
3 changed files with 23 additions and 1 deletions

View File

@ -75,7 +75,7 @@ constexpr byte& operator|=(byte& l, byte r) noexcept
constexpr byte operator|(byte l, byte r) noexcept constexpr byte operator|(byte l, byte r) noexcept
{ {
return byte(static_cast<unsigned char>(l) + static_cast<unsigned char>(r)); return byte(static_cast<unsigned char>(l) | static_cast<unsigned char>(r));
} }
constexpr byte& operator&=(byte& l, byte r) noexcept constexpr byte& operator&=(byte& l, byte r) noexcept

View File

@ -486,6 +486,16 @@ inline std::wstring to_string(wstring_span<> view)
#endif #endif
template <typename CharT,
typename Traits = typename std::char_traits<CharT>,
typename Allocator = std::allocator<CharT>,
typename gCharT,
std::ptrdiff_t Extent>
std::basic_string<CharT, Traits, Allocator> to_basic_string(basic_string_span<gCharT, Extent> view)
{
return {view.data(), static_cast<size_t>(view.length())};
}
// zero-terminated string span, used to convert // zero-terminated string span, used to convert
// zero-terminated spans to legacy strings // zero-terminated spans to legacy strings
template <typename CharT, std::ptrdiff_t Extent = dynamic_extent> template <typename CharT, std::ptrdiff_t Extent = dynamic_extent>

View File

@ -114,6 +114,18 @@ SUITE(string_span_tests)
CHECK(s2.length() == 5); CHECK(s2.length() == 5);
} }
TEST(TestToBasicString)
{
auto s = gsl::to_basic_string<char,std::char_traits<char>,::std::allocator<char>>(cstring_span<>{});
CHECK(s.length() == 0);
char stack_string[] = "Hello";
cstring_span<> v = ensure_z(stack_string);
auto s2 = gsl::to_basic_string<char,std::char_traits<char>,::std::allocator<char>>(v);
CHECK(static_cast<cstring_span<>::index_type>(s2.length()) == v.length());
CHECK(s2.length() == 5);
}
TEST(EqualityAndImplicitConstructors) TEST(EqualityAndImplicitConstructors)
{ {
{ {