Skip to content

Commit

Permalink
[Symforce] Use the _t variant instead of ::type
Browse files Browse the repository at this point in the history
These _t versions are available since c++14.
I might have missed some but these are the ones that I found.

Topic: chaoqu_symforce_t
Relative: chaoqu_symforce_replace_typedef
GitOrigin-RevId: b3f7d77e1583a556dce772f8b85a5388a4385c51
  • Loading branch information
chao-qu-skydio authored and aaron-skydio committed Mar 31, 2023
1 parent 59a0309 commit 72c45e4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions symforce/opt/factor.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ Factor<Scalar> Factor<Scalar>::Jacobian(Functor&& func, const std::vector<Key>&
SYM_ASSERT(Traits::num_arguments == keys_to_func.size() + 2);

// Get matrix types from function signature
using ResidualVec = typename std::remove_pointer<
typename Traits::template arg<Traits::num_arguments - 2>::type>::type;
using JacobianMat = typename std::remove_pointer<
typename Traits::template arg<Traits::num_arguments - 1>::type>::type;
using ResidualVec = typename std::remove_pointer_t<
typename Traits::template arg<Traits::num_arguments - 2>::type>;
using JacobianMat = typename std::remove_pointer_t<
typename Traits::template arg<Traits::num_arguments - 1>::type>;

// Check that they're Eigen matrices (nice for error messages)
static_assert(kIsEigenType<ResidualVec>,
Expand Down
16 changes: 8 additions & 8 deletions symforce/opt/internal/factor_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct JacobianFuncTypeHelper {
template <int Index>
using ArgType = typename Traits::template arg<Index>::base_type;

using ResidualVec = typename std::remove_pointer<ArgType<Traits::num_arguments - 2>>::type;
using JacobianMat = typename std::remove_pointer<ArgType<Traits::num_arguments - 1>>::type;
using ResidualVec = typename std::remove_pointer_t<ArgType<Traits::num_arguments - 2>>;
using JacobianMat = typename std::remove_pointer_t<ArgType<Traits::num_arguments - 1>>;
};

/**
Expand Down Expand Up @@ -166,8 +166,8 @@ auto JacobianFixed(Functor&& func) {
using FunctorType = std::decay_t<Functor>;

// Get matrix types from function signature
using JacobianMat = typename std::remove_pointer<
typename Traits::template arg<Traits::num_arguments - 1>::type>::type;
using JacobianMat = typename std::remove_pointer_t<
typename Traits::template arg<Traits::num_arguments - 1>::type>;

return [func = std::forward<Functor>(func)](const Values<Scalar>& values,
const std::vector<index_entry_t>& keys_to_func,
Expand Down Expand Up @@ -231,10 +231,10 @@ struct HessianFuncTypeHelper {
template <int Index>
using ArgType = typename Traits::template arg<Index>::base_type;

using ResidualVec = typename std::remove_pointer<ArgType<Traits::num_arguments - 4>>::type;
using JacobianMat = typename std::remove_pointer<ArgType<Traits::num_arguments - 3>>::type;
using HessianMat = typename std::remove_pointer<ArgType<Traits::num_arguments - 2>>::type;
using RhsVec = typename std::remove_pointer<ArgType<Traits::num_arguments - 1>>::type;
using ResidualVec = typename std::remove_pointer_t<ArgType<Traits::num_arguments - 4>>;
using JacobianMat = typename std::remove_pointer_t<ArgType<Traits::num_arguments - 3>>;
using HessianMat = typename std::remove_pointer_t<ArgType<Traits::num_arguments - 2>>;
using RhsVec = typename std::remove_pointer_t<ArgType<Traits::num_arguments - 1>>;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions symforce/opt/templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct function_traits : public function_traits<decltype(&remove_cvref_t<T>::ope
template <typename ReturnType, typename... Args>
struct function_traits<ReturnType(Args...)> {
using return_type = ReturnType;
using base_return_type = typename std::decay<return_type>::type;
using base_return_type = typename std::decay_t<return_type>;
using std_function_type = typename std::function<ReturnType(Args...)>;

static constexpr std::size_t num_arguments = sizeof...(Args);
Expand All @@ -72,7 +72,7 @@ struct function_traits<ReturnType(Args...)> {
struct arg {
static_assert(N < num_arguments, "error: invalid parameter index.");
using type = typename std::tuple_element<N, std::tuple<Args...>>::type;
using base_type = typename std::decay<type>::type;
using base_type = typename std::decay_t<type>;
};
};

Expand Down
2 changes: 1 addition & 1 deletion symforce/opt/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ auto NumericalDerivative(const F f, const X& x,
kDefaultEpsilon<typename StorageOps<X>::Scalar>,
const typename sym::StorageOps<X>::Scalar delta = 1e-2f) {
using Scalar = typename sym::StorageOps<X>::Scalar;
using Y = typename std::result_of<F(X)>::type;
using Y = typename std::result_of_t<F(X)>;
using JacobianMat =
Eigen::Matrix<Scalar, sym::LieGroupOps<Y>::TangentDim(), sym::LieGroupOps<X>::TangentDim()>;
static_assert(std::is_same<typename sym::StorageOps<Y>::Scalar, Scalar>::value,
Expand Down

0 comments on commit 72c45e4

Please sign in to comment.