moving from c++ to D is easy?

Namespace via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 12 15:45:48 PDT 2015


On Thursday, 12 March 2015 at 21:41:07 UTC, Ali Çehreli wrote:
> On 03/12/2015 01:19 PM, Namespace wrote:
>
> > On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote:
> >> On 03/12/2015 06:01 AM, ayush wrote:
> >>
> >> > Is D a lot like c++ ?
> >>
> >> I came to D from C++. I remember the following being notable
> differences:
> >>
> >> - In D, classes have reference semantics. I quickly realized
> that this
> >> is not an issue because so many of my C++ types were
> >> hand-reference-typified :p by this idiom, almost everywhere:
> >>
> >> class C { /* ... */ };
> >> typedef boost::shared_ptr<C> CPtr;
> >> void foo(CPtr c);
> >
> > This is a common mistake. In 99 percent of cases you want to
> use a
> > std::unique_ptr.
>
> Agreed. Here is an excerpt from a comment from one of our 
> header files:
>
> "We could not use boost::unique_ptr because the version of the 
> Boost library that we currently use does not include it."
>
> > std::shared_ptr is rarely common and often an indication of an
> > error in design. In general, there is exactly one owner only.
>
> Of course. We had definitions like the following as well, where 
> the C objects are stored in:
>
> typedef vector<CPtr> MyCs;
>
> > But I think you know that already. :)
>
> I think so. :) Maybe we should pass weak_ptrs around instead of 
> shared_ptr.
You could also pass raw pointers around. Since they have no owner 
it's fine. Or references.
> Anyway... That's old code and this is a D newsgroup.
>
> Ali
Agreed.


More information about the Digitalmars-d-learn mailing list