| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- //
- // gtest_variant_printers.h
- // variant
- //
- // Created by Sam Jaffe on 8/14/20.
- // Copyright © 2020 Sam Jaffe. All rights reserved.
- //
- #pragma once
- template <typename K, typename V>
- std::ostream & operator<<(std::ostream & os, std::map<K, V> const & value) {
- os << "{";
- if (value.size()) {
- auto it = value.cbegin();
- os << " " << it->first << ":" << it->second;
- for (++it; it != value.cend(); ++it) {
- os << ", " << it->first << ":" << it->second;
- }
- }
- return os << " }";
- }
- template <std::size_t I, typename ...Ts>
- void PrintTo(variant<Ts...> const & value, std::ostream * os) {
- if (value.index() == I) {
- (*os) << value.template get<I>();
- }
- }
- template <typename ...Ts, std::size_t ...Is>
- void PrintTo(variant<Ts...> const & value, std::ostream * os,
- std::index_sequence<Is...>) {
- [[maybe_unused]] auto l = { (PrintTo<Is>(value, os), 0)... };
- }
- template <typename ...Ts>
- void PrintTo(variant<Ts...> const & value, std::ostream * os) {
- if (value.valid()) {
- PrintTo(value, os, std::make_index_sequence<sizeof...(Ts)>());
- } else {
- (*os) << "<invalid>";
- }
- }
|