Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/core/detail/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ template<class Ch> class basic_string_view

template<class A> operator std::basic_string<Ch, std::char_traits<Ch>, A>() const
{
return std::basic_string<Ch, std::char_traits<Ch>, A>( data(), size() );
return std::basic_string<Ch, std::char_traits<Ch>, A>( begin(), end() );
}

#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
Expand Down
33 changes: 33 additions & 0 deletions test/sv_conversion_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ boost::core::string_view f( boost::core::string_view const& str )
return str;
}

template<typename Char>
boost::core::basic_string_view<Char> f( boost::core::basic_string_view<Char> const& str )
{
return str;
}

template<typename Char>
void subtest()
{
std::basic_string<Char> s1( 3, Char('1') );
s1[1] = Char('2');
s1[2] = Char('3');

std::basic_string<Char> s2 = f<Char>( s1 );
BOOST_TEST( s1 == s2 );

#if ! (defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 150000)
// leads to undefined symbols in Clang < 15: https://github.com/llvm/llvm-project/issues/55560
std::basic_string<Char> s3( (f<Char>( s1 )) );
BOOST_TEST( s1 == s3 );
#endif
}

int main()
{
{
Expand Down Expand Up @@ -62,5 +85,15 @@ int main()

#endif

#if !defined(BOOST_NO_CXX11_CHAR16_T)
subtest<char16_t>();
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T)
subtest<char32_t>();
#endif
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
subtest<char8_t>();
#endif

return boost::report_errors();
}
Loading