104
104
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
105
105
#define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
106
106
107
+
#include <any>
107
108
#include <functional>
108
109
#include <memory>
110
+
#include <optional>
109
111
#include <ostream> // NOLINT
110
112
#include <sstream>
111
113
#include <string>
114
+
#include <string_view>
112
115
#include <tuple>
113
116
#include <type_traits>
114
117
#include <typeinfo>
115
118
#include <utility>
119
+
#include <variant>
116
120
#include <vector>
117
121
118
122
#ifdef GTEST_HAS_ABSL
@@ -245,8 +249,8 @@ struct StreamPrinter {
245
249
// ADL (possibly involving implicit conversions).
246
250
// (Use SFINAE via return type, because it seems GCC < 12 doesn't handle name
247
251
// 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)) {
250
254
// Call streaming operator found by ADL, possibly with implicit conversions
251
255
// of the arguments.
252
256
*os << value;
@@ -521,11 +525,15 @@ GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
521
525
522
526
GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os);
523
527
inline 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);
525
531
}
526
532
#ifdef __cpp_lib_char8_t
527
533
inline 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);
529
537
}
530
538
#endif
531
539
@@ -695,44 +703,63 @@ void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
695
703
}
696
704
}
697
705
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);
700
708
inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
701
709
PrintStringTo(s, os);
702
710
}
711
+
inline void PrintTo(::std::string_view s, ::std::ostream* os) {
712
+
PrintStringTo(s, os);
713
+
}
703
714
704
-
// Overloads for ::std::u8string
715
+
// Overloads for ::std::u8string and ::std::u8string_view
705
716
#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);
707
718
inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) {
708
719
PrintU8StringTo(s, os);
709
720
}
721
+
inline void PrintTo(::std::u8string_view s, ::std::ostream* os) {
722
+
PrintU8StringTo(s, os);
723
+
}
710
724
#endif
711
725
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);
714
728
inline void PrintTo(const ::std::u16string& s, ::std::ostream* os) {
715
729
PrintU16StringTo(s, os);
716
730
}
731
+
inline void PrintTo(::std::u16string_view s, ::std::ostream* os) {
732
+
PrintU16StringTo(s, os);
733
+
}
717
734
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);
720
737
inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) {
721
738
PrintU32StringTo(s, os);
722
739
}
740
+
inline void PrintTo(::std::u32string_view s, ::std::ostream* os) {
741
+
PrintU32StringTo(s, os);
742
+
}
723
743
724
-
// Overloads for ::std::wstring.
744
+
// Overloads for ::std::wstring and ::std::wstring_view
725
745
#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);
727
747
inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
728
748
PrintWideStringTo(s, os);
729
749
}
750
+
inline void PrintTo(::std::wstring_view s, ::std::ostream* os) {
751
+
PrintWideStringTo(s, os);
752
+
}
730
753
#endif // GTEST_HAS_STD_WSTRING
731
754
732
755
#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>
734
761
inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
735
-
PrintTo(::std::string(sp), os);
762
+
PrintStringTo(sp, os);
736
763
}
737
764
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
738
765
@@ -890,14 +917,11 @@ class UniversalPrinter {
890
917
template <typename T>
891
918
class UniversalPrinter<const T> : public UniversalPrinter<T> {};
892
919
893
-
#if GTEST_INTERNAL_HAS_ANY
894
-
895
-
// Printer for std::any / absl::any
896
-
920
+
// Printer for std::any
897
921
template <>
898
-
class UniversalPrinter<Any> {
922
+
class UniversalPrinter<std::any> {
899
923
public:
900
-
static void Print(const Any& value, ::std::ostream* os) {
924
+
static void Print(const std::any& value, ::std::ostream* os) {
901
925
if (value.has_value()) {
902
926
*os << "value of type " << GetTypeName(value);
903
927
} else {
@@ -906,7 +930,7 @@ class UniversalPrinter<Any> {
906
930
}
907
931
908
932
private:
909
-
static std::string GetTypeName(const Any& value) {
933
+
static std::string GetTypeName(const std::any& value) {
910
934
#if GTEST_HAS_RTTI
911
935
return internal::GetTypeName(value.type());
912
936
#else
@@ -916,16 +940,11 @@ class UniversalPrinter<Any> {
916
940
}
917
941
};
918
942
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
925
944
template <typename T>
926
-
class UniversalPrinter<Optional<T>> {
945
+
class UniversalPrinter<std::optional<T>> {
927
946
public:
928
-
static void Print(const Optional<T>& value, ::std::ostream* os) {
947
+
static void Print(const std::optional<T>& value, ::std::ostream* os) {
929
948
*os << '(';
930
949
if (!value) {
931
950
*os << "nullopt";
@@ -937,29 +956,18 @@ class UniversalPrinter<Optional<T>> {
937
956
};
938
957
939
958
template <>
940
-
class UniversalPrinter<decltype(Nullopt())> {
959
+
class UniversalPrinter<std::nullopt_t> {
941
960
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)"; }
945
962
};
946
963
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
953
965
template <typename... T>
954
-
class UniversalPrinter<Variant<T...>> {
966
+
class UniversalPrinter<std::variant<T...>> {
955
967
public:
956
-
static void Print(const Variant<T...>& value, ::std::ostream* os) {
968
+
static void Print(const std::variant<T...>& value, ::std::ostream* os) {
957
969
*os << '(';
958
-
#ifdef GTEST_HAS_ABSL
959
-
absl::visit(Visitor{os, value.index()}, value);
960
-
#else
961
970
std::visit(Visitor{os, value.index()}, value);
962
-
#endif // GTEST_HAS_ABSL
963
971
*os << ')';
964
972
}
965
973
@@ -976,8 +984,6 @@ class UniversalPrinter<Variant<T...>> {
976
984
};
977
985
};
978
986
979
-
#endif // GTEST_INTERNAL_HAS_VARIANT
980
-
981
987
// UniversalPrintArray(begin, len, os) prints an array of 'len'
982
988
// elements, starting at address 'begin'.
983
989
template <typename T>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4