1*9356374aSAndroid Build Coastguard Worker // Copyright 2022 The Abseil Authors 2*9356374aSAndroid Build Coastguard Worker // 3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*9356374aSAndroid Build Coastguard Worker // 7*9356374aSAndroid Build Coastguard Worker // https://www.apache.org/licenses/LICENSE-2.0 8*9356374aSAndroid Build Coastguard Worker // 9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*9356374aSAndroid Build Coastguard Worker // limitations under the License. 14*9356374aSAndroid Build Coastguard Worker 15*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_STRINGS_HAS_ABSL_STRINGIFY_H_ 16*9356374aSAndroid Build Coastguard Worker #define ABSL_STRINGS_HAS_ABSL_STRINGIFY_H_ 17*9356374aSAndroid Build Coastguard Worker 18*9356374aSAndroid Build Coastguard Worker #include <type_traits> 19*9356374aSAndroid Build Coastguard Worker #include <utility> 20*9356374aSAndroid Build Coastguard Worker 21*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h" 22*9356374aSAndroid Build Coastguard Worker #include "absl/strings/string_view.h" 23*9356374aSAndroid Build Coastguard Worker 24*9356374aSAndroid Build Coastguard Worker namespace absl { 25*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN 26*9356374aSAndroid Build Coastguard Worker 27*9356374aSAndroid Build Coastguard Worker namespace strings_internal { 28*9356374aSAndroid Build Coastguard Worker 29*9356374aSAndroid Build Coastguard Worker // This is an empty class not intended to be used. It exists so that 30*9356374aSAndroid Build Coastguard Worker // `HasAbslStringify` can reference a universal class rather than needing to be 31*9356374aSAndroid Build Coastguard Worker // copied for each new sink. 32*9356374aSAndroid Build Coastguard Worker class UnimplementedSink { 33*9356374aSAndroid Build Coastguard Worker public: 34*9356374aSAndroid Build Coastguard Worker void Append(size_t count, char ch); 35*9356374aSAndroid Build Coastguard Worker 36*9356374aSAndroid Build Coastguard Worker void Append(string_view v); 37*9356374aSAndroid Build Coastguard Worker 38*9356374aSAndroid Build Coastguard Worker // Support `absl::Format(&sink, format, args...)`. 39*9356374aSAndroid Build Coastguard Worker friend void AbslFormatFlush(UnimplementedSink* sink, absl::string_view v); 40*9356374aSAndroid Build Coastguard Worker }; 41*9356374aSAndroid Build Coastguard Worker 42*9356374aSAndroid Build Coastguard Worker } // namespace strings_internal 43*9356374aSAndroid Build Coastguard Worker 44*9356374aSAndroid Build Coastguard Worker // `HasAbslStringify<T>` detects if type `T` supports the `AbslStringify()` 45*9356374aSAndroid Build Coastguard Worker // customization point (see 46*9356374aSAndroid Build Coastguard Worker // https://abseil.io/docs/cpp/guides/format#abslstringify for the 47*9356374aSAndroid Build Coastguard Worker // documentation). 48*9356374aSAndroid Build Coastguard Worker // 49*9356374aSAndroid Build Coastguard Worker // Note that there are types that can be `StrCat`-ed that do not use the 50*9356374aSAndroid Build Coastguard Worker // `AbslStringify` customization point (for example, `int`). 51*9356374aSAndroid Build Coastguard Worker 52*9356374aSAndroid Build Coastguard Worker template <typename T, typename = void> 53*9356374aSAndroid Build Coastguard Worker struct HasAbslStringify : std::false_type {}; 54*9356374aSAndroid Build Coastguard Worker 55*9356374aSAndroid Build Coastguard Worker template <typename T> 56*9356374aSAndroid Build Coastguard Worker struct HasAbslStringify< 57*9356374aSAndroid Build Coastguard Worker T, std::enable_if_t<std::is_void<decltype(AbslStringify( 58*9356374aSAndroid Build Coastguard Worker std::declval<strings_internal::UnimplementedSink&>(), 59*9356374aSAndroid Build Coastguard Worker std::declval<const T&>()))>::value>> : std::true_type {}; 60*9356374aSAndroid Build Coastguard Worker 61*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END 62*9356374aSAndroid Build Coastguard Worker } // namespace absl 63*9356374aSAndroid Build Coastguard Worker 64*9356374aSAndroid Build Coastguard Worker #endif // ABSL_STRINGS_HAS_ABSL_STRINGIFY_H_ 65