diff options
author | Gennadiy Civil <gennadiycivil@users.noreply.github.com> | 2018-08-15 15:37:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-15 15:37:15 (GMT) |
commit | 7e7e3a6f45db62d470c9d15b062582e9e95d3bcd (patch) | |
tree | 29039379de3d6fb3ef4c049d9b69faba9b4e5ccf /googletest/include/gtest/gtest-printers.h | |
parent | b50b2f775ed0268af9c83a96b285e296778d0743 (diff) | |
parent | 997d343dd680e541ef96ce71ee54a91daf2577a0 (diff) | |
download | googletest-7e7e3a6f45db62d470c9d15b062582e9e95d3bcd.zip googletest-7e7e3a6f45db62d470c9d15b062582e9e95d3bcd.tar.gz googletest-7e7e3a6f45db62d470c9d15b062582e9e95d3bcd.tar.bz2 |
Merge branch 'master' into patch-1
Diffstat (limited to 'googletest/include/gtest/gtest-printers.h')
-rw-r--r-- | googletest/include/gtest/gtest-printers.h | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index fa465c3..491bcc9 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Test - The Google C++ Testing and Mocking Framework // @@ -96,6 +95,8 @@ // being defined as many user-defined container types don't have // value_type. +// GOOGLETEST_CM0001 DO NOT DELETE + #ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ #define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ @@ -114,6 +115,7 @@ #if GTEST_HAS_ABSL #include "absl/strings/string_view.h" #include "absl/types/optional.h" +#include "absl/types/variant.h" #endif // GTEST_HAS_ABSL namespace testing { @@ -787,6 +789,28 @@ class UniversalPrinter<::absl::optional<T>> { } }; +// Printer for absl::variant + +template <typename... T> +class UniversalPrinter<::absl::variant<T...>> { + public: + static void Print(const ::absl::variant<T...>& value, ::std::ostream* os) { + *os << '('; + absl::visit(Visitor{os}, value); + *os << ')'; + } + + private: + struct Visitor { + template <typename U> + void operator()(const U& u) const { + *os << "'" << GetTypeName<U>() << "' with value "; + UniversalPrint(u, os); + } + ::std::ostream* os; + }; +}; + #endif // GTEST_HAS_ABSL // UniversalPrintArray(begin, len, os) prints an array of 'len' @@ -802,7 +826,7 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { // If the array has more than kThreshold elements, we'll have to // omit some details by printing only the first and the last // kChunkSize elements. - // TODO(wan@google.com): let the user control the threshold using a flag. + // FIXME: let the user control the threshold using a flag. if (len <= kThreshold) { PrintRawArrayTo(begin, len, os); } else { |