• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef PROTOBUF_HPB_REQUIRES_H_
2 #define PROTOBUF_HPB_REQUIRES_H_
3 
4 #include <type_traits>
5 namespace hpb::internal {
6 // Ports C++20 `requires` to C++17.
7 // C++20 ideal:
8 //  if constexpr (requires { t.foo(); }) { ... }
9 // Our C++17 stopgap solution:
10 //  if constexpr (Requires<T>([](auto x) -> decltype(x.foo()) {})) { ... }
11 template <typename... T, typename F>
Requires(F)12 constexpr bool Requires(F) {
13   return std::is_invocable_v<F, T...>;
14 }
15 }  // namespace hpb::internal
16 
17 #endif  // PROTOBUF_HPB_REQUIRES_H_
18