104104#ifndef  GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
105105#define  GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ 
106106
107+ #include  < any> 
107108#include  < functional> 
108109#include  < memory> 
110+ #include  < optional> 
109111#include  < ostream>    //  NOLINT
110112#include  < sstream> 
111113#include  < string> 
114+ #include  < string_view> 
112115#include  < tuple> 
113116#include  < type_traits> 
114117#include  < typeinfo> 
115118#include  < utility> 
119+ #include  < variant> 
116120#include  < vector> 
117121
118122#ifdef  GTEST_HAS_ABSL
@@ -245,8 +249,8 @@ struct StreamPrinter {
245249  //  ADL (possibly involving implicit conversions).
246250  //  (Use SFINAE via return type, because it seems GCC < 12 doesn't handle name
247251  //  lookup properly when we do it in the template parameter list.)
248-   static  auto  PrintValue (const  T& value,
249-                          ::std::ostream* os)  -> decltype((void )(*os << value)) {
252+   static  auto  PrintValue (const  T& value, ::std::ostream* os) 
253+       -> decltype((void )(*os << value)) {
250254    //  Call streaming operator found by ADL, possibly with implicit conversions
251255    //  of the arguments.
252256    *os << value;
@@ -521,11 +525,15 @@ GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
521525
522526GTEST_API_ void  PrintTo (char32_t  c, ::std::ostream* os);
523527inline  void  PrintTo (char16_t  c, ::std::ostream* os) {
524-   PrintTo (ImplicitCast_<char32_t >(c), os);
528+   //  TODO(b/418738869): Incorrect for values not representing valid codepoints.
529+   //  Also see https://github.com/google/googletest/issues/4762.
530+   PrintTo (static_cast <char32_t >(c), os);
525531}
526532#ifdef  __cpp_lib_char8_t
527533inline  void  PrintTo (char8_t  c, ::std::ostream* os) {
528-   PrintTo (ImplicitCast_<char32_t >(c), os);
534+   //  TODO(b/418738869): Incorrect for values not representing valid codepoints.
535+   //  Also see https://github.com/google/googletest/issues/4762.
536+   PrintTo (static_cast <char32_t >(c), os);
529537}
530538#endif 
531539
@@ -695,44 +703,63 @@ void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
695703  }
696704}
697705
698- //  Overloads for ::std::string. 
699- GTEST_API_ void  PrintStringTo (const   ::std::string&  s, ::std::ostream* os);
706+ //  Overloads for ::std::string and ::std::string_view 
707+ GTEST_API_ void  PrintStringTo (::std::string_view  s, ::std::ostream* os);
700708inline  void  PrintTo (const  ::std::string& s, ::std::ostream* os) {
701709  PrintStringTo (s, os);
702710}
711+ inline  void  PrintTo (::std::string_view s, ::std::ostream* os) {
712+   PrintStringTo (s, os);
713+ }
703714
704- //  Overloads for ::std::u8string
715+ //  Overloads for ::std::u8string and ::std::u8string_view 
705716#ifdef  __cpp_lib_char8_t
706- GTEST_API_ void  PrintU8StringTo (const   ::std::u8string&  s, ::std::ostream* os);
717+ GTEST_API_ void  PrintU8StringTo (::std::u8string_view  s, ::std::ostream* os);
707718inline  void  PrintTo (const  ::std::u8string& s, ::std::ostream* os) {
708719  PrintU8StringTo (s, os);
709720}
721+ inline  void  PrintTo (::std::u8string_view s, ::std::ostream* os) {
722+   PrintU8StringTo (s, os);
723+ }
710724#endif 
711725
712- //  Overloads for ::std::u16string
713- GTEST_API_ void  PrintU16StringTo (const   ::std::u16string&  s, ::std::ostream* os);
726+ //  Overloads for ::std::u16string and ::std::u16string_view 
727+ GTEST_API_ void  PrintU16StringTo (::std::u16string_view  s, ::std::ostream* os);
714728inline  void  PrintTo (const  ::std::u16string& s, ::std::ostream* os) {
715729  PrintU16StringTo (s, os);
716730}
731+ inline  void  PrintTo (::std::u16string_view s, ::std::ostream* os) {
732+   PrintU16StringTo (s, os);
733+ }
717734
718- //  Overloads for ::std::u32string
719- GTEST_API_ void  PrintU32StringTo (const   ::std::u32string&  s, ::std::ostream* os);
735+ //  Overloads for ::std::u32string and ::std::u32string_view 
736+ GTEST_API_ void  PrintU32StringTo (::std::u32string_view  s, ::std::ostream* os);
720737inline  void  PrintTo (const  ::std::u32string& s, ::std::ostream* os) {
721738  PrintU32StringTo (s, os);
722739}
740+ inline  void  PrintTo (::std::u32string_view s, ::std::ostream* os) {
741+   PrintU32StringTo (s, os);
742+ }
723743
724- //  Overloads for ::std::wstring. 
744+ //  Overloads for ::std::wstring and ::std::wstring_view 
725745#if  GTEST_HAS_STD_WSTRING
726- GTEST_API_ void  PrintWideStringTo (const   ::std::wstring&  s, ::std::ostream* os);
746+ GTEST_API_ void  PrintWideStringTo (::std::wstring_view  s, ::std::ostream* os);
727747inline  void  PrintTo (const  ::std::wstring& s, ::std::ostream* os) {
728748  PrintWideStringTo (s, os);
729749}
750+ inline  void  PrintTo (::std::wstring_view s, ::std::ostream* os) {
751+   PrintWideStringTo (s, os);
752+ }
730753#endif   //  GTEST_HAS_STD_WSTRING
731754
732755#if  GTEST_INTERNAL_HAS_STRING_VIEW
733- //  Overload for internal::StringView.
756+ //  Overload for internal::StringView. Needed for build configurations where
757+ //  internal::StringView is an alias for absl::string_view, but absl::string_view
758+ //  is a distinct type from std::string_view.
759+ template  <int &... ExplicitArgumentBarrier, typename  T = internal::StringView,
760+           std::enable_if_t <!std::is_same_v<T, ::std::string_view>, int > = 0 >
734761inline  void  PrintTo (internal::StringView sp, ::std::ostream* os) {
735-   PrintTo (:: std::string (sp) , os);
762+   PrintStringTo (sp , os);
736763}
737764#endif   //  GTEST_INTERNAL_HAS_STRING_VIEW
738765
@@ -890,14 +917,11 @@ class UniversalPrinter {
890917template  <typename  T>
891918class  UniversalPrinter <const  T> : public UniversalPrinter<T> {};
892919
893- #if  GTEST_INTERNAL_HAS_ANY
894- 
895- //  Printer for std::any / absl::any
896- 
920+ //  Printer for std::any
897921template  <>
898- class  UniversalPrinter <Any > {
922+ class  UniversalPrinter <std::any > {
899923 public: 
900-   static  void  Print (const  Any & value, ::std::ostream* os) {
924+   static  void  Print (const  std::any & value, ::std::ostream* os) {
901925    if  (value.has_value ()) {
902926      *os << " value of type "   << GetTypeName (value);
903927    } else  {
@@ -906,7 +930,7 @@ class UniversalPrinter<Any> {
906930  }
907931
908932 private: 
909-   static  std::string GetTypeName (const  Any & value) {
933+   static  std::string GetTypeName (const  std::any & value) {
910934#if  GTEST_HAS_RTTI
911935    return  internal::GetTypeName (value.type ());
912936#else 
@@ -916,16 +940,11 @@ class UniversalPrinter<Any> {
916940  }
917941};
918942
919- #endif   //  GTEST_INTERNAL_HAS_ANY
920- 
921- #if  GTEST_INTERNAL_HAS_OPTIONAL
922- 
923- //  Printer for std::optional / absl::optional
924- 
943+ //  Printer for std::optional
925944template  <typename  T>
926- class  UniversalPrinter <Optional <T>> {
945+ class  UniversalPrinter <std::optional <T>> {
927946 public: 
928-   static  void  Print (const  Optional <T>& value, ::std::ostream* os) {
947+   static  void  Print (const  std::optional <T>& value, ::std::ostream* os) {
929948    *os << ' ('  ;
930949    if  (!value) {
931950      *os << " nullopt"  ;
@@ -937,29 +956,18 @@ class UniversalPrinter<Optional<T>> {
937956};
938957
939958template  <>
940- class  UniversalPrinter <decltype (Nullopt()) > {
959+ class  UniversalPrinter <std:: nullopt_t > {
941960 public: 
942-   static  void  Print (decltype (Nullopt()), ::std::ostream* os) {
943-     *os << " (nullopt)"  ;
944-   }
961+   static  void  Print (std::nullopt_t , ::std::ostream* os) { *os << " (nullopt)"  ; }
945962};
946963
947- #endif   //  GTEST_INTERNAL_HAS_OPTIONAL
948- 
949- #if  GTEST_INTERNAL_HAS_VARIANT
950- 
951- //  Printer for std::variant / absl::variant
952- 
964+ //  Printer for std::variant
953965template  <typename ... T>
954- class  UniversalPrinter <Variant <T...>> {
966+ class  UniversalPrinter <std::variant <T...>> {
955967 public: 
956-   static  void  Print (const  Variant <T...>& value, ::std::ostream* os) {
968+   static  void  Print (const  std::variant <T...>& value, ::std::ostream* os) {
957969    *os << ' ('  ;
958- #ifdef  GTEST_HAS_ABSL
959-     absl::visit (Visitor{os, value.index ()}, value);
960- #else 
961970    std::visit (Visitor{os, value.index ()}, value);
962- #endif   //  GTEST_HAS_ABSL
963971    *os << ' )'  ;
964972  }
965973
@@ -976,8 +984,6 @@ class UniversalPrinter<Variant<T...>> {
976984  };
977985};
978986
979- #endif   //  GTEST_INTERNAL_HAS_VARIANT
980- 
981987//  UniversalPrintArray(begin, len, os) prints an array of 'len'
982988//  elements, starting at address 'begin'.
983989template  <typename  T>
0 commit comments