diff --git a/gsl/gsl_byte b/gsl/gsl_byte index f502ab0..09592eb 100644 --- a/gsl/gsl_byte +++ b/gsl/gsl_byte @@ -75,7 +75,7 @@ constexpr byte& operator|=(byte& l, byte r) noexcept constexpr byte operator|(byte l, byte r) noexcept { - return byte(static_cast(l) + static_cast(r)); + return byte(static_cast(l) | static_cast(r)); } constexpr byte& operator&=(byte& l, byte r) noexcept diff --git a/gsl/string_span b/gsl/string_span index 8e60183..cd49998 100644 --- a/gsl/string_span +++ b/gsl/string_span @@ -486,6 +486,16 @@ inline std::wstring to_string(wstring_span<> view) #endif +template , + typename Allocator = std::allocator, + typename gCharT, + std::ptrdiff_t Extent> +std::basic_string to_basic_string(basic_string_span view) +{ + return {view.data(), static_cast(view.length())}; +} + // zero-terminated string span, used to convert // zero-terminated spans to legacy strings template diff --git a/tests/string_span_tests.cpp b/tests/string_span_tests.cpp index 7e623f3..a1cfe79 100644 --- a/tests/string_span_tests.cpp +++ b/tests/string_span_tests.cpp @@ -114,6 +114,18 @@ SUITE(string_span_tests) CHECK(s2.length() == 5); } + TEST(TestToBasicString) + { + auto s = gsl::to_basic_string,::std::allocator>(cstring_span<>{}); + CHECK(s.length() == 0); + + char stack_string[] = "Hello"; + cstring_span<> v = ensure_z(stack_string); + auto s2 = gsl::to_basic_string,::std::allocator>(v); + CHECK(static_cast::index_type>(s2.length()) == v.length()); + CHECK(s2.length() == 5); + } + TEST(EqualityAndImplicitConstructors) { {