// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_STRINGS_TO_STRING_H_ #define BASE_STRINGS_TO_STRING_H_ #include <concepts> #include <ios> #include <memory> #include <sstream> #include <string> #include <tuple> #include <type_traits> #include <utility> #include "base/types/supports_ostream_operator.h" namespace base { template <typename... Ts> std::string ToString(const Ts&... values); namespace internal { SupportsToString; // I/O manipulators are function pointers, but should be sent directly to the // `ostream` instead of being cast to `const void*` like other function // pointers. IsIomanip; IsIomanip; // Function pointers implicitly convert to `bool`, so use this to avoid printing // function pointers as 1 or 0. WillBeIncorrectlyStreamedAsBool; // Fallback case when there is no better representation. template <typename T> struct ToStringHelper { … }; // Most streamables. ToStringHelper<T>; // Functions and function pointers. ToStringHelper<T>; // Non-streamables that have a `ToString` member. ToStringHelper<T>; // Non-streamable enums (i.e. scoped enums where no `operator<<` overload was // declared). ToStringHelper<T>; // Tuples. Will recursively apply `ToString()` to each value in the tuple. ToStringHelper<std::tuple<T...>>; } // namespace internal // Converts any type to a string, preferring defined operator<<() or ToString() // methods if they exist. If multiple `values` are given, returns the // concatenation of the result of applying `ToString` to each value. template <typename... Ts> std::string ToString(const Ts&... values) { … } } // namespace base #endif // BASE_STRINGS_TO_STRING_H_