123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #ifndef CERES_PUBLIC_INTERNAL_JET_TRAITS_H_
- #define CERES_PUBLIC_INTERNAL_JET_TRAITS_H_
- #include <tuple>
- #include <type_traits>
- #include <utility>
- #include "ceres/internal/integer_sequence_algorithm.h"
- #include "ceres/jet_fwd.h"
- namespace ceres {
- namespace internal {
- template <typename... Types>
- struct AreAnyJet : std::false_type {};
- template <typename T, typename... Types>
- struct AreAnyJet<T, Types...> : AreAnyJet<Types...> {};
- template <typename T, int N, typename... Types>
- struct AreAnyJet<Jet<T, N>, Types...> : std::true_type {};
- template <typename... Types>
- inline constexpr bool AreAnyJet_v = AreAnyJet<Types...>::value;
- template <typename T, typename E = void>
- struct UnderlyingScalar {
- using type = T;
- };
- template <typename T, int N>
- struct UnderlyingScalar<Jet<T, N>> : UnderlyingScalar<T> {};
- template <typename T>
- using UnderlyingScalar_t = typename UnderlyingScalar<T>::type;
- template <typename T1, typename... Types>
- inline constexpr bool AreAllSame_v = (std::is_same<T1, Types>::value && ...);
- template <typename T, typename E = void>
- struct Rank : std::integral_constant<int, -1> {};
- template <typename T>
- struct Rank<T, std::enable_if_t<std::is_scalar<T>::value>>
- : std::integral_constant<int, 0> {};
- template <typename T, int N>
- struct Rank<Jet<T, N>> : std::integral_constant<int, N> {};
- template <typename T>
- inline constexpr int Rank_v = Rank<T>::value;
- template <typename... Types>
- using Ranks_t = std::integer_sequence<int, Rank_v<Types>...>;
- template <typename T>
- constexpr decltype(auto) AsScalar(T&& value) noexcept {
- return std::forward<T>(value);
- }
- template <typename T, int N>
- constexpr decltype(auto) AsScalar(const Jet<T, N>& value) noexcept(
- noexcept(AsScalar(value.a))) {
- return AsScalar(value.a);
- }
- }
- template <typename... Types>
- struct CompatibleJetOperands : std::integral_constant
- <
- bool,
-
- internal::AreAnyJet_v<Types...> &&
-
- internal::AreAllSame_v<internal::UnderlyingScalar_t<Types>...> &&
-
- internal::IsEmptyOrAreAllEqual_v<internal::RemoveValue_t<internal::Ranks_t<Types...>, 0>>
- >
- {};
- template <typename T, int N>
- struct CompatibleJetOperands<Jet<T, N>> : std::true_type {};
- template <typename T>
- struct CompatibleJetOperands<T> : std::false_type {};
- template <>
- struct CompatibleJetOperands<> : std::false_type {};
- template <typename... Types>
- inline constexpr bool CompatibleJetOperands_v =
- CompatibleJetOperands<Types...>::value;
- template <typename... Types>
- struct PromotableJetOperands : std::integral_constant
- <
- bool,
-
- internal::AreAnyJet_v<Types...> &&
-
- internal::IsEmptyOrAreAllEqual_v<internal::RemoveValue_t<internal::Ranks_t<Types...>, 0>>
- >
- {};
- template <typename... Types>
- inline constexpr bool PromotableJetOperands_v =
- PromotableJetOperands<Types...>::value;
- }
- #endif
|