• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_SCOPED_OBSERVATION_TRAITS_INTERNAL_H_
6 #define BASE_SCOPED_OBSERVATION_TRAITS_INTERNAL_H_
7 
8 #include <type_traits>
9 
10 namespace base::internal {
11 
12 struct HasAddAndRemoveObserverMethodsHelper {
13   template <class Source, class Observer>
14   static auto Validate(Source* source, Observer* observer)
15       -> decltype(source->AddObserver(observer),
16                   source->RemoveObserver(observer),
17                   std::true_type());
18 
19   template <class...>
20   static auto Validate(...) -> std::false_type;
21 };
22 
23 template <class Source, class Observer>
24 inline constexpr bool HasAddAndRemoveObserverMethods =
25     decltype(HasAddAndRemoveObserverMethodsHelper::Validate<Source, Observer>(
26         nullptr,
27         nullptr))::value;
28 
29 }  // namespace base::internal
30 
31 #endif  // BASE_SCOPED_OBSERVATION_TRAITS_INTERNAL_H_
32