sequence_bound_internal.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_THREADING_SEQUENCE_BOUND_INTERNAL_H_
  5. #define BASE_THREADING_SEQUENCE_BOUND_INTERNAL_H_
  6. #include <tuple>
  7. #include "base/compiler_specific.h"
  8. namespace base {
  9. namespace internal {
  10. // Helpers to simplify sharing templates between non-const and const methods.
  11. // Normally, matching against a method pointer type requires defining both a
  12. // `R (T::*)(Args...)` and a `R (T::*)(Args...) const` overload of the template
  13. // function. Rather than doing that, these helpers allow extraction of `R` and
  14. // `Args...` from a method pointer type deduced as `MethodPointerType`.
  15. template <typename MethodPtrType>
  16. struct MethodTraits;
  17. template <typename R, typename T, typename... Args>
  18. struct MethodTraits<R (T::*)(Args...)> {
  19. using ReturnType = R;
  20. using ArgsTuple = std::tuple<Args...>;
  21. };
  22. template <typename R, typename T, typename... Args>
  23. struct MethodTraits<R (T::*)(Args...) const> {
  24. using ReturnType = R;
  25. using ArgsTuple = std::tuple<Args...>;
  26. };
  27. template <typename MethodPtrType>
  28. using ExtractMethodReturnType =
  29. typename MethodTraits<MethodPtrType>::ReturnType;
  30. template <typename MethodPtrType>
  31. using ExtractMethodArgsTuple = typename MethodTraits<MethodPtrType>::ArgsTuple;
  32. } // namespace internal
  33. } // namespace base
  34. #endif // BASE_THREADING_SEQUENCE_BOUND_INTERNAL_H_