better use functor-style access instead of implicit conversion

This commit is contained in:
Fischlurch 2010-11-06 22:49:32 +01:00
parent f597e7c8b4
commit bd361523d1
2 changed files with 6 additions and 6 deletions

View file

@ -38,7 +38,7 @@ namespace lib {
/**
* Optional or switchable link to an existing object.
* This reference wrapper normally behaves like a reference,
* This reference wrapper is accessed like a functor,
* but has the ability to be \em disabled. This disabled state
* is managed automatically by ctor and dtor, can be detected
* through \c bool check and -- contrary to a \c NULL pointer
@ -75,7 +75,8 @@ namespace lib {
: ref_(&target)
{ }
operator T& () const ///< ...allowing implicit conversion to T&
T&
operator() () const
{
if (!isValid())
throw lumiera::error::Logic ("access to this object is (not/yet) enabled"
@ -129,8 +130,7 @@ namespace lib {
friend bool
operator== (OptionalRef const& ref, T const& otherTarget) ///< @note might throw
{
T const& thisTarget (ref); // might throw
return thisTarget == otherTarget;
return ref() == otherTarget;
}
friend bool operator== (T const& otherTarget, OptionalRef const& ref) { return ref == otherTarget; }

View file

@ -65,7 +65,7 @@ namespace test{
SRef r1;
CHECK (!r1);
VERIFY_ERROR (BOTTOM_VALUE, s1 = r1 );
VERIFY_ERROR (BOTTOM_VALUE, r1() );
VERIFY_ERROR (BOTTOM_VALUE, s1 == r1 );
VERIFY_ERROR (BOTTOM_VALUE, r1 == s1 );
CHECK (!r1.points_to (s1));
@ -95,7 +95,7 @@ namespace test{
r2.clear();
CHECK (!r2);
VERIFY_ERROR (BOTTOM_VALUE, s1 = r2 );
VERIFY_ERROR (BOTTOM_VALUE, r2() );
VERIFY_ERROR (BOTTOM_VALUE, s1 == r2 );
VERIFY_ERROR (BOTTOM_VALUE, r2 == s1 );
VERIFY_ERROR (BOTTOM_VALUE, r2 == s2 );