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