您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

65 行
1.7 KiB

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