Skip to content

Commit 47a13c7

Browse files
committed
Remove unnecessary explicit typelists
1 parent bc3d79b commit 47a13c7

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

src/util/expr_cast.h

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ template<typename T> bool can_cast_expr(const exprt &base);
3535
/// validate particular types.
3636
inline void validate_expr(const exprt &) {}
3737

38-
namespace detail
38+
namespace detail // NOLINT
3939
{
4040

4141
// We hide this in a namespace so that only functions that it only
@@ -50,9 +50,12 @@ namespace detail
5050
/// \param base Reference to a generic \ref exprt
5151
/// \return Reference to object of type \a TUnderlying
5252
/// or valueless optional if \a base is not an instance of \a TUnderlying
53-
template<typename T, typename TConst, typename TUnderlying, typename TExpr>
54-
optionalt<std::reference_wrapper<TConst>> expr_try_dynamic_cast(TExpr &base)
53+
template <typename T, typename TExpr>
54+
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
55+
expr_try_dynamic_cast(TExpr &base)
5556
{
57+
typedef typename std::decay<T>::type TUnderlying;
58+
typedef typename std::remove_reference<T>::type TConst;
5659
static_assert(
5760
std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
5861
"Tried to expr_try_dynamic_cast from something that wasn't an exprt");
@@ -63,10 +66,10 @@ optionalt<std::reference_wrapper<TConst>> expr_try_dynamic_cast(TExpr &base)
6366
std::is_base_of<exprt, TUnderlying>::value,
6467
"The template argument T must be derived from exprt.");
6568
if(!can_cast_expr<TUnderlying>(base))
66-
return optionalt<std::reference_wrapper<TConst>>();
69+
return {};
6770
T value=static_cast<T>(base);
6871
validate_expr(value);
69-
return optionalt<std::reference_wrapper<TConst>>(value);
72+
return std::reference_wrapper<TConst>(value);
7073
}
7174

7275
} // namespace detail
@@ -81,11 +84,7 @@ template<typename T>
8184
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
8285
expr_try_dynamic_cast(const exprt &base)
8386
{
84-
return detail::expr_try_dynamic_cast<
85-
T,
86-
typename std::remove_reference<T>::type,
87-
typename std::decay<T>::type,
88-
const exprt>(base);
87+
return detail::expr_try_dynamic_cast<T>(base);
8988
}
9089

9190
/// \brief Try to cast a reference to a generic exprt to a specific derived
@@ -98,14 +97,10 @@ template<typename T>
9897
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
9998
expr_try_dynamic_cast(exprt &base)
10099
{
101-
return detail::expr_try_dynamic_cast<
102-
T,
103-
typename std::remove_reference<T>::type,
104-
typename std::decay<T>::type,
105-
exprt>(base);
100+
return detail::expr_try_dynamic_cast<T>(base);
106101
}
107102

108-
namespace detail
103+
namespace detail // NOLINT
109104
{
110105

111106
// We hide this in a namespace so that only functions that it only
@@ -120,9 +115,10 @@ namespace detail
120115
/// \throw std::bad_cast If \a base is not an instance of \a TUnderlying
121116
/// \remark If CBMC assertions (PRECONDITION) are set to abort then this will
122117
/// abort rather than throw if \a base is not an instance of \a TUnderlying
123-
template<typename T, typename TUnderlying, typename TExpr>
118+
template<typename T, typename TExpr>
124119
T expr_dynamic_cast(TExpr &base)
125120
{
121+
typedef typename std::decay<T>::type TUnderlying;
126122
static_assert(
127123
std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
128124
"Tried to expr_dynamic_cast from something that wasn't an exprt");
@@ -153,10 +149,7 @@ T expr_dynamic_cast(TExpr &base)
153149
template<typename T>
154150
T expr_dynamic_cast(const exprt &base)
155151
{
156-
return detail::expr_dynamic_cast<
157-
T,
158-
typename std::decay<T>::type,
159-
const exprt>(base);
152+
return detail::expr_dynamic_cast<T>(base);
160153
}
161154

162155
/// \brief Cast a reference to a generic exprt to a specific derived class
@@ -169,10 +162,7 @@ T expr_dynamic_cast(const exprt &base)
169162
template<typename T>
170163
T expr_dynamic_cast(exprt &base)
171164
{
172-
return detail::expr_dynamic_cast<
173-
T,
174-
typename std::decay<T>::type,
175-
exprt>(base);
165+
return detail::expr_dynamic_cast<T>(base);
176166
}
177167

178168
inline void validate_operands(

0 commit comments

Comments
 (0)