You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.8 KiB

  1. #pragma once
  2. #include <utility>
  3. #include <cppmp/config.h>
  4. #include <cppmp/core/types.h>
  5. #include <cppmp/core/checker.h>
  6. namespace cppmp
  7. {
  8. namespace __impl
  9. {
  10. template<typename T>
  11. struct is_default_impl
  12. {
  13. private:
  14. template<typename X>
  15. static void impl(decltype(typename X::is_default(), int()));
  16. template<typename X>
  17. static bool impl(char);
  18. public:
  19. static const bool value = std::is_same<void, decltype(impl<T>(0))>::value;
  20. };
  21. }
  22. /**
  23. * @brief Helper class to create generic predicates.
  24. *
  25. * @tparam T_builder Builder class to pass arguments to.
  26. */
  27. template<template<typename...> class T_builder>
  28. struct generic_predicate
  29. {
  30. /**
  31. * @brief Helper class to check if the passed arguments would create a valid object.
  32. */
  33. template<typename... T_args>
  34. struct is_valid
  35. : public bool_t<!__impl::is_default_impl<T_builder<list<T_args...>>>::value>
  36. { };
  37. #ifdef cppmp_supports_variable_templates
  38. /**
  39. * @brief Evaluates to true if the passed arguments would create a valid object, false otherwise.
  40. */
  41. template<typename... T_args>
  42. static constexpr bool is_valid_v = is_valid<T_args...>::value;
  43. #endif
  44. /**
  45. * @brief Invoke the builder to create the requested object.
  46. *
  47. * @param args Arguments to pass to the builder.
  48. *
  49. * @return Object created from the builder.
  50. */
  51. template<typename... T_args>
  52. constexpr decltype(auto) operator()(T_args&&... args) const
  53. { return T_builder<list<T_args...>>::apply(std::forward<T_args>(args)...); }
  54. };
  55. }