File size

File size

File size

File size

File size

109.6 MB

As promised, the great Stephan T. Lavavej is back! Tens of thousands of you have watched STL's (those are his initials, so that's what we call him) introductory series on the STL, or Standard Template Library. If you haven't, you should. This series, Advanced STL, covers the gory details of the STL's implementation -> you will therefore need to be versed in the basics of STL, competent in C++ (of course), and be able to pay attention! Stephan is a great teacher and we are so happy to have him on Channel 9—the only place you'll find this level of technical detail regarding the internals of the STL. There are no books. There are no websites. This is Stephan taking us into what is uncharted territory for most, even those with a more advanced STL skill set.

In the second part of this n-part series, Stephan digs into implementation strategies for various STL algorithms and opens the hood to look at some of the machinery inside the STL employing the goodness of template meta-programming and type traits. You'll also learn about some C++0x features that are used inside STL.

As you continue to learn about the beauty and the weirdness inside the STL, you should take Stephan's wisdom to heart and see if you can implement some of the patterns he shares with you in your own code. And you should, of course, take his advice about what NOT to do in your native compositions.

Would someone please explain why Microsoft insist on calling the C++ Standard Library the STL? If it is standard then surely every implementation would call it so and also the standard committee. #pet C++ hate number 1024

Sure. In fact, we (Microsoft or anybody else for that matter....) don't do this... I'm not sure how you've arrived at this conclusion. STL = Standard Template Library. These libraries share many things in common, but they are not the same things.

Sure. In fact, we (Microsoft or anybody else for that matter....) don't do this... I'm not sure how you've arrived at this conclusion. STL = Standard Template Library. These libraries share many things in common, but they are not the same things.

Charles,I am sorry, maybe it is me being dumb. The videos are about "STL" which is what exactly? Lets take std::copy for example that is from the C++ Standard Library not something called the Standard Template Library. Where does the standard in STL come from and are these videos really referring to the SGI implementation called STL? I do not recall the standard making any mention of a STL.

@Liam: You are not being dumb.... These videos are about the Dinkumware implementation of STL (So, the STL implementation that ships with VC++). There are many different implementations of the STL, all based on the language standard.

Hey Charles, wich version of video you use on smoothstream? even when i go fullscreen it looks aliased, like the Medium Quality WMV (I have a 10Mbps line, but for international link It sometimes drop to 1Mbps, depending the destination server).

@felix9 Thank you for doing some research but I think you will find the only piece of literature worth quoting about C++ is the standard itself. I did acknowledge the origins of the name "STL" in my second post and queried if we were talking about the same dead implementation and it seems we are.

@felix9 Thank you for doing some research but I think you will find the only piece of literature worth quoting about C++ is the standard itself. I did acknowledge the origins of the name "STL" in my second post and queried if we were talking about the same dead implementation and it seems we are.

if read carefully you can see that all of my quotes are talking about the part of the actual standard library, the 'dead implementation' is only mentioned when people want to explain 'why' they are using this term this way.

I dont think the standard itself is 'the only piece of literature worth quoting', surely you are getting way too formal here. this term is so widely used in the industry and academia, everybody understand it and take it naturally, if you want to talk that way then good for you, but we are living people and we dont need to always speak the 'iso standard' language.

@felix9 Thank you for doing some research but I think you will find the only piece of literature worth quoting about C++ is the standard itself. I did acknowledge the origins of the name "STL" in my second post and queried if we were talking about the same dead implementation and it seems we are.

Felix9 is correct.

Here's another example: Stroustrup mentions in his book: "Every algorithm works with every container without the use of conversions. This framework, conventionally called the STL [Stepanov,1994], is extensible in the sense that users can easily provide containers and algorithms in addtion to the ones provided as part of the standard and have these work directly with the standard containers and algorithms" (section 3.10 from The C++ Programming Language 3rd ed.). In sections 16.2 and 16.2.3, for example, he mentions the algorithms and containers portion of the standard library are often called the STL or STL framework.

@Charles:Yes, now that we know the C++ Standard Library or its collection of libraries are not called STL can we stop calling it so? I have had this conversation with many people and noone seems to be able to give me a good explaination why they call it so, other than "well he called it that". I also wonder when STL became the Standard Template Library."In 1992, when the project was formed, there were eight people in it. Gradually the group diminished, eventually becoming two people, me and Meng Lee. While Meng was new to the area---she was doing compilers for most of her professional life---she accepted the overall vision of generic programming research, and believed that it could lead to changing software development at the point when very few people shared this belief. I do not think that I would be able to build STL without her help. (After all, STL stands for Stepanov and Lee...) "http://www.sgi.com/tech/stl/drdobbs-interview.html

@Charles:Yes, now that we know the C++ Standard Library or its collection of libraries are not called STL can we stop calling it so? I have had this conversation with many people and noone seems to be able to give me a good explaination why they call it so, other than "well he called it that". I also wonder when STL became the Standard Template Library."In 1992, when the project was formed, there were eight people in it. Gradually the group diminished, eventually becoming two people, me and Meng Lee. While Meng was new to the area---she was doing compilers for most of her professional life---she accepted the overall vision of generic programming research, and believed that it could lead to changing software development at the point when very few people shared this belief. I do not think that I would be able to build STL without her help. (After all, STL stands for Stepanov and Lee...) "http://www.sgi.com/tech/stl/drdobbs-interview.html

Well, regardless of whether you agree or disagree with the usage of STL, Charles is right. We should return the focus on the content of the video.

My point is that pointer arithmetic is completely unnecessary here. Instead of _Count, we could calculate _Bytes. I slightly misspoke - I should have said char * instead of void *.

Liam: Along with many other people, I use "STL" to refer to "the subset of the C++ Standard Library that was derived from, or was designed in imitation of, Stepanov's original design". Therefore, vector and sort() are clearly parts of the STL. So are copy_if() and shared_ptr, even though they're new to C++0x. std::string is a borderline case. iostreams are clearly *not* part of the STL - they follow radically different design principles.

There are many useful terms that the Standard doesn't mention. Did you know that SFINAE (Substitution Failure Is Not An Error) is never mentioned in the Standard, despite being covered by several important paragraphs? And this is a term that the Standardization Committee's members use freely among themselves.

Some people, through metonymy, refer to the whole C++ Standard Library as the STL, but I consider such usage to be misleading. I've probably been lazy and guilty of it a few times, but I try not to be.

If you don't want to say "STL", you don't have to, but the term isn't confusing so there's no point in complaining when other people use it.

The _Advance function for bidirectional_iterator_tag has this code: for (; 0 < _Off; --_Off) ++_Where; for (; _Off < 0; ++_Off) --_Where;That's a little disappointing considering that this way saves a branch when the parameter is positive, which should be the common case: if (_Off > 0) { do { ++_Where; --_Off; } while (_Offset > 0); } else { for (; _Off < 0; ++_Off) --_Where; }Another branch could be saved by an overload that takes an unsigned offset, since in that case the parameter does not have to be checked to see if it is negative. Though perhaps having an unsigned overload would violate the standard.The only saving grace I can come up with is if the compiler can always perform these two optimizations on its own.

@STDThe problem is that these subsections already have names given by the standard yet people seem to ignore this, where does it stop? You stated that you feel std::cup_cakes is part of JimJams yet it comes from Boost, why not refer to it as the Boost Library; hell why stop there why not rename the language. I think Flapjack is as good as any other name.I personally find it lazy and uninformed that some people wrongly refer to sections of the Standard Library as PANCAKES, however what I find worse than this is somebody who is informed and still calls it by an incorrect name. Lets go the whole hog and refer to it as Stepanov and Lee.At this point I realise that I am not going to change anyones mind here on this topic and would just like to say I do enjoy the videos Paul.Yours, the Earth is flatGalileo Galilei

Discussing terminology is often futile. For example, most C++ programmers say that "a pointer is a variable that stores an address", which is completely wrong. Should I go around correcting these people all the time? No. It is common vocabulary that you simply cannot eradicate anymore. As long as everybody understands what you're talking about, there's no problem. We all know that, at least in the context of these videos, STL means "the part of the standard library that is based upon the ideas of containers, algorithms and iterators".

(In case you're wondering, despite its name, the unary prefix operator & does not yield an address, but a pointer. The correct way to say it would be "a pointer variable is a variable that stores a pointer", which is quite obvious, so you won't hear it uttered very often.)

"For example, most C++ programmers say that "a pointer is a variable that stores an address", which is completely wrong. Should I go around correcting these people all the time? No""The result of the unary & operator is a pointer to its operand. The operand shall be an lvalue or a qualified- id. In the first case, if the type of the expression is “T,” the type of the result is “pointer to T.” In particular, the address of an object of type “cv T” is “pointer to cv T,” with the same cv-qualifiers." "The address of an object of incomplete type can be taken, but if the complete type of that object is a class type that declares operator&() as a member function, then the behavior is undefined (and no diagnostic is required).The operand of & shall not be a bit-field."

Are you sure that the optimized memcmp() version is called for std::equal in release builds?

With VS2008 SP1, I tried with a simple modification to <xutility> header, adding a printf() for logging purposes before ::memcmp() calls, and the printf() message is *not* printed in release builds with _SECURE_SCL=0.

@LiamYour last post rather takes the argument out from under you, don't you think? You posit that there should be a slippery slope where we use all manner of different, arbitrary names for different parts of the C++ Standard Library (JimJams, Flapjacks, Pancakes, etc), and yet that simply hasn't happened.

In fact, the names have been rather stable, don't you think? I mean, isn't that your real complaint? A library was created, then adopted by the standards committee and the general populous kept using the same name for it. Oh the horror!

We definitely need to change the name of every library once it gets popular or standardized, otherwise people will keep trolling awesome videos that peeking under the covers of these libraries to complain that the library today is not the same as the library 15 years ago.

(Hint, in the real world, things can have many names, and people deal with it just fine.)

Very cool video, not just because we have similar wallpapers. :DJust one small question, although this is more a optimization question, and not STL question. Have you ever considered using instruction level parralelism to improve performance on random access structures. For example if you are doing somthing like sum+=v[i]you could start from the start and start from the middle at the same time. Because CPUs can handle more than one instruction at the time it could be faster for some operations. Although you can have some "problems"because you must account for odd(not even) sized structures. And you would have to for example have sum1, sum 2, and sum would be sum1+sum2.Don't get me wrong, I know that there is no sum in STL, it was just an example. If user writes a simple lambda that does sumation is there any chance that you can tell the compiler that that vector is huge(aka please if you can optimize this on vectors). If it isn't clear what I'm saying:// STL even.cpp : Defines the entry point for the console application.//#include #include #include #include #include using namespace std;int main(){ vector v (8*1024*1024+1); iota(v.begin(),v.end(),0); long long sum=0; clock_t start, finish; start = clock(); //* for_each(v.begin(),v.end(),[&sum] (int& x){ sum+=x; }); //*/ /* long long sum1=0; long long sum2=0; auto half=v.size()/2; auto j=half; for (auto i=0; iI can notice big diff in execution time(i compiled 2 times - first time with lambda part, second time with the sum1, sum2 part, and renamed the .exe):...\nx01\Documents\Visual Studio 2010\Projects\STL even\Release>"STL even_nomal.exe"3518437628313629//nomal should be normal -this is the lambda version...\nx01\Documents\Visual Studio 2010\Projects\STL even\Release>"STL even_optim.exe"3518437628313618//this is the sum1, sum2 versionP.S. sorry for my bad English and for my bad cpp. :D

Interestingly, as I increase the distance, the performance gap widens before closing again (as expected): 3.4% for 1, 5.3% for 2, 5.6% for 3, 3.5% for 4, 2.5% for 5.

That's still pretty small (and it's only for bidi, not weaker or stronger iterators), but I'll think about it.

C64> Are you sure that the optimized memcmp() version is called for std::equal in release builds?

Yes (for char, signed char, and unsigned char, as I mentioned). I just verified that by debugging VC10 RTM.

We rewrote the STL between VC9 and VC10 - I'd have to set up a VM to see what VC9 did.

Ivan> Have you ever considered using instruction level parralelism to improve performance on random access structures.

It's hard to do that sort of thing unobservably - i.e. without damaging correctness or performance in some scenarios. In the STL, we implement library optimizations only when they won't damage correctness anywhere, and they must be a strict performance improvement, or have minor negative effects in rare scenarios.

This sort of thing is better done by the user, possibly with a full-fledged parallel_for_each() (if you can break up the computation like that, you may as well use multiple cores).

Ivan> Don't get me wrong, I know that there is no sum in STL

Actually, there is: accumulate() in <numeric>. (It's one of the few algorithms hiding in <numeric> instead of <algorithm>.)

@STL:Interesting. I wouldn't be surprised if the % operation you use for the test is actually responsible for a significant part of the runtime. It should be less common for the argument to advance to be negative, and I wonder if MSVC++ is smart enough to usually remove the negative branch when it can't be taken statically. In that case your way may actually be better if the compiler is smart enough to remove the negative branch, but not smart enough to combine the first if and the do {...} while condition back into a single branch instruction. Since then you get the same number of dynamic branches but the code is larger. If you use an unsigned type for the argument (so then the compiler really really should be able to eliminate the negative loop) and the two implementations then behave identically in terms of size and speed then this probably isn't a concern and otherwise probably it is a concern.Thanks for the great video by the way.

Hey Charles, wich version of video you use on smoothstream? even when i go fullscreen it looks aliased, like the Medium Quality WMV (I have a 10Mbps line, but for international link It sometimes drop to 1Mbps, depending the destination server).

sorry for going OT, but I'm also seeing very poor quality in full-screen or zoomed browser. I have a fast connection, and I was able to stream the 'High Quality WMV' without dropping frames. It would be great if you could enable smooth-streaming for some of the higher bitrate streams.

Off-Topic: I like test my connection from time to time with the IIS Smooth Stream's test HD movie (Big Buck Bunny), it works perfect for all stream bands, what is awesome

On-Topic: Another great video, but I think this time have not much to comment, besides the partition code comments between @STL and @Bob, everything else is a nice use the type_traits and compiler branch on function overloads (sorry i forgot the term @STL use ). The only draw is thatforthose not yet fully accustomed to the wayin which variables are noted, is a bit confusing to track then on the source code. I'm sure thare are a add-in for VS that make a nice visual track on function call, that can help on the misson for starters (like me)

Instead of people diverge on the roots of worth the terns "Standard Templare Library" why not suggest next topics, like we did on previous video I still waiting anything about Allocators (yea for that off-topic SSE discussion )

I remember @STL says one of the few things that disgust him is when people is not paying attention

Good video. Interesting optimization of std::copy. I'm a bit jealous you get to do metaprogramming every day at your job. Its good though you did not edit out that part where you found that performance bug in the optimization of std::equal.. Sometimes its the bugs that are the most valuable to learning.One suggestion though for the IDE guys at MS.. as sseen in this video, when debugging and stepping into a function you often have to step into and out of a bunch of argument calls that you are not interested in. That gets a bit frustrating after a while.. especially if you then accidentally step out of the function you are interested in, and have to start all over again. It would be nice to be able to highlight the part of a statement that one is interested in, right click, and get to select "step into". Then you would not have to step into all those other parts of a statement you are not interested in. Thats cant be to hard too hard to implement, as you got all the logic there, all we need is a button.Thanks.

@STL:OK, my bad... but can you answer the question... I understand that optimizing sum in that way can be tricky if you have large negative and positive numbers ...sum1+ sum2 can give result 1729 while simple sum can overflow... but for example find() could start from the beggining and from the middle. Again I don't know how many comparisons can a CPU make in parallel, so it might be a failure. So again here is my baaaad code(checking if size is even or not is really hard (for my skill level), and I had little time to do this, but the point of this code is to ilustrate what i mean, not to be legit :D)

#include #include #include #include #include using namespace std;vector::iterator my_find(vector::iterator first, vector::iterator last, int element){ auto middle=first; auto dist=distance( first, last); advance(middle, dist/2); while (middle v (40*1000*1000+1); iota(v.begin(),v.end(),0); clock_t start, finish; int value=15*1000*1000; start = clock(); //* auto it=std::find(v.begin(),v.end(),value); //cout< P.S. I know that formatting will be lost, but you can c/p in something and auto format it.P.P.S because of advance() something like this can only work on RA it. And remember this code is broken, it's just to show what I mean.

petke> Its good though you did not edit out that part where you found that performance bug in the optimization of std::equal.. Sometimes its the bugs that are the most valuable to learning.

Yes, I thought that'd be interesting. The only time I've ever asked them to edit anything out is when I accidentally created two meow.cpp files, got stuck in the wrong one, and was confused why my source wasn't compiling when it was clearly correct. (Ordinarily I don't use the IDE, so the most trouble I can get into is opening two editors for the same file.)

Ivan> but can you answer the question...

I did. It's hard to do what you're describing in such a way that it *never* harms users. As the STL is a general purpose library for pure computation, it gets used by zillions of people in zillions of ways. This restricts what optimizations we can perform.

@piersh/new2STL: I'm not sure what's going on here. The idea behind Smooth Streaming is that we will deliver the highest quality stream that the SL player detects you're capable of handling given local network conditions.

I recommend that you simply watch the high bitrate WMV or MP4 if that works better for you. Since you both are on high speed networks, why not? In the meantime, I will ask the folks who have the answers regarding SS and high qulaity streaming (again, it's supposed to just work once your high speed network is detected....).

@STL:cool tnx, for the answer.my implementation was wrong on so many levels. Including the fact that second it starsts from the middle, and that is a wrong, because fucntion should return the FIRST occurence, not ANY. So I can say now that I'm unable to outoptimize your implementation. :D Good job. :D

(Off-topic) @Charles: Hi Charles, I decided to make a test: Wait some days and played the SmoothStream at a early morning. Result: The SmoothStream worked at hi-rez when I go to fullscreen. The 'problem' is the huge success of @STL videos that are making the bandwidth drop shared by all of his fans on the first days of launch :D

@STL: Something I would like to see in future Advanced STL lectures would be a discussion of allocator trickiness, especially if you do any EBO (Empty Base Optimization) trickery. You may also want to discuss any special list::splice nastiness.

One other thing I am curious about... do the internal functions that take iterator tags get inlined to the point that no stack space is consumed by the tag instance? Basically, is that function call completely free, or does it cost you 1 byte on the stack in various places?

Suggestion: Sometimes it helps to look at the Release-mode assembly output (i.e. assembly output after optimizations) to convince a programmer that template meta-programming is actually doing something useful. I know that this has helped me. Using /FAs (or [in the IDE] selecting "Assembly With Source Code (/FAs)" from the "Assembler Output" drop-down box in Configuration Properties \ C/C++ \ Output Files from a project's Property page), allows a programmer to see the fruits of their template-meta-programming labor.

If certain instructions in the assembly output are unfamiliar (like they are for me), then looking at the instruction set reference in combination with the assembly output can also be helpful:http://www.intel.com/products/processor/manuals/

Is it always better to use the erase/erase_ifs? Also when erasing everything? If so, how do you declare an overloaded erase function, that just takes the container and calls the erase_if helper with a predicate functor that always returns true (don't only use C++0x, so I can't use a lambda).

2. Is there a standard way of finding out if C++0x is enabled, so I could use this:

#ifndef C++0x // or whatever way
typedef NULL nullptr;
#endif

3. Is it possible, that VS11 can implement an option, e.g. Portability and Version?

Reason for Portability: VS is unarguably my favorite dev IDE, but sometimes it gives messages like (not sure of the exact wording) "use fopen_s for safe version of fopen", which is only MS specific (I realized after porting my code). So I'd rather have a warning/error when using code that is MS/Win specific.

Reason for Version: If the other machine dev env doesn't support C++0x, a warning/error would be good, not allowing those features (i.e. auto, lambdas etc.). I saw that some toolset version thing is available, but it says that VS2008 must be installed.

Thanks for the info, could be useful. But I also meant generally be able to throw a warning/error when using non-portable code. I thought, maybe STL would be in the position to see if something like that could be done. Also, MFC etc. should then throw an error, when it should be portable, and some other windows specific headers. That would make it very easy to port code.

I'll see to use those definitions in my code. So is inferring the compiler version simple? If so, I could do a specific one for VS, since I only use XCode on the "other side", that totally lacks C++0x support (LLVM or old GCC 4.2). I guess that won't come too soon either on the Mac side.

Thanks again!

@STL: Still wondering on my first question. myVector.clear(); as good as erase(myVector v) calling erase_if(v,MyTruePredicate);

@Deraynger: Some macro definitions for compilers here. For Visual Studio it is _MSC_VER and encodes the compiler version (1600 for VS10.0), for GNU have some problem, they have __GNUC__ separated for each major.minor.revision the suggestion is mix all in one __GNUC_VERSION__ (see the link).

Clang (one of LLVM compilers) are beginning to support c++0x but in an early stage yet.

- More C0x new features as many will change the way one will/should program; Perhaps beginning with the FAQ items Stroustrup didn't have time to write yet in his 0x FAQ.

- Maximizing portability. What is Microsoft doing to clearly delimitate C++ and C++/CLI in documentation, syntax, keywords etc? What is the best way to strictly limitate the use of code non-compliant with ISO C++?

Ben_Craig> Something I would like to see in future Advanced STL lectures would be a discussion of allocator trickiness, especially if you do any EBO (Empty Base Optimization) trickery.

In fact, we've recently worked on this. I'll see what I can do.

Ben_Craig> You may also want to discuss any special list::splice nastiness.

Splicing between lists with different allocators hurts my head - fortunately, our code handles it. I think this is too specific to be the subject of a video, though.

Ben_Craig> One other thing I am curious about... do the internal functions that take iterator tags get inlined to the point that no stack space is consumed by the tag instance? Basically, is that function call completely free, or does it cost you 1 byte on the stack in various places?

When inlined, this technique (tag structs for overload resolution) should be completely free, presenting absolutely no challenge whatsoever to the optimizer. When inlining doesn't occur, I believe that it has minor costs - but in that case the absence of inlining is a much bigger deal.

Burkholder> Outstanding video!Deraynger> Awesome video, as usual!

Thanks!

Deraynger> Is it always better to use the erase/erase_ifs?

Compared to what?

Deraynger> Also when erasing everything?

No. Use clear() - that tells a container to nuke itself from orbit as fast as possible.

Deraynger> Is there a standard way of finding out if C++0x is enabled, so I could use this:

That isn't the right question to ask, because C++0x consists of many features, compilers support different subsets, and those subsets are growing over time.

In general, you'll need compiler version queries.

Deraynger> So I'd rather have a warning/error when using code that is MS/Win specific.

We have warnings for some of our non-Standard Core Language extensions, e.g. the Evil Extension allowing temporaries to bind to modifiable lvalue references. But not for others (e.g. C++98/03 didn't contain long long, but according to my knowledge we don't warn about that). And we typically don't have such warnings for our libraries.

There's also the /Za switch, but please don't use that - it is buggy.

Deraynger> Reason for Version: If the other machine dev env doesn't support C++0x, a warning/error would be good, not allowing those features (i.e. auto, lambdas etc.).

You can submit suggestions to Connect.

new2STL> And for nullptr, you can infer the compiler version but you haven't a way to know if the compiler option -std=c++0x (in the case of gcc) is being used

Actually, GCC documents __GXX_EXPERIMENTAL_CXX0X__ for that purpose.

CedricM> More C0x new features as many will change the way one will/should program; Perhaps beginning with the FAQ items Stroustrup didn't have time to write yet in his 0x FAQ.

CedricM> Maximizing portability. What is Microsoft doing to clearly delimitate C++ and C++/CLI in documentation, syntax, keywords etc? What is the best way to strictly limitate the use of code non-compliant with ISO C++?

Not really on topic for this series, sorry. As for native C++ versus C++/CLI, what you see on MSDN is what we've got. The best way to achieve portability is to be familiar with the Standard (so you don't accidentally write non-portable code), and then compile and test your code with multiple compilers.

C64> Or is this stomping on your STL code, causing subtle bugs or something?

Please DON'T do this. C++03 17.4.3.1 [lib.reserved.names]/1: "It is undefined for a C++ program to add declarations or definitions to namespace std or namespaces within namespace std unless otherwise specified. A program may add template specializations for any standard library template to namespace std. Such a specialization (complete or partial) of a standard library template results in undefined behavior unless the declaration depends on a user-defined name of external linkage and unless the specialization meets the standard library requirements for the original template."

(Remember, there are no such things as partial specializations of function templates. Anything that looks like that is actually an overload, and adding overloads to namespace std is forbidden. As for explicit specializations of function templates and class templates, the "user-defined name" part is important - that prevents users from messing with machinery that's not their business.)

new2STL> Clang (one of LLVM compilers) are beginning to support c++0x but in an early stage yet.

This is true, but I don't think Apple will use any newer version too soon, that makes it "useless". I do find it very unfortunate, since it would be really nice to use C++0x features, and I must say hats off to MS for implementing so much already, while most compilers are far behind. I mean just a nullptr on most compilers would be nice, and lambdas would be great, and unordered_map, and... oh wait, now I'm going too far .

@STL & @new2STL: Thanks for the answers, very appreciated!!!

@STL: Is there any page where the VC11 features regarding C++0x are listed? Couldn't find anything by quickly searching googling for it.

I use beta software all the time, i know the risks.( Quite satisfying, when the software is released, i know it will work since i've reported and/or sent patches to the devs.From a dev to a dev communication, oh so nice, no bs/secrets/pr people, i wish official bug reports could be this efficient and time consuming/hassle free ) *cough* example: AMD 3d drivers w7 bug reports, going over 6 months and still not fixed. example 2: microsoft "by design"... *cough*

> The console is delicious.

Sure i can agree somewhat, if you exclude the excessive typing and lack of colors (colors improve readability)I wish gcc would add colors for warnings and errors. Perhaps i'm forced to write some kind of console wrapper to do the coloring

> There isn't, unless you consider writing a local struct to be a workaround.

I was thinking more of something i could add to my class so it accepts lambdas, like some template magic: if lambda use std::function...or similar...

I've used the Eclipse IDE for C/C++ Developers on Windows to wrap MinGW's version of gcc & g++ (i.e. gcc & g++ on Windows: http://sourceforge.net/projects/mingw/ ) ... and it works very well ... and is easy to understand ... and has lots of colors. The default is not C++0x, so you'll need to add "-std=c++0x" by editing the properties of your C++ project in C/C++ Build / Settings / Tool Settings tab / GCC C++ Compiler / Miscellaneous / Other flags text field. You'll need to add that to the Debug and Release configurations. For the Release configuration, you also might want to add "-march=native" (or whatever architecture you're writing for) to the same text field; otherwise, the default instruction set that gets used is a little old.

There is probably an easy way to make that "-std=c++0x" addition the default for all future projects, but I haven't had to worry about that yet.

@Burkholder: Nice tip, it looked good but then i saw it needed java to run which is a big no no and also i don't like java since it doesn't integrate well with windows (according to the java devs it's due to microsoft not cooperating, (sarcasm) shocking, right (/sarcasm) ) I use mingw and mingwx64 on my usb thumb drive so i can take it with me everywhere i go, the programs i use have to be portable. I would have liked to use vs2010 as IDE but as we all know it microsoft likes to make programs that integrate into the operating system *cough* internet explorer, office 2010, etc.. *cough* But thanks for the suggestion and info i appreciate it

@Mr Crash:Unfortunately, the "Eclipse IDE for C/C++ Developers" does require the JRE 1.5 or higher to run. There is a way to "install" the JRE without actually installing the JRE (i.e. no Windows registry and no admin rights) - place the bin folder of that unzipped JRE temporarily in the PATH and execute Eclipse with that temporarily revised path ... but that requires a little more leg work. It's easier to just install Java.

I have never had a problem with Java on Windows. The JRE and JDK on Windows have always played nicely for me ... and never interfered with anything. I'm not a fan of Java ... I only develop using it when forced by requirements ... and I would always choose C# (on .NET/Mono) over Java (on JRE) for managed work, but Java has always worked for me ... so no M$ conspiracy theories here.

@Mr Crash: You can also use Code::Blocks, Its build over WxWidgets, so have ports to Linux, Windows, Mac etc And it is based on the L&F of VS6, its integrates with gcc, mingw, even with Windows SDK. (and are the spiritual successor of dev-c++).

I have used Eclipse for a long time, and because my machine must have JRE instaled I have not problems in using the compressed version (no installs no hidden configs)

The copy optimization code raised a question that why 'is_scalar' is used instead of 'has_trivial_assign' to determine the possibility to use memmove? Without knowing better, it seems weird that objects of type such as struct MyInt {int a;};now don't seem to get the memmove-optimization.

2pRQb: As I mentioned, is_scalar is too conservative. I have a todo about extending this optimization - I've just added a note that we should use the trivial type traits. (This optimization is actually quite old, and predates <type_traits> - we've always been able to detect scalars through handwritten machinery.)

Thanks for the vedio.I would like to ask about a memory leak problem around std::ios_base when I use boost interprocess basic_vectorstream under VC++ (both 2008 and 2010). I don't know where is the proper place I should post it? Sorry for posting here!In boost\interprocess\streams\vectorstream.hpp there is a class base_vectorstream derived from std::basic_iostreamcode from vectorstream.hppbasic_vectorstream(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : basic_ios_t(), base_t(0), m_buf(mode){ basic_ios_t::init(&m_buf); }The constructor basic_vectorstream(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) :it constructs the based std::basic_iostream with base_t(0)The based std::basic_iostream will constructs std::basic_istream by _Myis(_Strbuf, false) now _Strbuf == 0 as base_t(0)above std::basic_istream constructor basic_istream(_Strbuf, false) will call into _Myios::init(_Strbuf, _Isstd)_Myios (std::ios_base) calls into _Init() (std::ios_base)std::ios_base _Init() will new a locale by _Ploc = _NEW_CRT localethe "basic_ios_t::init(&m_buf);" called by basic_vectorstream constructor in vectorstream.hpp will new a locale again! It causes a memory leak problem.What is the suggestion to fix it? Change to below? Or it should be fixed in std::ios_base?basic_vectorstream(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : basic_ios_t(), base_t(&m_buf), m_buf(mode){}

I would like to ask about a memory leak problem around std::ios_base when I use boost interprocess basic_vectorstream under VC++ (both 2008 and 2010). I don't know where is the proper place I should post it? Sorry for posting here!

In boost\interprocess\streams\vectorstream.hpp there is a class base_vectorstream derived from std::basic_iostream

>That isn't the right question to ask, because C++0x consists of many features, compilers support different subsets, and those subsets are growing over time.>In general, you'll need compiler version queries.It would be awesome if other compilers than just Clang implemented the feature check extension __has_feature:http://clang.llvm.org/docs/LanguageExtensions.html#feature_checkInterestingly enough, browser script writers have long since learned that version queries (user-agent queries) are of the devil. But as C++ programmers, we're still stuck with essentially the same logic. "So _MSC_VER is defined. But does that mean it's VC++, or is it Intel pretending to be VC++? Let's check _ICL_VERSION - or what was it called? So, turns out I've got actual VC++, version 1400. Er, what real version does that correspond to? Does it have the feature I want?"It's pretty much black magic. This is so much prettier:#if __has_feature(cxx_variadic_templates)// variadic template implementation#else// emulation#endif

Remove this comment

Remove this thread

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums, or
Contact Us and let us know.