12#ifndef INCLUDE_ARK_TYPECHECKER_HPP
13#define INCLUDE_ARK_TYPECHECKER_HPP
31 template <
typename T,
typename... Ts>
32 using AllSame = std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>;
35 bool checkN([[maybe_unused]]
const std::vector<Value>& args)
40 template <
int I,
typename T,
typename... Ts>
41 bool checkN(
const std::vector<Value>& args, T type, Ts... xs)
43 if (I >= args.size() || (type !=
ValueType::Any && args[I].valueType() != type))
45 return checkN<I + 1>(args, xs...);
59 bool check(
const std::vector<Value>& args, Ts... types)
61 if (
sizeof...(types) != args.size())
63 return details::checkN<0>(args, types...);
77 name(name), types { type }, variadic(variadic)
80 Typedef(std::string_view name,
const std::vector<ValueType>& types,
bool variadic =
false) :
81 name(name), types(types), variadic(variadic)
101 ARK_API void generateError [[noreturn]] (std::string_view funcname,
const std::vector<Contract>& contracts,
const std::vector<Value>& args);
std::enable_if_t< std::conjunction_v< std::is_same< T, Ts >... > > AllSame
bool checkN(const std::vector< Value > &args)
bool check(const std::vector< Value > &args, Ts... types)
Helper to see if a builtin has been given a wanted set of types.
ARK_API void generateError(std::string_view funcname, const std::vector< Contract > &contracts, const std::vector< Value > &args)
Generate an error message based on a given set of types contracts provided argument list.
A contract is a list of typed arguments that a function can follow.
std::vector< Typedef > arguments
A type definition within a contract.
Typedef(std::string_view name, const std::vector< ValueType > &types, bool variadic=false)
Typedef(std::string_view name, ValueType type, bool variadic=false)
std::vector< ValueType > types