File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 130130#include < stan/math/prim/meta/scalar_type.hpp>
131131#include < stan/math/prim/meta/seq_view.hpp>
132132#include < stan/math/prim/meta/static_select.hpp>
133- #include < stan/math/prim/meta/tuple_elt.hpp>
133+ #include < stan/math/prim/meta/tuple_element.hpp>
134+ #include < stan/math/prim/meta/tuple_size.hpp>
134135#include < stan/math/prim/meta/value_type.hpp>
135136#include < stan/math/prim/meta/void_t.hpp>
136137#include < stan/math/prim/meta/StdVectorBuilder.hpp>
Original file line number Diff line number Diff line change @@ -62,10 +62,12 @@ inline constexpr bool is_tuple_v = math::is_tuple_v<T>;
6262 * @tparam N expected size
6363 * @ingroup type_trait
6464 */
65+ template <typename T, std::size_t N, typename = void >
66+ struct is_tuple_of_size : std::false_type {};
67+
6568template <typename T, std::size_t N>
66- struct is_tuple_of_size
67- : std::bool_constant<
68- is_tuple_v<T> && std::tuple_size_v<std::decay_t <T>> == N> {};
69+ struct is_tuple_of_size <T, N, std::enable_if_t <is_tuple_v<T>>>
70+ : std::bool_constant<std::tuple_size_v<std::decay_t <T>> == N> {};
6971
7072template <typename T, std::size_t N>
7173inline constexpr bool is_tuple_of_size_v = is_tuple_of_size<T, N>::value;
Original file line number Diff line number Diff line change 1- #ifndef STAN_MATH_PRIM_META_IS_TUPLE_ELT_HPP
2- #define STAN_MATH_PRIM_META_IS_TUPLE_ELT_HPP
1+ #ifndef STAN_MATH_PRIM_META_TUPLE_ELEMENT_HPP
2+ #define STAN_MATH_PRIM_META_TUPLE_ELEMENT_HPP
3+
4+ #include < stan/math/prim/meta/is_tuple.hpp>
5+ #include < stan/math/prim/meta/tuple_size.hpp>
36
47#include < type_traits>
58#include < cstddef>
@@ -20,8 +23,8 @@ struct tuple_element {
2023};
2124
2225template <std::size_t N, typename T>
23- struct tuple_element <
24- N, T, std::enable_if_t <(N < std:: tuple_size_v<std:: decay_t <T> >)>> {
26+ struct tuple_element <N, T,
27+ std::enable_if_t <is_tuple_v<T> && (N < tuple_size_v<T >)>> {
2528 using type = std::tuple_element_t <N, std::decay_t <T>>;
2629};
2730
Original file line number Diff line number Diff line change 1+ #ifndef STAN_MATH_PRIM_META_TUPLE_SIZE_HPP
2+ #define STAN_MATH_PRIM_META_TUPLE_SIZE_HPP
3+
4+ #include < stan/math/prim/meta/is_tuple.hpp>
5+ #include < type_traits>
6+ #include < cstddef>
7+ #include < tuple>
8+
9+ namespace stan {
10+
11+ /* *
12+ * Equivalent to std::tuple_size but returns 0 T is not a tuple
13+ * @tparam T type to get tuple size of
14+ * @ingroup type_trait
15+ */
16+ template <typename T, typename = void >
17+ struct tuple_size : std::integral_constant<std::size_t , 0 > {};
18+
19+ template <typename T>
20+ struct tuple_size <T, std::enable_if_t <is_tuple_v<T>>>
21+ : std::integral_constant<std::size_t , std::tuple_size_v<std::decay_t <T>>> {
22+ };
23+
24+ template <typename T>
25+ constexpr std::size_t tuple_size_v = tuple_size<T>::value;
26+ } // namespace stan
27+
28+ #endif
You can’t perform that action at this time.
0 commit comments