|
- #pragma once
-
- #include <utility>
-
- #include <cppmp/config.h>
- #include <cppmp/core/types.h>
- #include <cppmp/core/checker.h>
-
- namespace cppmp
- {
-
- namespace __impl
- {
- template<typename T>
- struct is_default_impl
- {
- private:
- template<typename X>
- static void impl(decltype(typename X::is_default(), int()));
-
- template<typename X>
- static bool impl(char);
-
- public:
- static const bool value = std::is_same<void, decltype(impl<T>(0))>::value;
- };
-
- }
-
- /**
- * @brief Helper class to create generic predicates.
- *
- * @tparam T_builder Builder class to pass arguments to.
- */
- template<template<typename...> class T_builder>
- struct generic_predicate
- {
- /**
- * @brief Helper class to check if the passed arguments would create a valid object.
- */
- template<typename... T_args>
- struct is_valid
- : public bool_t<!__impl::is_default_impl<T_builder<list<T_args...>>>::value>
- { };
-
- #ifdef cppmp_supports_variable_templates
- /**
- * @brief Evaluates to true if the passed arguments would create a valid object, false otherwise.
- */
- template<typename... T_args>
- static constexpr bool is_valid_v = is_valid<T_args...>::value;
- #endif
-
- /**
- * @brief Invoke the builder to create the requested object.
- *
- * @param args Arguments to pass to the builder.
- *
- * @return Object created from the builder.
- */
- template<typename... T_args>
- constexpr decltype(auto) operator()(T_args&&... args) const
- { return T_builder<list<T_args...>>::apply(std::forward<T_args>(args)...); }
- };
-
- }
|