1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

Convert is_callable to a backport of std::is_invocable (#3023)

This commit is contained in:
Oxan van Leeuwen
2022-01-09 23:07:37 +01:00
committed by GitHub
parent 6b773553fc
commit 499625f266
3 changed files with 16 additions and 15 deletions

View File

@@ -186,17 +186,6 @@ template<typename... Ts> class CallbackManager<void(Ts...)> {
std::vector<std::function<void(Ts...)>> callbacks_;
};
// https://stackoverflow.com/a/37161919/8924614
template<class T, class... Args>
struct is_callable // NOLINT
{
template<class U> static auto test(U *p) -> decltype((*p)(std::declval<Args>()...), void(), std::true_type());
template<class U> static auto test(...) -> decltype(std::false_type());
static constexpr auto value = decltype(test<T>(nullptr))::value; // NOLINT
};
void delay_microseconds_safe(uint32_t us);
template<typename T> class Deduplicator {
@@ -274,6 +263,18 @@ template<typename T> constexpr const T &clamp(const T &v, const T &lo, const T &
}
#endif
// std::is_invocable from C++17
#if __cpp_lib_is_invocable >= 201703
using std::is_invocable;
#else
// https://stackoverflow.com/a/37161919/8924614
template<class T, class... Args> struct is_invocable { // NOLINT(readability-identifier-naming)
template<class U> static auto test(U *p) -> decltype((*p)(std::declval<Args>()...), void(), std::true_type());
template<class U> static auto test(...) -> decltype(std::false_type());
static constexpr auto value = decltype(test<T>(nullptr))::value; // NOLINT
};
#endif
// std::bit_cast from C++20
#if __cpp_lib_bit_cast >= 201806
using std::bit_cast;