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
181181 template <typename T>
182182 T cast () const
183183 {
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 " );
186186 if constexpr (std::is_enum_v<T>)
187187 {
188188 if (!isNumber ())
@@ -192,23 +192,26 @@ class Any
192192 }
193193 return static_cast <T>( convert<int >().value () );
194194 }
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- }
204195 else
205196 {
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 {
209212 throw std::runtime_error ( res.error () );
210- }
211- return res. value ();
213+ }
214+ }
212215 }
213216 }
214217
You can’t perform that action at this time.
0 commit comments