<div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Andras, </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">One thing that may be relevant is this link: <a href="http://marc.info/?l=vtk-developers&m=126471789304821">http://marc.info/?l=vtk-developers&m=126471789304821</a></div><div class="gmail_default">Note: I think<br><span style="font-size:16px;color:rgb(0,0,0);font-family:"courier new",courier,monospace;font-weight:600">vtkSmartPointer<vtkPolyData> output;</span></div><div class="gmail_default">should be:<br><span style="font-family:"courier new",courier,monospace;color:rgb(0,0,0);font-size:16px;font-weight:600">vtkSmartPointer<vtkPolyData> readerOutput;</span></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I think the example there nicely demonstrates the difference between vtkNew and vtkSmartPointer.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Maybe something like this could be incorporated into the testing in <a href="https://gitlab.kitware.com/vtk/vtk/merge_requests/2961">https://gitlab.kitware.com/vtk/vtk/merge_requests/2961</a></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Regards</div><div class="gmail_default" style="font-size:small">   Andrew</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 25, 2017 at 6:07 AM, Andras Lasso <span dir="ltr"><<a href="mailto:lasso@queensu.ca" target="_blank">lasso@queensu.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It is great that you've brought this up! There is a very important, fundamental difference. Unlike std::shared_ptr or QSharedPointer, VTK smart pointer does NOT need clear distinction between the pointer object and the raw pointer it holds, because reference counting is implemented in the managed object itself.<br>
<br>
See in std::shared_ptr documentation: "Constructing a new shared_ptr using the raw underlying pointer owned by another shared_ptr leads to undefined behavior." (<a href="http://en.cppreference.com/w/cpp/memory/shared_ptr" rel="noreferrer" target="_blank">http://en.cppreference.com/w/<wbr>cpp/memory/shared_ptr</a>)<br>
<br>
In VTK, if you assign a vtkSmartPointer to another, internally the raw pointer is retrieved and used (Common/Core/vtkSmartPointer.<wbr>h):<br>
<br>
  vtkSmartPointer& operator=(const vtkSmartPointer<U>& r)<br>
  {<br>
    this->vtkSmartPointerBase::<wbr>operator=(CheckType(r.<wbr>GetPointer()));<br>
    return *this;<br>
  }<br>
<br>
VTK smart pointers work differently from STL and Qt, so it is reasonable to use a different API that reflects this difference. As VTK allows safe use of a simpler API, we should take advantage of that and use it.<br>
<br>
Andras<br>
<span class=""><br>
-----Original Message-----<br>
From: Elvis Stansvik [mailto:<a href="mailto:elvis.stansvik@orexplore.com">elvis.stansvik@<wbr>orexplore.com</a>]<br>
Sent: Saturday, June 24, 2017 12:36 PM<br>
To: Andras Lasso <<a href="mailto:lasso@queensu.ca">lasso@queensu.ca</a>><br>
Cc: David Lonie <<a href="mailto:david.lonie@kitware.com">david.lonie@kitware.com</a>>; Shawn Waldon <<a href="mailto:shawn.waldon@kitware.com">shawn.waldon@kitware.com</a>>; VTK Developers <<a href="mailto:vtk-developers@vtk.org">vtk-developers@vtk.org</a>>; Andrew Maclean <<a href="mailto:andrew.amaclean@gmail.com">andrew.amaclean@gmail.com</a>><br>
Subject: Re: [vtk-developers] vtk-developers Digest, Vol 158, Issue 21<br>
<br>
</span><span class="">2017-06-24 15:53 GMT+02:00 Andras Lasso <<a href="mailto:lasso@queensu.ca">lasso@queensu.ca</a>>:<br>
> Based on the feedbacks and the poll results (11 out of 13 votes for<br>
> changing current behavior), it seems there is a strong consensus for adding implicit conversion.<br>
<br>
I was away and missed the vote, but frankly I'm not sure what I would have voted.<br>
<br>
Looking at what others do, I guess vtkNew is comparable to std::unique_ptr or Qt's QScopedPointer, none of which do implicit conversion to the underlying pointer (they have .get() and .data() respectively). So VTK would be rather unique in doing that for a scoped smart pointer I think..<br>
<br>
Elvis<br>
<br>
><br>
> Here is a pull request with the change:<br>
</span>> <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitla" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>https%3A%2F%2Fgitla</a><br>
> <a href="http://b.kitware.com" rel="noreferrer" target="_blank">b.kitware.com</a>%2Fvtk%2Fvtk%<wbr>2Fmerge_requests%2F2961&data=<wbr>02%7C01%7Classo<br>
> %<a href="http://40queensu.ca" rel="noreferrer" target="_blank">40queensu.ca</a>%<wbr>7C14c5314b70e443f5be4908d4bb1f<wbr>0bf4%7Cd61ecb3b38b142d582c<br>
> 4efb2838b925c%7C1%7C0%<wbr>7C636339189405346369&sdata=<wbr>2Jv0QS1qlRUgSJvN%2BO8<br>
> 0pXOt89kKC0NP7iXXRr2mg30%3D&<wbr>reserved=0<br>
<div><div class="h5">><br>
> Andras<br>
><br>
> -----Original Message-----<br>
> From: David Lonie [mailto:<a href="mailto:david.lonie@kitware.com">david.lonie@kitware.<wbr>com</a>]<br>
> Sent: Friday, June 23, 2017 1:51 PM<br>
> To: Shawn Waldon <<a href="mailto:shawn.waldon@kitware.com">shawn.waldon@kitware.com</a>><br>
> Cc: Andras Lasso <<a href="mailto:lasso@queensu.ca">lasso@queensu.ca</a>>; VTK Developers<br>
> <<a href="mailto:vtk-developers@vtk.org">vtk-developers@vtk.org</a>>; Andrew Maclean <<a href="mailto:andrew.amaclean@gmail.com">andrew.amaclean@gmail.com</a>><br>
> Subject: Re: [vtk-developers] vtk-developers Digest, Vol 158, Issue 21<br>
><br>
> I'm so glad someone brought this up =)<br>
><br>
> On Fri, Jun 23, 2017 at 10:52 AM, Shawn Waldon <<a href="mailto:shawn.waldon@kitware.com">shawn.waldon@kitware.com</a>> wrote:<br>
>>  But realistically what it does is<br>
>> discourage use of vtkNew.  Most people I talk to say "I would use<br>
>> vtkNew but then I have to clutter up my code with GetPointer calls<br>
>> everywhere" and so they still use vtkSmartPointer.  Honestly I only<br>
>> used it to clean up declarations (the problem discussed earlier in<br>
>> this thread).  Now that we can use auto in VTK, I'll probably go back<br>
>> to vtkSmartPointer since it is easier to use.<br>
><br>
> I agree with Shawn. It's an unnecessary hassle to require the Get() to be used.<br>
><br>
> I suppose I'm just a fan of the design philosophy for C++ about "don't prevent developers from shooting themselves in the foot." If a dev doesn't understand VTK's reference counting well enough to understand that you can't simply return a vtkNew'd pointer without increfing it first, they're going to have far greater problems using the toolkit than this.<br>
><br>
> Besides, you could easily (and safely) return a vtkNew'd pointer from a function:<br>
><br>
> vtkObject* function()<br>
> {<br>
>   vtkNew<vtkObject> obj;<br>
>   obj->Register();<br>
>   return obj; // If we had implicit conversions, anyway }<br>
><br>
> Making the class unwieldly simply so that people don't need to learn how reference counts work is a poor justification IMO.<br>
><br>
> Just my 2c,<br>
> Dave<br>
> ______________________________<wbr>_________________<br>
> Powered by<br>
</div></div>> <a href="https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&dat" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>www.kitware.com&dat</a><br>
> a=02%7C01%7Classo%<a href="http://40queensu.ca" rel="noreferrer" target="_blank">40queensu.ca</a><wbr>%<wbr>7C14c5314b70e443f5be4908d4bb1f<wbr>0bf4%7Cd6<br>
> 1ecb3b38b142d582c4efb2838b925c<wbr>%7C1%7C0%7C636339189405346369&<wbr>sdata=EWly<br>
> 8qDaOVuCYOrDhoQ7SyY3glwTdlm1J1<wbr>nxY%2BBDO50%3D&reserved=0<br>
<span class="">><br>
> Visit other Kitware open-source projects at<br>
</span>> <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.ki" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>http%3A%2F%2Fwww.ki</a><br>
> <a href="http://tware.com" rel="noreferrer" target="_blank">tware.com</a>%2Fopensource%<wbr>2Fopensource.html&data=02%<wbr>7C01%7Classo%40queens<br>
> <a href="http://u.ca" rel="noreferrer" target="_blank">u.ca</a>%<wbr>7C14c5314b70e443f5be4908d4bb1f<wbr>0bf4%<wbr>7Cd61ecb3b38b142d582c4efb2838b<br>
> 925c%7C1%7C0%<wbr>7C636339189405346369&sdata=<wbr>v7U9kMfdmgpWZ6WYn1nyPTuUHWzn4s<br>
> J6XvYEJdpw50I%3D&reserved=0<br>
<span class="">><br>
> Search the list archives at:<br>
</span>> <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkma" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>http%3A%2F%2Fmarkma</a><br>
> <a href="http://il.org" rel="noreferrer" target="_blank">il.org</a>%2Fsearch%2F%3Fq%3Dvtk-<wbr>developers&data=02%7C01%<wbr>7Classo%40queensu<br>
> .ca%<wbr>7C14c5314b70e443f5be4908d4bb1f<wbr>0bf4%<wbr>7Cd61ecb3b38b142d582c4efb2838b<wbr>9<br>
> 25c%7C1%7C0%<wbr>7C636339189405346369&sdata=<wbr>otfBLrSAA5d7a9u6mrb56%2ByrIVM%<wbr>2<br>
> Bl3f%2BZNQpwOvqgO0%3D&<wbr>reserved=0<br>
<span class="">><br>
> Follow this link to subscribe/unsubscribe:<br>
</span>> <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpublic" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>http%3A%2F%2Fpublic</a><br>
> .<a href="http://kitware.com" rel="noreferrer" target="_blank">kitware.com</a>%2Fmailman%<wbr>2Flistinfo%2Fvtk-developers&<wbr>data=02%7C01%7Classo%<a href="http://40queensu.ca" rel="noreferrer" target="_blank">40queensu<wbr>.ca</a>%<wbr>7C14c5314b70e443f5be4908d4bb1f<wbr>0bf4%<wbr>7Cd61ecb3b38b142d582c4efb2838b<wbr>925c%7C1%7C0%<wbr>7C636339189405346369&sdata=<wbr>whCFetn1LnPSRi0CZ%<wbr>2BD1aGlMHqdv5vSgzkRdcuLw8qI%<wbr>3D&reserved=0<br>
><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">___________________________________________<br>Andrew J. P. Maclean<br><br>___________________________________________</div>
</div>