The Artima Developer Community
Sponsored Link

Artima Developer Spotlight Forum
Overview of the New C++ (C++0x)

40 replies on 3 pages. Most recent reply: May 4, 2010 2:57 AM by Achilleas Margaritis

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 40 replies on 3 pages [ « | 1 2 3 ]
Chris Bruner

Posts: 6
Nickname: iplayfast
Registered: Oct, 2007

Re: Overview of the New C++ (C++0x) Posted: Apr 12, 2010 8:17 AM
Reply to this message Reply
Advertisement
> For instance, templates that you mention as a "nuisance"
> are the essential tool for making type-safe containers.
> Using something like std::vector is much easier and less
> error-prone than C realloc(). In fact, STL is still the
> best container/algorithm library that I am aware of. .NET
> Power Collections are the closest thing to STL, but very
> few people use it. I've heard of JAL - which is an attempt
> to port STL to Java, but have no idea if it is any good.

Just a few months ago I added a little stack class using the stl class into a function. When porting to another OS, guess what broke. I ended up just re-writing it because it was easier then trying to figure out where the stl went wrong. Sorry this is more then a nuisance to me. It is an unportable mess.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: Overview of the New C++ (C++0x) Posted: Apr 12, 2010 10:12 AM
Reply to this message Reply
> added a little stack class using
> the stl class into a function.

Not sure what that means.

Anyway, I can reply with another anecdote: at my previous job we were heavily using STL to write code that compiled on Windows (with MS compiler) and Linux (GNU compiler) and everything worked like a charm.

Max Lybbert

Posts: 314
Nickname: mlybbert
Registered: Apr, 2005

Re: Overview of the New C++ (C++0x) Posted: Apr 12, 2010 11:01 AM
Reply to this message Reply
> Just a few months ago I added a little stack class using
> the stl class into a function. When porting to another OS,
> guess what broke. I ended up just re-writing it because it
> was easier then trying to figure out where the stl went
> wrong. Sorry this is more then a nuisance to me. It is an
> unportable mess.

I realize that (1) you may not have the original source code, (2) you may not be able to share it, and (3) this isn't something that you're actively working on because you've already solved the problem. But I have to admit I'm interested in seeing this problem code.

I haven't had a problem with porting applications that use the STL in several years, unless the target system had a bug in the STL implementation (I'm thinking of an old AIX box we had in the computer science department I had to use back in school; it was old when I was there, and that was a while ago). Bugs in the STL implementation are becoming more rare.

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: Overview of the New C++ (C++0x) Posted: Apr 12, 2010 11:10 AM
Reply to this message Reply
> a while ago). Bugs in the STL implementation are becoming
> more rare.
It was all but unusable with the MS compiler for many years. Which is why it isn't used in any of our remaining C++ code.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: Overview of the New C++ (C++0x) Posted: Apr 12, 2010 11:29 AM
Reply to this message Reply
> It was all but unusable with the MS compiler for many
> years.

Even for the pre-standard MS compilers there were alternative STL implementations available. We used STLPort with VC 6.0. However, that hasn't been an issue since VC++ 2002; MS compilers come with very good Dinkumware libraries - the only complaint I had with versions VC 2005 and VC 2008 is that STL was checked by default even in release builds, but that was reverted in the newly released VC 2010.

As for GNU, their libraries were pretty bad before the 3.0 version, but that's ancient history now. Current GNU libraries are very good as well.

Jonathan Wakely

Posts: 14
Nickname: jwakely
Registered: Jul, 2009

Re: Overview of the New C++ (C++0x) Posted: Apr 15, 2010 4:19 AM
Reply to this message Reply
>
> AFAIK, this is not fixed in C++0x. However, this problem
> can be avoided in current C++. There are two obvious
> solutions that I can think of. The first is to not create
> temporary std::auto_ptrs:
>
>
> std::auto_ptr<Bar> bar(new Bar());
> std::auto_ptr<Baz> baz(new Baz());
> foo(bar.get(), baz.get());
> 


auto_ptr is deprecated in C++1x, unique_ptr is superior in every way. C++1x also provides a make_shared function to solve the problem of allocating two objects in function arguments:

foo( std::make_shared<Bar>(), std::make_shared<Baz>() );


make_shared<T>(args...) returns shared_ptr<T>(new T(args...))

Using this prevents leaks if either allocation throws, because the object is safely managed by a shared_ptr as soon as its created

Jonathan Wakely

Posts: 14
Nickname: jwakely
Registered: Jul, 2009

Re: Overview of the New C++ (C++0x) Posted: Apr 15, 2010 4:38 AM
Reply to this message Reply
you can of course solve the problem the same way today

template<typename T>
std::auto_ptr<T>
make_auto_ptr()
{
  return std:auto_ptr<T>(new T());
}


A C++0x version is better because it an forward any number of arguments, preserving their lvalue-ness or rvalue-ness

template<typename T, typename... Args>
std::auto_ptr<T>
make_auto_ptr(Args&&... args)
{
  return std:auto_ptr<T>(new T(args...));
}

Steve Simmons

Posts: 5
Nickname: scs
Registered: Sep, 2007

Re: Overview of the New C++ (C++0x) Posted: Apr 16, 2010 11:15 AM
Reply to this message Reply
36 posts, near zero information about the class and only slightly more about the new C++. What is this, Slashdot?

Larry Brunelle

Posts: 3
Nickname: lab
Registered: Aug, 2006

Re: Overview of the New C++ (C++0x) Posted: Apr 16, 2010 11:59 AM
Reply to this message Reply
> 36 posts, near zero information about the class and only
> slightly more about the new C++. What is this, Slashdot?

This seems a reasonable observation.

FWIW, I am a purchaser of the presentation materials for
personal use (for about $30) and have reviewed most of
the package. I report the following.
a) For my money, it was money well spent and worth every
penny, with much useful information.
b) It is a set of presentation slides, annotated, not a
book. It therefore suffers somewhat from not having
the prose that the presenter would speak. Since it
doesn't appear that it's yet time for Scott to write
another book, I see this as a pretty good way to get
an idea of what we're in for when the greater bulk of
features are widely supported in mainstream compilers.
c) Far as I can tell from the list of features so far
supported in GCC 4.x, we won't see full support in the
mainstream compilers in a wild hurry. The makeover of
the Standard is HUGE; I am in awe.

Fortunately (from my point of view), I won't be compelled
to use every new feature. :-) Seriously, I see as a
possible downside some confusion about newly-accepted
syntax, since some developers may be anxious to use the
same, while others will see their new work and have to
delve into the new Standard (or some reference) to
understand what they're looking at.

I **will** be looking for some work from Scott (in due
course) showing how to use these new capabilities
Effectively. Myself, I have a bias against using language
features unless I can see how they buy me something I want;
call me conservative.

Bruce Fancher

Posts: 4
Nickname: iterative
Registered: Mar, 2007

Re: Overview of the New C++ (C++0x) Posted: Apr 26, 2010 10:04 AM
Reply to this message Reply
C++ is a great language for people who enjoy doing things in the most complicated and difficult way possible. Fortunately, when the rest of us need to use a "C with classes," there's Objective-C.

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: Overview of the New C++ (C++0x) Posted: May 4, 2010 2:57 AM
Reply to this message Reply
> C++ is a great language for people who enjoy doing things
> in the most complicated and difficult way possible.
> Fortunately, when the rest of us need to use a "C with
> h classes," there's Objective-C.

What exactly do you find more difficult and more complicated in C++ than in other languages?

Flat View: This topic has 40 replies on 3 pages [ « | 1  2  3 ]
Topic: Developer Productivity in FlashBuilder 4 Previous Topic   Next Topic Topic: Rickard Öberg: Contexts Are the New Objects

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use