@@ -41,8 +41,8 @@ inline void validate_expr(const exprt &) {}
41
41
namespace detail // NOLINT
42
42
{
43
43
44
- // We hide these functions in a namespace so that only functions that they only
45
- // participate in overload resolution when explicitly requested.
44
+ // We hide these functions in a namespace so that they only participate in
45
+ // overload resolution when explicitly requested.
46
46
47
47
// / \brief Try to cast a reference to a generic exprt to a specific derived
48
48
// / class
@@ -56,39 +56,21 @@ template <typename T, typename TExpr>
56
56
optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
57
57
expr_try_dynamic_cast (TExpr &base)
58
58
{
59
- typedef typename std::decay<T>::type TUnderlyingt;
60
- typedef typename std::remove_reference<T>::type TConstt;
59
+ typedef typename std::decay<T>::type decayt;
61
60
static_assert (
62
61
std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
63
62
" Tried to expr_try_dynamic_cast from something that wasn't an exprt" );
64
63
static_assert (
65
64
std::is_reference<T>::value,
66
65
" Tried to convert exprt & to non-reference type" );
67
66
static_assert (
68
- std::is_base_of<exprt, TUnderlyingt >::value,
67
+ std::is_base_of<exprt, decayt >::value,
69
68
" The template argument T must be derived from exprt." );
70
- if (!can_cast_expr<TUnderlyingt >(base))
69
+ if (!can_cast_expr<decayt >(base))
71
70
return {};
72
71
T ret=static_cast <T>(base);
73
72
validate_expr (ret);
74
- return std::reference_wrapper<TConstt>(ret);
75
- }
76
-
77
- // / \brief Try to cast a reference to a generic exprt to a specific derived
78
- // / class
79
- // / \tparam T The reference or const reference type to \a TUnderlying to cast
80
- // / to
81
- // / \tparam TExpr The original type to cast from, either exprt or const exprt
82
- // / \param base Reference to a generic \ref exprt
83
- // / \return Reference to object of type \a TUnderlying
84
- // / or valueless optional if \a base is not an instance of \a TUnderlying
85
- template <typename T, typename TExpr>
86
- optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
87
- expr_try_checked_cast (TExpr &base)
88
- {
89
- typedef typename std::decay<T>::type TUnderlyingt;
90
- PRECONDITION (can_cast_expr<TUnderlyingt>(base));
91
- return expr_try_checked_cast<T>(base);
73
+ return std::reference_wrapper<typename std::remove_reference<T>::type>(ret);
92
74
}
93
75
94
76
} // namespace detail
@@ -119,37 +101,11 @@ expr_try_dynamic_cast(exprt &base)
119
101
return detail::expr_try_dynamic_cast<T>(base);
120
102
}
121
103
122
- // / \brief Try to cast a constant reference to a generic exprt to a specific
123
- // / derived class. Also assert that the expr invariants are not violated.
124
- // / \tparam T The exprt-derived class to cast to
125
- // / \param base Reference to a generic \ref exprt
126
- // / \return Reference to object of type \a T or valueless optional if \a base
127
- // / is not an instance of \a T
128
- template <typename T>
129
- optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
130
- expr_try_checked_cast (const exprt &base)
131
- {
132
- return detail::expr_try_checked_cast<T>(base);
133
- }
134
-
135
- // / \brief Try to cast a reference to a generic exprt to a specific derived
136
- // / class. Also assert that the expr invariants are not violated.
137
- // / \tparam T The exprt-derived class to cast to
138
- // / \param base Reference to a generic \ref exprt
139
- // / \return Reference to object of type \a T or valueless optional if \a base is
140
- // / not an instance of \a T
141
- template <typename T>
142
- optionalt<std::reference_wrapper<typename std::remove_reference<T>::type>>
143
- expr_try_checked_cast (exprt &base)
144
- {
145
- return detail::expr_try_checked_cast<T>(base);
146
- }
147
-
148
104
namespace detail // NOLINT
149
105
{
150
106
151
- // We hide these functions in a namespace so that only functions that they only
152
- // participate in overload resolution when explicitly requested.
107
+ // We hide these functions in a namespace so that they only participate in
108
+ // overload resolution when explicitly requested.
153
109
154
110
// / \brief Cast a reference to a generic exprt to a specific derived class.
155
111
// / \tparam T The reference or const reference type to \a TUnderlying to cast to
@@ -160,17 +116,17 @@ namespace detail // NOLINT
160
116
template <typename T, typename TExpr>
161
117
T expr_dynamic_cast (TExpr &base)
162
118
{
163
- typedef typename std::decay<T>::type TUnderlyingt ;
119
+ typedef typename std::decay<T>::type decayt ;
164
120
static_assert (
165
121
std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
166
122
" Tried to expr_dynamic_cast from something that wasn't an exprt" );
167
123
static_assert (
168
124
std::is_reference<T>::value,
169
125
" Tried to convert exprt & to non-reference type" );
170
126
static_assert (
171
- std::is_base_of<exprt, TUnderlyingt >::value,
127
+ std::is_base_of<exprt, decayt >::value,
172
128
" The template argument T must be derived from exprt." );
173
- if (!can_cast_expr<TUnderlyingt >(base))
129
+ if (!can_cast_expr<decayt >(base))
174
130
throw std::bad_cast ();
175
131
T ret=static_cast <T>(base);
176
132
validate_expr (ret);
@@ -189,8 +145,7 @@ T expr_dynamic_cast(TExpr &base)
189
145
template <typename T, typename TExpr>
190
146
T expr_checked_cast (TExpr &base)
191
147
{
192
- typedef typename std::decay<T>::type TUnderlyingt;
193
- PRECONDITION (can_cast_expr<TUnderlyingt>(base));
148
+ PRECONDITION (can_cast_expr<typename std::decay<T>::type>(base));
194
149
return expr_dynamic_cast<T>(base);
195
150
}
196
151
0 commit comments