File tree Expand file tree Collapse file tree 1 file changed +19
-16
lines changed
include/behaviortree_cpp/utils Expand file tree Collapse file tree 1 file changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -181,8 +181,8 @@ class Any
181
181
template <typename T>
182
182
T cast () const
183
183
{
184
- static_assert (!std::is_reference<T>::value, " Any::cast uses value semantic, can not cast to reference " );
185
-
184
+ static_assert (!std::is_reference<T>::value, " Any::cast uses value semantic, "
185
+ " can not cast to reference " );
186
186
if constexpr (std::is_enum_v<T>)
187
187
{
188
188
if (!isNumber ())
@@ -192,23 +192,26 @@ class Any
192
192
}
193
193
return static_cast <T>( convert<int >().value () );
194
194
}
195
-
196
- if ( _any.empty () )
197
- {
198
- throw std::runtime_error (" Any::cast failed because it is empty" );
199
- }
200
- if (_any.type () == typeid (T))
201
- {
202
- return linb::any_cast<T>(_any);
203
- }
204
195
else
205
196
{
206
- auto res = convert<T>();
207
- if ( !res )
208
- {
197
+ if ( _any.empty () )
198
+ {
199
+ throw std::runtime_error (" Any::cast failed because it is empty" );
200
+ }
201
+ if (_any.type () == typeid (T))
202
+ {
203
+ return linb::any_cast<T>(_any);
204
+ }
205
+ else
206
+ {
207
+ if (auto res = convert<T>())
208
+ {
209
+ return res.value ();
210
+ }
211
+ else {
209
212
throw std::runtime_error ( res.error () );
210
- }
211
- return res. value ();
213
+ }
214
+ }
212
215
}
213
216
}
214
217
You can’t perform that action at this time.
0 commit comments