You're right. I'd already considered this, and so decided that the "nulling" ctor overload would take an address of the handle. This has the big advantage that there can be no such confusion, and the small disadvantage that you can't "inline" the allocation function invocation with the scoped_handle ctor. ;-)
 
This should all work ticketyboo (LOL, don't you love the silly English and our daft expressions!). Just give me a few days to get over the last book push.
 
BigBoy
 
"Adi Shavit" <adish@gentech.co.il> wrote in message news:epsgtf$hve$1@digitaldaemon.com...

Seems like a hasty implementation on my part. I think the better solution is
to ensure that the external resource handle is "null'd". I worked it out
this morning (on my bike <g>), and have just to find a time to implement it.
Basically, I'll add a union that holds a "H h" and a "H* ph". The
scoped_handle will hold onto an instance of that, and a marker to say which
is viable. The function translators will know which member to use anyway
(translate() will use the h member; translate_indirect will use the ph
member).
  
Hmmm..
That'll work and, indeed, fix the problem.

However, I am concerned (from your point of view) that this would make 2 scoped_handle classes, with 2 subtly different behaviors.

Ideally the union should (impossibly?) detect if the class was constructed with an externally held handle e.g.

  FILE                             *file = ::fopen("file.ext", "r");
  // ...
  {
     ::stlsoft::scoped_handle<FILE*>  h2(file, ::fclose);
     // ...
  }
  // ...
or used with the internally held handle e.g.

    ::stlsoft::scoped_handle<int> h1(::open("file.ext"), ::close);


What would happen if I used an indirect function, with a reference to a temporary?
Can this happen?
Can the scope of the scoped_handle<> exceed the scope of the given temporary ?

Something like this:

// MyClass ctor
MyClass():
    myScopedHandle(makeHandle(), ::releaseAndReset) // init
myScopedHandle handle with indirect function
{}

Can this happen?
makeHandle() will generate a temp handle, and myScopedHandle will hold a reference to it. When the ctor goes out of scope, what happens to the temp reference? (I'm not so clear about temp rules at the moment).
In this case, it seems that a copy need to be made, not a reference.

Confused,
Adi