Skip to content

Commit b9d0a33

Browse files
authored
Merge pull request #2965 from stan-dev/feature/simplify-meta
Expanding 5 macros `STAN_ADD_REQUIRE_*` directly into code.
2 parents de0c1a7 + 66b92b5 commit b9d0a33

36 files changed

+2880
-636
lines changed

doxygen/contributor_help_pages/require_meta.md

Lines changed: 427 additions & 116 deletions
Large diffs are not rendered by default.

stan/math/prim/meta/is_arena_matrix.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ namespace stan {
1212
template <typename T, typename = void>
1313
struct is_arena_matrix : std::false_type {};
1414

15-
STAN_ADD_REQUIRE_UNARY(arena_matrix, is_arena_matrix, require_eigens_types);
16-
STAN_ADD_REQUIRE_CONTAINER(arena_matrix, is_arena_matrix, require_eigens_types);
17-
STAN_ADD_REQUIRE_UNARY_INNER(arena_matrix, is_arena_matrix,
18-
require_eigens_types);
15+
/*! \ingroup require_eigen_types */
16+
/*! \defgroup arena_matrix_types arena_matrix */
17+
/*! \addtogroup arena_matrix_types */
18+
/*! @{ */
19+
20+
/*! \brief Require type satisfies @ref is_arena_matrix */
21+
/*! @tparam T the type to check */
22+
template <typename T>
23+
using require_arena_matrix_t = require_t<is_arena_matrix<std::decay_t<T>>>;
24+
/*! @} */
1925

2026
} // namespace stan
2127
#endif

stan/math/prim/meta/is_autodiff.hpp

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,82 @@ struct is_autodiff
1919
: bool_constant<math::disjunction<is_var<std::decay_t<T>>,
2020
is_fvar<std::decay_t<T>>>::value> {};
2121

22-
STAN_ADD_REQUIRE_UNARY(autodiff, is_autodiff, require_stan_scalar_real);
23-
STAN_ADD_REQUIRE_UNARY_INNER(autodiff, is_autodiff, require_stan_scalar_real);
22+
/*! \ingroup require_stan_scalar_real */
23+
/*! \defgroup autodiff_types autodiff */
24+
/*! \addtogroup autodiff_types */
25+
/*! @{ */
26+
27+
/*! \brief Require type satisfies @ref is_autodiff */
28+
/*! @tparam T the type to check */
29+
template <typename T>
30+
using require_autodiff_t = require_t<is_autodiff<std::decay_t<T>>>;
31+
32+
/*! \brief Require type does not satisfy @ref is_autodiff */
33+
/*! @tparam T the type to check */
34+
template <typename T>
35+
using require_not_autodiff_t = require_not_t<is_autodiff<std::decay_t<T>>>;
36+
37+
/*! \brief Require all of the types satisfy @ref is_autodiff */
38+
/*! @tparam Types The types that are checked */
39+
template <typename... Types>
40+
using require_all_autodiff_t
41+
= require_all_t<is_autodiff<std::decay_t<Types>>...>;
42+
43+
/*! \brief Require any of the types satisfy @ref is_autodiff */
44+
/*! @tparam Types The types that are checked */
45+
template <typename... Types>
46+
using require_any_autodiff_t
47+
= require_any_t<is_autodiff<std::decay_t<Types>>...>;
48+
49+
/*! \brief Require none of the types satisfy @ref is_autodiff */
50+
/*! @tparam Types The types that are checked */
51+
template <typename... Types>
52+
using require_all_not_autodiff_t
53+
= require_all_not_t<is_autodiff<std::decay_t<Types>>...>;
54+
55+
/*! \brief Require at least one of the types do not satisfy @ref is_autodiff */
56+
/*! @tparam Types The types that are checked */
57+
template <typename... Types>
58+
using require_any_not_autodiff_t
59+
= require_any_not_t<is_autodiff<std::decay_t<Types>>...>;
60+
/*! @} */
61+
62+
/*! \ingroup require_stan_scalar_real */
63+
/*! \addtogroup autodiff_types */
64+
/*! @{ */
65+
66+
/*! \brief Require value type does not satisfy @ref is_autodiff */
67+
/*! @tparam T A type with a valid overload of @ref value_type available */
68+
template <typename T>
69+
using require_not_vt_autodiff
70+
= require_not_t<is_autodiff<value_type_t<std::decay_t<T>>>>;
71+
72+
/*! \brief Require none of the value types satisfy @ref is_autodiff */
73+
/*! @tparam Types The types with a valid overload of @ref value_type available
74+
*/
75+
template <typename... Types>
76+
using require_all_not_vt_autodiff
77+
= require_all_not_t<is_autodiff<value_type_t<std::decay_t<Types>>>...>;
78+
79+
/*! \brief Require scalar type satisfies @ref is_autodiff */
80+
/*! @tparam T A type with a valid overload of @ref scalar_type available */
81+
template <typename T>
82+
using require_st_autodiff
83+
= require_t<is_autodiff<scalar_type_t<std::decay_t<T>>>>;
84+
85+
/*! \brief Require scalar type does not satisfy @ref is_autodiff */
86+
/*! @tparam T A type with a valid overload of @ref scalar_type available */
87+
template <typename T>
88+
using require_not_st_autodiff
89+
= require_not_t<is_autodiff<scalar_type_t<std::decay_t<T>>>>;
90+
91+
/*! \brief Require any of the scalar types satisfy is_autodiff */
92+
/*! @tparam Types The types with a valid overload of @ref scalar_type available
93+
*/
94+
template <typename... Types>
95+
using require_any_st_autodiff
96+
= require_any_t<is_autodiff<scalar_type_t<std::decay_t<Types>>>...>;
97+
/*! @} */
2498

2599
} // namespace stan
26100

stan/math/prim/meta/is_complex.hpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,59 @@ struct scalar_type<T, std::enable_if_t<is_complex<T>::value>> {
5555
using type = std::complex<typename std::decay_t<T>::value_type>;
5656
};
5757

58-
STAN_ADD_REQUIRE_UNARY(complex, is_complex, require_stan_scalar_complex);
59-
STAN_ADD_REQUIRE_UNARY_INNER(complex, is_complex, require_stan_scalar_complex);
58+
/*! \ingroup require_stan_scalar_complex */
59+
/*! \defgroup complex_types complex */
60+
/*! \addtogroup complex_types */
61+
/*! @{ */
62+
63+
/*! \brief Require type satisfies @ref is_complex */
64+
/*! @tparam T the type to check */
65+
template <typename T>
66+
using require_complex_t = require_t<is_complex<std::decay_t<T>>>;
67+
68+
/*! \brief Require type does not satisfy @ref is_complex */
69+
/*! @tparam T the type to check */
70+
template <typename T>
71+
using require_not_complex_t = require_not_t<is_complex<std::decay_t<T>>>;
72+
73+
/*! \brief Require all of the types satisfy @ref is_complex */
74+
/*! @tparam Types The types that are checked */
75+
template <typename... Types>
76+
using require_all_complex_t = require_all_t<is_complex<std::decay_t<Types>>...>;
77+
78+
/*! \brief Require any of the types satisfy @ref is_complex */
79+
/*! @tparam Types The types that are checked */
80+
template <typename... Types>
81+
using require_any_complex_t = require_any_t<is_complex<std::decay_t<Types>>...>;
82+
83+
/*! \brief Require none of the types satisfy @ref is_complex */
84+
/*! @tparam Types The types that are checked */
85+
template <typename... Types>
86+
using require_all_not_complex_t
87+
= require_all_not_t<is_complex<std::decay_t<Types>>...>;
88+
/*! @} */
89+
90+
/*! \ingroup require_stan_scalar_complex */
91+
/*! \addtogroup complex_types */
92+
/*! @{ */
93+
94+
/*! \brief Require value type satisfies @ref is_complex */
95+
/*! @tparam T A type with a valid overload of @ref value_type available */
96+
template <typename T>
97+
using require_vt_complex = require_t<is_complex<value_type_t<std::decay_t<T>>>>;
98+
99+
/*! \brief Require value type does not satisfy @ref is_complex */
100+
/*! @tparam T A type with a valid overload of @ref value_type available */
101+
template <typename T>
102+
using require_not_vt_complex
103+
= require_not_t<is_complex<value_type_t<std::decay_t<T>>>>;
104+
105+
/*! \brief Require scalar type does not satisfy @ref is_complex */
106+
/*! @tparam T A type with a valid overload of @ref scalar_type available */
107+
template <typename T>
108+
using require_not_st_complex
109+
= require_not_t<is_complex<scalar_type_t<std::decay_t<T>>>>;
110+
/*! @} */
60111

61112
/**
62113
* If the `value_type` of the type `T` is of type

stan/math/prim/meta/is_constant.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,5 @@ template <typename T>
6262
struct is_constant<T, require_eigen_t<T>>
6363
: bool_constant<is_constant<typename std::decay_t<T>::Scalar>::value> {};
6464

65-
STAN_ADD_REQUIRE_UNARY(constant, is_constant, require_stan_scalar_real);
66-
STAN_ADD_REQUIRE_UNARY_INNER(constant, is_constant, require_stan_scalar_real);
67-
6865
} // namespace stan
6966
#endif

stan/math/prim/meta/is_container.hpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,65 @@ template <typename Container>
2222
using is_container = bool_constant<
2323
math::disjunction<is_eigen<Container>, is_std_vector<Container>>::value>;
2424

25-
STAN_ADD_REQUIRE_UNARY(container, is_container, general_types);
26-
STAN_ADD_REQUIRE_CONTAINER(container, is_container, general_types);
25+
/*! \ingroup general_types */
26+
/*! \defgroup container_types container */
27+
/*! \addtogroup container_types */
28+
/*! @{ */
29+
30+
/*! \brief Require type satisfies @ref is_container */
31+
/*! @tparam T the type to check */
32+
template <typename T>
33+
using require_container_t = require_t<is_container<std::decay_t<T>>>;
34+
35+
/*! \brief Require type does not satisfy @ref is_container */
36+
/*! @tparam T the type to check */
37+
template <typename T>
38+
using require_not_container_t = require_not_t<is_container<std::decay_t<T>>>;
39+
40+
/*! \brief Require all of the types satisfy @ref is_container */
41+
/*! @tparam Types The types that are checked */
42+
template <typename... Types>
43+
using require_all_container_t
44+
= require_all_t<is_container<std::decay_t<Types>>...>;
45+
46+
/*! \brief Require any of the types satisfy @ref is_container */
47+
/*! @tparam Types The types that are checked */
48+
template <typename... Types>
49+
using require_any_container_t
50+
= require_any_t<is_container<std::decay_t<Types>>...>;
51+
52+
/*! \brief Require none of the types satisfy @ref is_container */
53+
/*! @tparam Types The types that are checked */
54+
template <typename... Types>
55+
using require_all_not_container_t
56+
= require_all_not_t<is_container<std::decay_t<Types>>...>;
57+
/*! @} */
58+
59+
/*! \ingroup general_types */
60+
/*! \defgroup container_types container */
61+
/*! \addtogroup container_types */
62+
/*! @{ */
63+
64+
/*! \brief Require type satisfies @ref is_container */
65+
/*! and scalar type satisfies `TypeCheck` */
66+
/*! @tparam TypeCheck The type trait to check the scalar type against */
67+
/*! @tparam Check The type to test @ref is_container for and whose @ref
68+
* scalar_type is checked with `TypeCheck` */
69+
template <template <class...> class TypeCheck, class... Check>
70+
using require_container_st
71+
= require_t<container_type_check_base<is_container, scalar_type_t,
72+
TypeCheck, Check...>>;
73+
74+
/*! \brief Require type does not satisfy @ref is_container */
75+
/*! or scalar type does not satisfy `TypeCheck` */
76+
/*! @tparam TypeCheck The type trait to check the scalar type against */
77+
/*! @tparam Check The type to test @ref is_container for and whose @ref
78+
* scalar_type is checked with `TypeCheck` */
79+
template <template <class...> class TypeCheck, class... Check>
80+
using require_not_container_st
81+
= require_not_t<container_type_check_base<is_container, scalar_type_t,
82+
TypeCheck, Check...>>;
83+
/*! @} */
2784

2885
} // namespace stan
2986

stan/math/prim/meta/is_container_or_var_matrix.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ using is_container_or_var_matrix
2424
= bool_constant<math::disjunction<is_container<Container>,
2525
is_var_matrix<Container>>::value>;
2626

27-
STAN_ADD_REQUIRE_UNARY(container_or_var_matrix, is_container_or_var_matrix,
28-
general_types);
29-
STAN_ADD_REQUIRE_CONTAINER(container_or_var_matrix, is_container_or_var_matrix,
30-
general_types);
31-
3227
} // namespace stan
3328

3429
#endif

stan/math/prim/meta/is_dense_dynamic.hpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,22 @@ struct is_dense_dynamic_impl<T, require_t<is_var<T>>>
3838
template <typename T>
3939
using is_dense_dynamic = internal::is_dense_dynamic_impl<std::decay_t<T>>;
4040

41-
STAN_ADD_REQUIRE_UNARY(dense_dynamic, is_dense_dynamic, require_eigens_types);
42-
STAN_ADD_REQUIRE_CONTAINER(dense_dynamic, is_dense_dynamic,
43-
require_eigens_types);
41+
/*! \ingroup require_eigens_types */
42+
/*! \defgroup dense_dynamic_types dense_dynamic */
43+
/*! \addtogroup dense_dynamic_types */
44+
/*! @{ */
45+
46+
/*! \brief Require type satisfies @ref is_dense_dynamic */
47+
/*! @tparam T the type to check */
48+
template <typename T>
49+
using require_dense_dynamic_t = require_t<is_dense_dynamic<std::decay_t<T>>>;
50+
51+
/*! \brief Require all of the types satisfy @ref is_dense_dynamic */
52+
/*! @tparam Types The types that are checked */
53+
template <typename... Types>
54+
using require_all_dense_dynamic_t
55+
= require_all_t<is_dense_dynamic<std::decay_t<Types>>...>;
56+
/*! @} */
4457

4558
} // namespace stan
4659

stan/math/prim/meta/is_double_or_int.hpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,47 @@ struct is_double_or_int
1818
math::disjunction<std::is_same<double, std::decay_t<T>>,
1919
std::is_same<int, std::decay_t<T>>>::value> {};
2020

21-
STAN_ADD_REQUIRE_UNARY(double_or_int, is_double_or_int,
22-
require_stan_scalar_real);
23-
STAN_ADD_REQUIRE_UNARY_INNER(double_or_int, is_double_or_int,
24-
require_stan_scalar_real);
21+
/*! \ingroup require_stan_scalar_real */
22+
/*! \defgroup double_or_int_types double_or_int */
23+
/*! \addtogroup double_or_int_types */
24+
/*! @{ */
25+
26+
/*! \brief Require type satisfies @ref is_double_or_int */
27+
/*! @tparam T the type to check */
28+
template <typename T>
29+
using require_double_or_int_t = require_t<is_double_or_int<std::decay_t<T>>>;
30+
31+
/*! \brief Require type does not satisfy @ref is_double_or_int */
32+
/*! @tparam T the type to check */
33+
template <typename T>
34+
using require_not_double_or_int_t
35+
= require_not_t<is_double_or_int<std::decay_t<T>>>;
36+
37+
/*! \brief Require all of the types satisfy @ref is_double_or_int */
38+
/*! @tparam Types The types that are checked */
39+
template <typename... Types>
40+
using require_all_double_or_int_t
41+
= require_all_t<is_double_or_int<std::decay_t<Types>>...>;
42+
43+
/*! \brief Require any of the types satisfy @ref is_double_or_int */
44+
/*! @tparam Types The types that are checked */
45+
template <typename... Types>
46+
using require_any_double_or_int_t
47+
= require_any_t<is_double_or_int<std::decay_t<Types>>...>;
48+
49+
/*! \brief Require none of the types satisfy @ref is_double_or_int */
50+
/*! @tparam Types The types that are checked */
51+
template <typename... Types>
52+
using require_all_not_double_or_int_t
53+
= require_all_not_t<is_double_or_int<std::decay_t<Types>>...>;
54+
55+
/*! \brief Require at least one of the types do not satisfy @ref
56+
* is_double_or_int */
57+
/*! @tparam Types The types that are checked */
58+
template <typename... Types>
59+
using require_any_not_double_or_int_t
60+
= require_any_not_t<is_double_or_int<std::decay_t<Types>>...>;
61+
/*! @} */
2562

2663
} // namespace stan
2764
#endif

0 commit comments

Comments
 (0)