Skip to content

Commit f7a1b35

Browse files
Fix #320 : forbit refrences in Any
1 parent dfa90bc commit f7a1b35

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/behaviortree_cpp_v3/utils/safe_any.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Any
9292
template <typename T>
9393
explicit Any(const T& value, EnableNonIntegral<T> = 0) : _any(value), _original_type( &typeid(T) )
9494
{
95+
static_assert(!std::is_reference_v<T>, "Any can not contain references");
9596
}
9697

9798
Any& operator = (const Any& other)
@@ -118,6 +119,8 @@ class Any
118119
template <typename T>
119120
T cast() const
120121
{
122+
static_assert(!std::is_reference_v<T>, "Any::cast uses value semantic, can not cast to reference");
123+
121124
if( _any.empty() )
122125
{
123126
throw std::runtime_error("Any::cast failed because it is empty");

0 commit comments

Comments
 (0)