Botcraft 1.21.4
Loading...
Searching...
No Matches
Templates.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
5// Generate two constexpr templated bools to check if
6// a function is a member of a class.
7// - has_name<Class, function> to check for simple name existence
8// - has_name<Class, function, ret(args...)> to check for existence with signature constraint
9#define GENERATE_CHECK_HAS_FUNC(FuncName) \
10template <typename, typename = void, typename = void> \
11constexpr bool has_##FuncName = false; \
12 \
13template <typename T> \
14constexpr bool has_##FuncName<T, \
15 typename ::std::enable_if_t<::std::is_member_function_pointer_v<decltype(&T::FuncName)>>> \
16= true; \
17 \
18template <typename T, typename Ret, typename... Args> \
19constexpr bool has_##FuncName<T, Ret(Args...), \
20 ::std::void_t<decltype(::std::declval<T>().FuncName(::std::declval<Args>()...))>> \
21= ::std::is_same_v<decltype(::std::declval<T>().FuncName(::std::declval<Args>()...)), Ret>; \
22 static_assert(true, "") /* To require a ; after macro call */