<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<div class="moz-text-plain" wrap="true" graphical-quote="true"
style="font-family: -moz-fixed; font-size: 13px;" lang="x-western">
<pre wrap="">Hi,
Hope this is the right place to post this. I was just wondering if
there's a reason why itk::SmartPointer was designed so as not to allow e.g.
itk::Image<int,3>::Pointer image;
const itk::Image<int,3>::ConstPointer& cimage = image;
?
The equivalent with boost::shared_ptr is allowed, e.g.
boost::shared_ptr<int> p(new int);
const boost::shared_ptr<const int>& cp = p;
This doesn't seem like a major problem, until you start writing
functions taking const itk::Image<...>::ConstPointer& parameters - at
which point it won't let you pass a normal Pointer in without explicitly
constructing a ConstPointer from it. Now the types are often quite long,
and it's annoying to have to add extra typedefs in the calling code just
for that purpose. Duplicating the functions with const
itk::Image<...>::Pointer& parameters doesn't work either, because you
get a combinatorial explosion when you have multiple such parameters.
For instance, with 3 parameters, you have to create functions with
combinations:
const Pointer&, const Pointer&, const Pointer&
const Pointer&, const Pointer&, const constPointer&
const Pointer&, const ConstPointer& const Pointer&
// more here
const ConstPointer&, const ConstPointer& const ConstPointer&
This seems like an unproductive way to spend one's time, to say the
least. The only other "reasonable" alternative I've managed to come up
with that doesn't either (a) clutter up the call site or (b) cause the
combinatorial explosion just outlined, is to just use the non-const
Pointers everywhere and abandon the idea of making the code
const-correct. But that seems defeatist to me <span
class="moz-smiley-s1"><span> :) </span></span> Please could you tell
me if there's something I'm missing? (And if so, what?)
Cheers,
Stuart
</pre>
</div>
</body>
</html>