mirror of
https://github.com/boostorg/core.git
synced 2025-07-29 12:27:42 +02:00
Add support for string_view
This commit is contained in:
@ -21,6 +21,9 @@
|
||||
#include <utility>
|
||||
#include <cstdio>
|
||||
#include <cstddef>
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
# include <string_view>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -447,6 +450,12 @@ inline std::string type_name( tn_identity<std::nullptr_t> )
|
||||
|
||||
// strings
|
||||
|
||||
template<template<class Ch, class Tr, class A> class L, class Ch> std::string type_name( tn_identity< L<Ch, std::char_traits<Ch>, std::allocator<Ch> > > )
|
||||
{
|
||||
std::string tn = sequence_template_name< L<Ch, std::char_traits<Ch>, std::allocator<Ch> > >();
|
||||
return tn + '<' + type_name( tn_identity<Ch>() ) + '>';
|
||||
}
|
||||
|
||||
inline std::string type_name( tn_identity<std::string> )
|
||||
{
|
||||
return "std::string";
|
||||
@ -484,6 +493,55 @@ inline std::string type_name( tn_identity<std::basic_string<char8_t>> )
|
||||
|
||||
#endif
|
||||
|
||||
// string views (et al)
|
||||
|
||||
template<template<class Ch, class Tr> class L, class Ch> std::string type_name( tn_identity< L<Ch, std::char_traits<Ch> > > )
|
||||
{
|
||||
std::string tn = sequence_template_name< L<Ch, std::char_traits<Ch> > >();
|
||||
return tn + '<' + type_name( tn_identity<Ch>() ) + '>';
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
|
||||
inline std::string type_name( tn_identity<std::string_view> )
|
||||
{
|
||||
return "std::string_view";
|
||||
}
|
||||
|
||||
inline std::string type_name( tn_identity<std::wstring_view> )
|
||||
{
|
||||
return "std::wstring_view";
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T)
|
||||
|
||||
inline std::string type_name( tn_identity<std::u16string_view> )
|
||||
{
|
||||
return "std::u16string_view";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T)
|
||||
|
||||
inline std::string type_name( tn_identity<std::u32string_view> )
|
||||
{
|
||||
return "std::u32string_view";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
|
||||
|
||||
inline std::string type_name( tn_identity<std::basic_string_view<char8_t>> )
|
||||
{
|
||||
return "std::u8string_view";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// class templates
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <cstddef>
|
||||
#include <iosfwd>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
|
||||
# include <unordered_set>
|
||||
@ -26,6 +27,10 @@
|
||||
# include <array>
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
# include <string_view>
|
||||
#endif
|
||||
|
||||
//
|
||||
|
||||
#define TEST(...) BOOST_TEST_EQ((boost::core::type_name<__VA_ARGS__>()), std::string(#__VA_ARGS__))
|
||||
@ -56,6 +61,10 @@ enum class E2
|
||||
|
||||
#endif
|
||||
|
||||
struct Ch
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
TEST(int);
|
||||
@ -121,6 +130,8 @@ int main()
|
||||
TEST(std::pair<A, B>);
|
||||
TEST(std::pair<A const*, B*> volatile&);
|
||||
|
||||
TEST(std::basic_string<Ch>);
|
||||
|
||||
TEST(std::string);
|
||||
TEST(std::wstring);
|
||||
|
||||
@ -181,5 +192,31 @@ int main()
|
||||
TEST(std::array<std::wstring const*, 0> const&);
|
||||
|
||||
#endif
|
||||
|
||||
TEST(std::basic_ostream<char>);
|
||||
TEST(std::basic_ostream<wchar_t>);
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
|
||||
TEST(std::basic_string_view<Ch>);
|
||||
|
||||
TEST(std::string_view);
|
||||
TEST(std::wstring_view);
|
||||
|
||||
#if BOOST_CXX_VERSION >= 201100L
|
||||
|
||||
TEST(std::u16string_view);
|
||||
TEST(std::u32string_view);
|
||||
|
||||
#endif
|
||||
|
||||
#if BOOST_CXX_VERSION >= 202000L
|
||||
|
||||
TEST(std::u8string_view);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user