diff --git a/src/lib/meta/function-erasure.hpp b/src/lib/meta/function-erasure.hpp index f86de74b9..6d3729160 100644 --- a/src/lib/meta/function-erasure.hpp +++ b/src/lib/meta/function-erasure.hpp @@ -64,6 +64,7 @@ namespace lumiera { namespace typelist{ using std::tr1::function; + using util::unConst; @@ -100,8 +101,6 @@ namespace typelist{ * Using this policy allows to store arbitrary complex functor objects * embedded within a neutral container and retrieving them later type-safe. * The price to pay is vtable access and heap storage of function arguments. - * - * @note the bool conversion and #isValid are highly implementation dependent */ class StoreFunction : public lib::BoolCheckable @@ -112,6 +111,7 @@ namespace typelist{ enum { SIZE = sizeof(function) }; char storage_[SIZE]; virtual ~Holder() {} + virtual bool isValid() const { return false; } }; /** embedding the concrete functor object */ @@ -129,6 +129,12 @@ namespace typelist{ { get().~Functor(); } + bool + isValid() const + { + const Functor& func (unConst(this)->get()); + return bool(func); + } Functor& get() { @@ -161,9 +167,9 @@ namespace typelist{ } bool - isValid() const ///< @note implementation dependent!! + isValid() const { - return reinterpret_cast (holder_.storage_[0]); + return holder_.isValid(); } }; diff --git a/tests/lib/meta/function-erasure-test.cpp b/tests/lib/meta/function-erasure-test.cpp index 43320c453..aadd03e14 100644 --- a/tests/lib/meta/function-erasure-test.cpp +++ b/tests/lib/meta/function-erasure-test.cpp @@ -47,9 +47,9 @@ namespace test { typedef FunErasure Evoid; template - struct BuildEmptyHolder { typedef long (*Type)(int,char); }; + struct BuildEmptyFunctor { typedef long (*Type)(int,char); }; template<> - struct BuildEmptyHolder { typedef function Type; }; + struct BuildEmptyFunctor { typedef function Type; }; /*********************************************************************** @@ -210,8 +210,9 @@ namespace test { { // fabricate an unbound functor... - typedef typename BuildEmptyHolder::Type EmptyHolder; - EmptyHolder emptyHolder; + typedef typename BuildEmptyFunctor::Type NoFunc; + NoFunc noFunction; + HOL emptyHolder (noFunction); ASSERT (!emptyHolder); ASSERT ( h1 ); ASSERT ( h2 );