Results 1 to 3 of 3

Thread: [3.4.2] IceUtil/Handle.h comparing objects not pointers

  1. #1
    phil++ is offline Registered User
    Name: Philip Kovacs
    Organization: University of Pennsylvania
    Project: Ice Storm Evaluation
    Join Date
    Jul 2007
    Posts
    24

    [3.4.2] IceUtil/Handle.h comparing objects not pointers

    Code:
    //
    // g++ -o test -l IceUtil test.cc
    //
    
    #include <cassert>
    #include <iostream>
    
    #include <IceUtil/Handle.h>
    #include <IceUtil/Shared.h>
    
    class Demo : public ::IceUtil::SimpleShared
    {
      public:
        Demo (int x = 0) :
          x_(x)
        {
        }
        bool operator== (const Demo& d)
        {
          ::std::cout << "erroneous object comparison invoked" << ::std::endl;
          return x_ == d.x_;
        }
      protected:
        virtual ~Demo ()
        {
        }
      private:
        int x_;
    };
    typedef ::IceUtil::Handle<Demo> DemoPtr;
    
    int main ()
    {
      DemoPtr a (new Demo (1));
      DemoPtr b (new Demo (1));
    
      assert (a == b);  // this succeeds, but should fail according to the documented semantics
    
      // Handle.h
      //
      // template<typename T, typename U>
      // inline bool operator==(const HandleBase<T>& lhs, const HandleBase<U>& rhs)
      // {
      //    T* l = lhs.get();
      //    U* r = rhs.get();
      //    if(l && r)
      //    {
      //      return *l == *r;
      //    }
      //    return !l && !r;
      // }
      //
      // Sometimes less is more.  How about simply: return lhs.get() == rhs.get();
      // 
      return 0;
    }
    Last edited by phil++; 11-20-2011 at 01:29 AM.

  2. #2
    benoit's Avatar
    benoit is online now ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    Hi Phil,

    Thanks for the bug report. The documentation is wrong actually. It is the intended behavior for the IceUtil::Handle comparison operators to rely on the class comparison operators. It's the responsibility of the class to decide how the handle comparison behaves (for example, if your class inherits from Ice::LocalObject it will use address comparison by default).

    Cheers,
    Benoit.

  3. #3
    phil++ is offline Registered User
    Name: Philip Kovacs
    Organization: University of Pennsylvania
    Project: Ice Storm Evaluation
    Join Date
    Jul 2007
    Posts
    24
    Benoit,

    OK. You might place special emphasis in the documentation on this point as it deviates from other implementations of smart pointers (c++0x, tr1, boost, boost tr1) -- all of them have pointer comparison semantics for operator==, operator!=, etc. Anyone using IceUtil::Handle as a substitute smart pointer can get thrown by this unusual twist.

    Phil
    Last edited by phil++; 11-22-2011 at 02:51 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 11-05-2007, 11:35 AM
  2. Comparing ICE performance with Hessian/Burlap
    By shantanu_k06 in forum Comments
    Replies: 1
    Last Post: 09-06-2007, 06:06 AM
  3. Replies: 1
    Last Post: 04-13-2007, 09:49 PM
  4. Pointers and Proxies
    By MikeGerdes in forum Help Center
    Replies: 5
    Last Post: 02-07-2007, 10:56 AM
  5. Problem with smart pointers
    By galbe in forum Help Center
    Replies: 2
    Last Post: 06-22-2004, 05:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •