Thursday, October 11, 2012

Parameter Types in Constructors

[This is the first time I've tried to include code fragments in a blog post, and let's just say I was surprised at how badly Blogger deals with them.  I apologize for any formatting problems, and I welcome suggestions on how to get Blogger to swallow code displays without throwing a fit.]


I recently went through Sumant Tambe's presentation materials from his Silicon Valley Code Camp presentation, "C++11 Idioms."  He argues that an emerging idiom is to pass arguments to constructors by value, because this takes advantage of move opportunities when they are available.  I was surprised to read about this emerging idiom, in part because I had not heard of it (I'm supposed to be clued in about this kind of stuff) and in part because it runs contrary to my own thinking on the subject, which is to use perfect forwarding. 

His presentation goes on to discuss the general problem of efficient parameter passing, based on a trio of blog posts by










Suppose I have a Widget class with a std::string data member.  In C++98, I'd initialize it like this:
class Widget1 {
public:
  Widget1(const std::string& n): name(n) {}

private:
  std::string name;
};
The problem here is that if an rvalue is passed to the Widget1 constructor, name is copy-initialized from n instead of being move-initialized.  That's easy to fix using perfect forwarding, which is designed to optimize this kind of thing:
class Widget2 {
public:
  template <typename T>
  Widget2(T&& n): name(std::forward<T>(n)) {}

private:
  std::string name;
};
No muss, no fuss, no enable_if, no testing for whether the argument passed to n was an rvalue--none of that stuff.  Very nice.

But let's suppose there's another way to initialize a Widget.  Instead of passing a name, we can pass an ID number, and the name can be looked up from the ID number.  In C++98, adding this would be trivial:
class Widget3 {
public:
  Widget3(const std::string& n): name(n) {}
  Widget3(int id): name(findNameFromID(id)) {}

private:
  std::string name;
};
Adding this to the version of Widget with the perfect forwarding constructor, however, leads to grief.  But not immediately. The class will compile without any trouble, and simple tests will work as expected:
class Widget4 {
public:
  template <typename T>
  Widget4(T&& n): name(std::forward<T>(n)) { std::cout << "T&&\n"; }
  Widget4(int id): name(findName(id)) { std::cout << "int\n"; }

private:
  std::string name;
};

Widget4 w1("Hello");      // calls perfect forwarding ctor
Widget4 w2(22);           // calls int constructor
But slightly trickier tests fail.  For example, if the type of the passed ID isn't exactly int--e.g., a long or a short or an unsigned--the perfect forwarding constructor is a better match, and the code will try to initialize a std::string with a numerical value.  This makes no sense, and the compiler will exhibit no reluctance in telling you that.  Given
Widget4 w3(22L);          // pass a long
gcc 4.7 says this:
ctors.cpp: In instantiation of 'Widget4(long int &&)':
ctors.cpp:40:18:   required from here
ctors.cpp:18:42: error: invalid conversion from 'long int' to 'const char *' [-
    fpermissive]

basic_string.h:487:7: error: init. arg 1 of 'basic_string<
        char; _Traits = char_traits<char>; _Alloc = allocator<char>, _Traits
      , _Alloc
    >::basic_string(
        const char; _Traits = char_traits<char>; _Alloc = allocator<char> *
      , const _Alloc &
    )' [-fpermissive]
In file included from c:\users\scott\apps\mingw\bin\../lib/gcc/i686-pc-
    mingw32/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from ctors.cpp:1
The fundamental problem is that perfect forwarding and overloading make very bad bedfellows, because perfect forwarding functions want to take everything. They're the greediest functions in C++.

To curb their avarice, you have to limit the conditions under which they can be instantiated, and that's where enable_if comes in.  And where enable_if comes in, any semblance of beauty leaves.  For example, if you'd like to disable the perfect forwarding template for integral types (thus allowing the int overload to handle those types), you could code it this way:
class Widget5 {
public:
  template <typename T>
  Widget5(T&& n, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
    : name(std::forward<T>(n)) { std::cout << "T&&\n"; }
  Widget5(int id): name(findName(id)) { std::cout << "int\n"; }

private:
  std::string name;
};
This code behaves as we'd like, assuming (sigh) we'd like to treat a char as a number:
  Widget5 w3a("Sally");           // calls perfect fowarding ctor
  Widget5 w3b(44);                // calls int ctor
  Widget5 w3c(44L);               // calls int ctor
  Widget5 w3d((short)44);         // calls int ctor
  Widget5 w3e('x');               // calls int ctor
If more constructor overloads are added, or if the constraints on when the perfect forwarding constructor is applicable become more complicated, the enable_if-related code can become, er, unpleasant. Such unpleasantness is presumably the noise that Sumant Tambe refers to when he rejects perfect forwarding.

In those cases, I think his preferred solution to the problem of declaring constructor parameters--take everything by value--is reasonable.   The generated code isn't quite as efficient as you'd get from perfect forwarding, but the overloading rules are a lot easier to understand, and the resulting code is easier to both read and write.

I still think that perfect forwarding is the language tool you should prefer when you need to write constructors and similar functions (e.g., setters) that simply shuttle values from one place to another.  That's what it's designed for.  If you need to overload such functions, however, things get very messy very quickly, and except in the most demanding of performance-sensitive applications and libraries, I think it's reasonable to fall back on pass-by-value as the parameter-passing mechanism.

But these are still early days in C++11 programming, and we're all still learning.  I welcome your thoughts on how to declare constructor parameters, the proper role of perfect forwarding, and the wisdom of passing parameters by value.

Scott

Tuesday, October 9, 2012

Video for "Universal References in C++11" Now Available

A couple of days ago, I blogged that my article on "Universal References" had been published by Overload, and I said a video of me presenting this topic at C++ and Beyond would soon be available.  Soon has become now. Servers are standing by, and on-demand viewing is available at Channel 9.  Many thanks to Charles Torre and to Microsoft for recording and hosting the presentation. I hope you like it and find it useful.  If you do, please tell others about it, because I'm trying to inject the term universal reference into the C++ vocabulary, and I can't do it alone.

Scott

Saturday, October 6, 2012

New Article: "Universal References in C++11"

One of the most difficult aspects of C++11 for me to wrap my head around was the meaning of "T&&" in type declarations.  “It means rvalue reference,” I was told, and that was fine until I was also told that in some cases, it actually means lvalue reference.  I fought with this seeming contradiction for a couple of years before my head cleared and I decided that we need to distinguish declarations for rvalue references from declarations for things that look like rvalue references, but may not be.  I call these latter things universal references.  I hope the term catches on, because I think it makes the matter a lot easier to understand.

I gave a talk on universal references at this year's C++ and Beyond, and a video of that talk should go live sometime this month.  (I'll let you know when.)  I also wrote an article on the topic for ACCU's Overload, and the issue with the article (PDF) has just been published.  This is from the beginning of that article:
Given that rvalue references are declared using “&&”, it seems reasonable to assume that the presence of “&&” in a type declaration indicates an rvalue reference. That is not the case:
Widget&& var1 = someWidget;       // here, “&&” means rvalue reference

auto&& var2 = var1;               // here, “&&” does not mean rvalue reference

template<typename T>
void f(std::vector<T>&& param);   // here, “&&” means rvalue reference

template<typename T>
void f(T&& param);                // here, “&&” does not mean rvalue reference
In this article, I describe the two meanings of “&&” in type declarations, explain how to tell them apart, and introduce new terminology that makes it possible to unambiguously communicate which meaning of “&&” is intended. Distinguishing the different meanings is important, because if you think “rvalue reference” whenever you see “&&” in a type declaration, you’ll misread a lot of C++11 code.
I hope you find the article both interesting and useful.

Scott

Monday, October 1, 2012

The Projucer

A lot of uninvited stuff shows up in my electronic mailbox. There's spam, sure, plus my share of links, stories, and pictures from friends and family members who are more easily entertained than I am.  I also get questions and comments and links to C++- and software-related things people think---or hope---I might be interested in. I skip a lot of the "entertainment" I get from friends and family (none of whom read this blog, so I'm not worried about offending them), but in the realm of C++, I look at everything I get, because it's part of my job as a C++ consultant. Most of the stuff I see I dismiss without action, because I don't think it's interesting or I don't see how it's useful or I simply don't have time to really analyze and pursue it.  There are, after all, only so many hours in a day.

Julian Storer
(unless he's using
a picture of
somebody else)
Every once in a while, something piques my interest, and not always for the reason the sender imagines.  Such was the case about three weeks ago, when I got a message from Julian Storer. He wrote (with minor editing and link addition on my part):
For the last decade I've been running a big C++ cross-platform toolkit called JUCE. Won't attempt to describe it in this email - there's plenty of info about it on my website if you want to learn more.

I've just been making some announcements about a new tool that I'm aiming to release soon, and being proud of what I've managed to cook-up, I thought it'd be worth pestering some of my C++ guru heros to have a look at it. It's something that nobody's managed to do in C++ before, so I think you'll probably find it interesting!

The TL;DR is: I've built an IDE that uses Clang and the LLVM JIT engine to provide real-time interactive execution of C++ GUI code, and to allow GUI editing by automatic refactoring of user-code... Hard to sum it up in a sentence, but if you saw the Bret Victor demo that everyone was talking about a few months ago, you'll get the gist - he
was showing off interactive javascript, and I've managed to do the same trick in C++.

Hope you can spare 10 mins to check it out!
I did check it out, and not just because he called me a C++ guru hero. Though I had not watched all of  Bret Victor's demo, I had watched part of it, so I had some idea what was involved, and the idea that something similar could be done for C++ intrigued me.  Also, when people tell me they have done something in C++ that nobody has done before, that tends to catch my attention. Most important, at the time I was trying to figure out what to do with Julian's email, I had much more pressing things to work on that I didn't want to attack yet, so I needed a way to tell myself I was working without actually, you know, working.  So I toddled over to the screencast Julian had put together and invested the six minutes and thirty-six seconds it runs.

It's a nifty demo, but the application area is GUI development, and that's not really an area I know a lot about.  So when he ran the GUI from the compiled application, changed the application source code, then showed how the GUI updated itself, I was impressed with what must be happening behind the scenes, but I didn't have to hold onto my hat, nor was I concerned that my socks would be knocked off.  And when he modified the running GUI and some literals changed in the source code, I thought it was, well, nice. But then I saw something that made me replay that part of the video several times.  Not only did the literals in the source code change when he moved a GUI widget around, he was also able to have new statements added to the source code by interactively editing the running GUI.  He was editing the program source code through the GUI.

Maybe this is old news.  Maybe Visual Studio and Eclipse and various other IDEs for GUI development allow you to create and edit source code via both text (traditional source code) and generated GUI (arguably an alternative form of source code).  As I said, I'm not a GUI development guy, so I have no idea what the state of the art in this area is.  What I do know is that Julian's demo is consistent with the idea that there is no such thing as canonical source code.  C++ text is source code, of course, but there's no reason that the GUI generated from that source code can't be viewed as source code, too.  Since they're both source code, it makes sense that the underlying program can be edited through either.  One could argue that each representation of the program (C++ text and displayed GUI) is simply a view of that program, and the program itself is something more fundamental--something more abstract that transcends the concrete syntax and semantics of whatever view is used to see and manipulate it.

I'd like to believe that this is a reasonable argument, because, in essence, this was the topic of my PhD research many years ago.  My dissertation, Representing Software Systems in Multiple-View Development Environments, explored how one could represent programs such that they could be viewed and edited through any of a variety of concrete syntaxes ("programming languages").  Let me save you the trouble of reading my dissertation by summarizing my conclusion: It's hard.

I'm guessing that Julian was not expecting that his demo would remind me of the research I was pursuing over 20 years ago, but it did.  And that's why I'm blogging about it. Besides, as far as I know, he has done something in C++ that nobody has done before, and groundbreakers like that deserve encouragement. If you're wise in the ways of GUI development with C++, I encourage you to watch Julian's screencast and offer him feedback to help him continue his work.  I'm sure he'd be pleased to hear from you.

Scott

Save money! Expand your library! Win my bits!

It seems that the marketing department at Addison-Wesley has been working overtime, and one of the plots they hatched to lure you to their web site, where they're offering free shipping (within the USA) and a 30% discount if you buy one C++ book and 40% if you buy two or more, is a chance to win a free copy of the digital bundle of my three C++ books.  They even sent me this snazzy graphic for you to click on:
Actually, they sent me three graphics, so you can click on these, too, if you want to:

I'm sure that high-performance server software is standing by to count your clicks and whisk you to the land of irresistible C++ discounts.

To get the full discount, be sure to use the discount code "CPLUSPLUS".

Many of Addison-Wesley's recent C++ titles are introductory, and it's been so long since I was in need of that kind of book, I don't offer recommendations on them, though certainly many of the horses in the Addison-Wesley stable have excellent reputations.  One book I have looked at and strongly recommend is Nicolai M. Josuttis' updated-for-C++11 second edition of The C++ Standard Library.  Getting 30% or 40% off that book (or book+PDF combo) would certainly be nice. And frankly, if you don't yet own a copy of C++ Templates: The Complete Guide (by Nicolai M. Josuttis (who at this point should be sending me kickbacks--but, alas, isn't) and David Vandevoorde), this would be a good time to fill that hole in your library. 

Happy shopping, and good luck with the drawing to win the combined bits of my books. I hope it goes without saying that you don't need to buy anything to get a chance to win the digital versions of my books, but in case it doesn't, you don't need to buy anything to get a chance to win the digital versions of my books. So sign up!

Scott

PS - My mole inside AW whispers, "We are advertising this promotion as applying only to C++ titles, but it works for any set of titles from InformIT." So if you want to scratch that Scala itch that's been bugging you or you want to combine your buying power with that of colleagues who use--gasp!--other languages, now's your chance.

Wednesday, September 19, 2012

"Ask Us Anything!" Session from C&B 2012 now live

The final part of each C++ and Beyond is always the wide-open "Ask Us Anything!" Q&A session. Charles Torre from Microsoft's Channel 9 was there with video equipment in hand (okay, most was on the floor, and the camera itself was on a tripod, but you know what I mean), and his recording is now available.  Andrei, Herb, and I hope you enjoy it.

Scott

Saturday, August 25, 2012

C++ & Beyond Interview with me, Herb, and Andrei

At the end of the second day of C++ and Beyond, Charles Torre of Channel 9 corralled me, Herb Sutter, and Andrei Alexandrescu and pelted us with questions, some from him, others from Channel 9 viewers.  The interview is now online, the first of several videos associated with this year's C&B that will be rolled out on an ongoing basis.

Enjoy!

Scott

Tuesday, July 31, 2012

C&B 2012 Registration Ends Tomorrow!

Registration for C++ and Beyond 2012 ends tomorrow (Wednesday) at 11:55PM Eastern Time--roughly 36 hours from now.   For the third year in a row in this unique conference's three-year history, we've set a new attendance record, but there are still some spots available for this limited-enrollment event. 

Perhaps one reason for the unprecedented interest is the unprecedented amount of technical material we'll be presenting, much of it announced only recently.  We even extended the schedule for the first two conference days to make room for new content.  If you haven't been following the C&B blog, you may be interested in these posts from the past week and a half:
  • Writing Fast Code, which describes a new double-length session (three hours total) that Andrei Alexandrescu will be presenting based, in part, on the work he's been doing at Facebook to optimize the processing of, well, lots, of data. This is not theoretical it-should-run-faster-if-we-do-this kind of stuff, it's the result of countless hours trying things out and seeing what actually works.  For performance-oriented C++ developers, it can't get more practical than this.
  • A Special Announcement by Herb Sutter that gives C&B attendees a sneak preview of and an opportunity to help shape the initial rollout of a project that will be a boon to the entire C++ community.  As Herb clarified in a comment below his post, this project will be free and available to everybody when it goes live, but Herb needs a limited group of active and experienced C++ developers from whom to solicit feedback and engage in active discussion at this point in the project's creation, and C&B 2012 attendees will be part of that group.
  • More C&B than ever!, which describes how each year's C&B has scheduled more time for technical content than the year before.
Those are just the most recent posts.  For all the C&B-related info, check out the full blog history.

This isn't the C&B blog, however, it's my blog, so I'll remind you of the talks I'll be giving at C&B:
Having just finished the materials for these presentations, I can say I'm quite excited about them.  I think they'll help make it easier to use some of the new features in C++11 to greatest effect, while at the same time avoiding some of the potential pitfalls that accompany those features.

I hope to see you in Asheville, NC, next week.

Scott

Thursday, June 21, 2012

Final C&B Talk Announced

I just announced the final talk I'll be giving at this year's C++ and Beyond. It's Secrets of the C++11 Threading API.  Like my other talks, it's a new presentation covering new information I've never written, blogged, or spoken about before. (Okay, there may be some tiny overlap.  For example, in my Effective C++11 talk, I'm going to offer a more detailed analysis of the issues I raised in my blog post, std::string, SSO, and Move Semantics.)

The full slate of talks I'll be giving at C&B in August is:
In addition, I'll be participating in panel discussions and Q&A sessions with Herb Sutter and Andrei Alexandrescu on these topics:
For the talks Andrei and Herb will be giving, check out the C&B schedule. I think you'll find that the mix of talks this year is especially compelling, even by C&B standards.

Registration for C++ and Beyond continues through the end of July, but we're nearly 3/4th full, and once all the seats are gone, they're gone.  In addition, the discounted room rate for C&B attendees expires on July 6, so if you're interested in being part of the premier C++ event of 2012 (at least among those being held in Asheville, NC, in August :-}), I encourage you to sign up sooner rather than later.

Scott

Thursday, June 14, 2012

35% Discount Code for my Digital Book Bundle

Today I got email from my publisher regarding the bundled electronic versions of my books:
Only informIT.com offers this collection in both PDF and ePub formats, together for one price. PRE-ORDER TODAY and SAVE 35% off the list price.
Enter the coupon code MEYERS8627 during checkout to receive your discount. Offer expires June 21, 2012.
The list price of the bundle is $95.99, but, from what I can tell, the "normal" pre-order price is $76.79.  The email says that with the code, the price drops to $62.40.

I don't know if I'm supposed to share this coupon code with you, but the email didn't say I shouldn't, so here you go :-)

In my original post about this digital book bundle, I noted that I had not had a chance to review the product, and that's still the case.  (They tell me I'll get a copy once they're sure it's ready to ship, which I think is quite reasonable.)  I've also not tested the discount code mentioned above.  But I have no reason to think that the bundle is anything less than it's advertised to be, nor do I have a reason to doubt the authenticity of the coupon code. 

If you're interested in having electronic copies of my books for only about $20 each, this looks like a good way to get them.

Scott

PS - My wife suggests you buy as many copies as you can afford.  My editor wonders whether it'd really be such a hardship if you were to buy a few more than you can afford :-)

Wednesday, June 6, 2012

New Digital Bundle of my Books

I recently received this message:
Hi Scott,

I was looking through the books at InformIT.com and was checking to see if the promotion for buying all of your Effective C++ books together was still active and found this instead:


Are those updated versions of your books, or is that one SKU for all three existing books in that series?
I replied:
This is a single SKU for digital editions of all my existing books.  The content of the books is the same as the current editions of the printed books. I was not actually aware that this SKU had been put online, though I knew it was in the planning stages.
Shortly thereafter, I got mail from my publisher:
Your eBook digital collection is now available for pre-order. You can feel free to start pointing folks to http://www.informit.com/store/product.aspx?isbn=0133068625 now!
Consider yourselves pointed.

My books have been available in PDF for over three years (per this post from Feburary 2009), but, as far as I know, this is the first time they've been made available as a bundle of all three books in both PDF and ePub formats. I have not yet had a chance to examine this bundle myself (the author is always the last to know...), but when I announced the PDF versions in February 2009, I wrote:
[The PDFs are] DRM-free and chock-full of linked navigation in all the ways I believe you have a right to expect: tables of contents, indices, cross-references, URLs, mailtos, the whole nine yards.
To the best of my knowledge, all those features are still present.  For all I know, so are a whole bunch more.  Once I get my hands on the digital bundle and take a look at it, I'll let you know for sure. 

Scott

 

Monday, May 28, 2012

Final Week for Early-Bird Registration for C++ and Beyond

This is the final week for Early-Bird (i.e., discounted) registration for C++ and Beyond, the C++ conference-only-better event organized and put on by me, Herb Sutter, and Andrei Alexandrescu. Among the topics we'll address in our technical sessions are "universal references" in C++11 (a term I'll introduce, define, and, I hope motivate), using C++11 features to write error-resilient code, how new C++11 meanings for longstanding keywords affect concurrent and parallel code, and how to convince your colleagues to improve their software development behavior.  Additional topics are listed on the C&B 2012 Schedule Page, and there are more to come.

Every year I say the same thing about C&B, but every year I honestly believe it:  the coming C&B looks to be the best one ever. It's still the only C++ event featuring limited attendance; all-new presentations by me, Herb, and Andrei; and communal breakfasts and lunches as one of many characteristics designed to maximize the opportunity for you to talk not just with us, but also with one another.  In a year with more C++ events than probably any since the turn of the century, C++ and Beyond continues to distinguish itself as an event focusing not just on top-notch content, but also on face time with the people who developed the content and with the leading developers who will apply it.

During the Early Bird period, registration is discounted 10% for both individual and group registrations.  Group registrations (three or more) get an additional 10% off for being a group, so for the remainder of this week (i.e., through Friday), the discounts are effectively 10% for individuals and 20% for members of groups.  That's a savings of literally hundreds of dollars per registration.

Early-Bird registration won't be extended, so if you'd like to be part of C++ and Beyond 2012 (I'd certainly love to see you there), I encourage you to register no later than Friday.

Scott

Friday, April 27, 2012

Josuttis 2E has arrived!

For C++98, the standard everyday reference work for the C++ standard library was Nicolai M. Josuttis' The C++ Standard Library.  His updated version for C++11 has been eagerly anticipated, and I was pleased to receive my copy yesterday.

I was confident that the new edition would be a worthy successor to its predecessor, but I have this whole Trust-and-Verify mentality, so I forced myself to withhold judgement until I'd had a chance to check the book's content.  I wasn't disappointed.  Based on skipping around and reading here and there (primarily about functionality new to C++11, including emplacement functions, forward_list, random numbers, tuples, async, and the atomics API, not to mention an overview of new C++11 core language features, e.g., lambda expressions, rvalue references, constexpr, and more), the second edition of The C++ Standard Library looks to be to C++11 what the first edition was to C++98:  the first place to go for a readable and insightful summary of the C++ standard library.  Language lawyers will still turn to the C++ Standard itself, of course, and Josuttis' new book doesn't cover every nuance of library interfaces any more than the first edition did, but note my use of the word readable in my description of his presentation.  The Standard is definitive, but it's not readable.  Josuttis' book is readable, and, for most people most of the time, as good as definitive. I make my living studying the arcania of C++, but when I'm coding, I turn to Josuttis when I can and the Standard only when I must.

Interestingly, the physical size of the new book is no larger than the original edition, even though the standard library has become a lot bigger.  The new book has 300 more pages, however.  (Exactly 300.  The final page number in the first edition is 799, and the final page number in the new version is 1099.  How he managed that, I don't know, but it's a neat trick.)

[The following information about electronic editions has been revised since my original post.]
In terms of electronic editions, the book is available in PDF and ePub, plus there is an edition for Kindle. This information is courtesy of comments readers left on this blog entry, and I am grateful to them for it.

I encourage you to consider buying your own copy of the new edition of The C++ Standard Library.  Having it close at hand was indispensable for C++98 programming, and I think that having it close at hand for C++11 programming will be just as important.

Scott

Tuesday, April 24, 2012

Information on the C++11 Memory Model

I've been receiving a number of inquiries about where to turn for information about the C++11 memory model (technically the memory consistency model).  Having prepared and given a talk on the topic at last year's C++ and Beyond, I can tell you that the C++11 memory model is one of the most technically challenging topics I've ever tried to master. The good news is that if your goal is simply to write well-behaved multithreaded programs, you don't need to know any of the details of the memory model.  All you need to remember is to avoid data races in your programs, and the simplest way to do that is to follow the advice that multithreaded developers have been following for years:  access shared mutable data only when you know you have exclusive access to it, typically by acquiring a mutex before the access and releasing the mutex after the access. C++11 offers RAII classes to automate the release part of this protocol (std::lock_guard and std::unique_lock), so this is easier than ever to do. In C++11, you can also use atomic data types (e.g., std::atomic<bool>) to ensure exclusive access with often greater efficiency, but conceptually these are just data types where, on each access, C++ itself handles the moral equivalent of locking and unlocking the appropriate mutex.  (In practice, special machine instructions that avoid the need for mutexes are typically employed.) So, as I said, if your interest in the C++11 memory model is to know how to write threaded programs that will run correctly, you can essentially ignore the model itself.

If, on the other hand, you really want to understand the memory model, you have your work cut out for you.  Under no conditions should you start with the C++11 Standard!  Without the proper protective gear in place, that thing could maim you for life. Instead, I suggest you start with Anthony Williams' book, C++ Concurrency in Action.  Chapter 5 has the most comprehensible description of the C++11 memory model I have seen, and in fact it's the only one I know of that points out that C++11 actually offers three different consistency models:  sequential consistency, acquire-release consistency, and relaxed consistency.  (That alone should give you some idea of what you're in for if you decide to delve into this topic.) I own Williams' book in both electronic and paper form, and I think it's not just the best current treatment of C++11's threading facilities (including, but not limited to, the memory  model), it's likely to remain the best for some time to come.

Sources that complement Williams' coverage include the following.  Note that anything published before September 2011 may differ from the final C++11 memory model, and the longer the time before September 2011, the higher the likelihood of divergence.
Good luck!
Scott

Tuesday, April 10, 2012

std::string, SSO, and Move Semantics

I'm becoming increasingly concerned that C++11's support for move semantics is leading some people to conclude that we no longer have to pay as much attention to the cost of copying objects as we used to.  "Many copies will silently become moves," they exclaim, "and moves are cheap!" Such reasoning is invalid in a number of ways.

First, not all copy requests can be replaced by moves.  Only copy requests for rvalues are eligible for the optimization.  Second, not all types support move operations that are more efficient than copying operations.  An example is a std::array<double, 1000>.  Third, even types that support efficient move operations may support them only some of the time.  Case in point: std::string.  It supports moves, but in cases where std::string is implemented using SSO (the small string optimization), small strings are just as expensive to move as to copy!

What it means to be "small" is up to the implementation.  Unless I'm misreading the source files, std::strings with a capacity of up to 15 are "small" in Visual C++ 11 beta, so std::string objects of up to that capacity will not benefit when copies become moves.  (The SSO buffer size seems to be hardwired to be 16 bytes in VC11, so the maximum capacity of a std::wstring that fits in the SSO buffer is smaller:  7 characters.)

gcc 4.7 seems to continue to use reference-counting instead of SSO for its std::string implementation.  This is non-conforming in C++11 (reference-counting may no longer be used for std::string), and it looks like gcc is aware that it must be changed. However, gcc 4.7 offers the non-standard __versa_string with a std::basic_string-compatible interface (other than the name of the template and the namespace in which it's located), and __versa_string offers the SSO.  In this case, the maximum capacity of "small" strings seems to be hardwired to 15 characters (not bytes).

While googling around for a good page to link to for the term "small string optimization" above, I came across John Ahlgren's blog entry of March 30 on how SSO interacts with move semantics.  He refers to the fact that short strings with the SSO move more slowly than longer strings as the "small string deterioration" :-)

Scott

Thursday, April 5, 2012

C++11 is Almost Here for Real!

This entry is the first under a slightly expanded charter for this blog.  Until now, I've restricted blog entries to announcements about my professional activities.  Hereafter, entries will simply be related to my professional activities and interests. The difference is subtle, and, in all likelihood, you will rarely notice it.



At the beginning of my Overview of C++11, I show a simple program to compute the most common words in a set of input files.  I write the program once using "old" C++ (i.e., standard C++98/03), then again using features from C++11. 

In 2009, when I first published the C++11 program (at that time, what became C++11 was still known as C++0x), there was no compiler that could come anywhere near compiling it. Testing the code required replacing standard C++11 library components with similar components available in TR1 or from Boost or Just Software Solutions, and language features like auto, range-based for loops, lambda expressions, and template aliases had to be replaced with typically clumsier C++98/03 constructs that were more or less equivalent in meaning.

This week I tested my simple C++11 sample program with Stephan T. Lavavej's excellent  distribution of gcc 4.7 for Windows as well as Microsoft's VC11 beta.  gcc 4.7 has lots of support for C++11, but the concurrency API still seems to be largely missing, at least for Windows, so my sample program doesn't get very far with that compiler.  [Update 6 April 2012: As noted in the comments below, when invoked in the proper manner on the proper platform, gcc 4.7 compiles and runs my program without modification!]

 The situation with the VC11 beta is a lot better.  Only two lines have to be changed.  The template alias
  using WordCountMapType = std::unordered_map<std::string, std::size_t>;
needs to be replaced by its typedef equivalent:
  typedef std::unordered_map<std::string, std::size_t> WordCountMapType;
And the z length specifier in this call to printf,
  std::printf("  %-10s%10zu\n", (*it)->first.c_str(), (*it)->second);
needs to be replaced with its VC++ equivalent, I:
  std::printf("  %-10s%10Iu\n", (*it)->first.c_str(), (*it)->second);
Other than that, the demonstration program I wrote three years ago (which, in fairness to compiler writers, was two and a half years before the C++11 standard was ratified) compiles cleanly with VC11.

If you have access to a compiler that compiles my program without modification, please let me know! The program itself is below.  You can see a more colorful version of it, along with some commentary, and an example invocation and the corresponding output, on slides 13-15 of the free sample of my C++11 training materials.

Scott

#include <cstdio>
#include <iostream>
#include <iterator>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <unordered_map>  
#include <future>

using WordCountMapType = std::unordered_map<std::string, std::size_t>;

WordCountMapType wordsInFile(const char * const fileName)   // for each word
{                                                           // in file, return
  std::ifstream file(fileName);                             // # of
  WordCountMapType wordCounts;                              // occurrences

  for (std::string word; file >> word; ) {  
    ++wordCounts[word];
  }
  return wordCounts;
}

template<typename MapIt>                                            // print n most  
void showCommonWords(MapIt begin, MapIt end, const std::size_t n)   // common words
{                                                                   // in [begin, end)
  // typedef std::vector<MapIt> TempContainerType;
  // typedef typename TempContainerType::iterator IterType;
  std::vector<MapIt> wordIters;
  wordIters.reserve(std::distance(begin, end));
  for (auto i = begin; i != end; ++i) wordIters.push_back(i);

  auto sortedRangeEnd = wordIters.begin() + n;

  std::partial_sort(wordIters.begin(), sortedRangeEnd, wordIters.end(),
                    [](MapIt it1, MapIt it2){ return it1->second > it2->second; });

  for (auto it = wordIters.cbegin(); 
       it != sortedRangeEnd; 
       ++it) {
    std::printf("  %-10s%10zu\n", (*it)->first.c_str(), (*it)->second);
  }
}

int main(int argc, const char** argv)   // take list of file names on command line,
{                                       // print 20 most common words within;
                                        // process files concurrently
  std::vector<std::future<WordCountMapType>> futures;

  for (int argNum = 1; argNum < argc; ++argNum) {
    futures.push_back(std::async([=]{ return wordsInFile(argv[argNum]); }));
  }

  WordCountMapType wordCounts;
  for (auto& f : futures) {
    const auto wordCountInfoForFile = f.get();  // move map returned by wordsInFile

    for (const auto& wordInfo : wordCountInfoForFile) {
      wordCounts[wordInfo.first] += wordInfo.second;
    }
  }

  std::cout << wordCounts.size() << " words found.  Most common:\n" ;
 
  const std::size_t maxWordsToShow = 20;
  showCommonWords(wordCounts.begin(), wordCounts.end(), 
                  std::min(wordCounts.size(), maxWordsToShow));
}

Monday, March 12, 2012

My Training Courses through Other Vendors

For many years, I've allowed select outside technical trainers and training firms to use my course  materials with their clients. In cases where people approached me for training, but, due to scheduling or location or budgetary issues, etc., we were unable to work out an agreement, I'd refer them to one or more of these outside vendors.

These days, I face a challenge most people would love to have: there's more demand for my services than I can provide. Fortunately, thanks to these outside trainers and training firms, I have a viable suggestion for would-be training clients in cases where I can't do the work myself. In the past, my referrals to outside vendors have been ad hoc, but the issue arises often enough that I decided to put together a page at my web site listing the various individuals and companies who are authorized to use my training materials.

As a general rule, these vendors tend to have better scheduling flexibility than I do. I typically know the people who do the training, and I have great confidence in them. They use the exact same training materials that I use. As the person who did the research into the topics addressed by the materials and who created the materials themselves, I like to think I offer something nobody else can, but in cases where my doing a training gig is not possible, I'm pleased to be able to offer clients and would-be clients reasonable alternatives.

To view a summary of my authorized outside training vendors, please visit my Approved Outside Vendors page.

Thanks,

Scott

Thursday, February 23, 2012

Open-Enrollment Seminars in May in Eindhoven, The Netherlands

In 2002—ten years ago!—I gave my first-ever presentation on the effective use of C++ in embedded systems. That presentation was sponsored by Programming Research, a firm that develops static analysis tools for C and C++. Such tools were near and dear to my heart then, and they're no less so now, so I was pleased when Programming Research asked me to collaborate with them again. The result is two seminars this May in Eindhoven, The Netherlands:

21-22 May 2012Effective C++ in an Embedded Environment
23 May 2012Better Software—No Matter What

The presentation on C++ in embedded systems has been substantially extended and updated since its world debut a decade ago, but the core of that talk—providing practical information about how to apply C++ to solve common problems and to address common issues faced by embedded developers—remains unchanged. For a more detailed overview of the seminar than you'll find at the page linked to above, consult my web site's description.

My Better Software seminar has a characteristic that takes many people by surprise: it doesn't focus on C++.  It was originally motivated by my observation that many C++ projects that struggle do so for reasons that have nothing to do with the choice of programming language, so I put together a presentation that focused on the extralinguistic (but still programming-based) issues I commonly encountered.  When I was done, I realized that the issues in the presentation applied regardless of..., well, let me quote from my web site's description of the seminar (which is more comprehensive than the official seminar page linked to above):
Some development practices improve software quality, regardless of the domain of the application, the language in which it's written, the platform on which it runs, or the users it is intended to serve. This seminar explores fundamental principles, practices, and standards that improve software quality, no matter what the software does, how it does it, or whom it does it for.
As a reader of this blog, you're likely a C++ developer, but while the material in the seminar is perfectly applicable to you, it's also perfectly applicable to your colleagues who use other languages.  I encourage you to let them know about it.

This will be my first time working in The Netherlands.  With luck, it won't be my last. I hope to see you in Eindhoven in May.

Scott

Friday, February 17, 2012

C++ and Beyond 2012 Registration is Open!

For the third year in a row, Herb Sutter, Andrei Alexandrescu, and I are teaming up for C++ and Beyond, a limited-attendance conference-only-better event built around the dissemination of new, timely, and practical information for serious C++ software developers. This year's C&B will take place August 5-8 in Asheville, North Carolina, at the Grove Park Inn.
A more detailed post announcing the opening of registration is available on the C&B Blog, which I encourage you to subscribe to if you're interested in C++ and Beyond. That's where most information about it gets posted. Or you can go straight to the registration page, if you like :-)

I hope to see you in Asheville at C++ and Beyond 2012.  Andrei and Herb and I are working hard to make it the best C&B ever!

Scott

Tuesday, January 31, 2012

Minor Update to Table Showing Compiler Support for C++11

I just added coverage of enhanced enums (e.g., enum classes) and new alignment controls (alignof, alignas, std::aligned_storage and std::aligned_union) to my C++11 training course, and during the course of my research into and testing of those features, I made some minor updates to my summary table of C++11 support in gcc and MSVC.

The new slides will be included in the published version of my C++11 training materials the next time I push out a release.  Having recently done that, I don't expect the next release to go out for a while, but in the meantime, the information sources I refer to for enhanced enums and for alignment control in my C++11 training course are listed below.

Enhanced enums:

Alignment Control:
Scott

Wednesday, January 25, 2012

September Open-Enrollment Seminars in Stuttgart, Germany

In what has in recent years become an annual pilgrimage to Stuttgart, I, in collaboration with QA Systems, will conduct three open-enrollment seminars in September.  Each is two days long.  As with all my public presentations, you'll find details at my Upcoming Talks page. To save you the trouble of clicking through that, here's the summary:

17-18 September 2012
Effective C++ in an Embedded Environment
20-21 September 2012

Fastware for C++
24-25 September 2012

An Overview of the New C++ (C++11)

The talk on C++11 will be a two-day version of my three-day training course, which means that some topics I'd normally cover will be omitted. The topics to be skipped will come out of the material covering new standard library functionality, but which library features will be omitted will be determined during the seminar, based on the interests of the attendees and the time remaining after all core C++11 language topics have been discussed.  To ensure that attendees have copies of all the materials I'll show, each attendee will receive a copy of the materials for the full three-day seminar, even though it will be clear from the outset that I won't be able to cover everything.  In other words, the handout you'll get as a seminar participant will include "bonus topics" not covered in the lecture :-) 

Last year's experiment in doing a presentation in German was, linguistically speaking, successful (people had no trouble understanding me, and I had no trouble responding to their questions and comments), but I don't speak German as quickly as I speak English, and that meant that I had to omit a couple of topics I normally cover.  The feedback I got was that covering more topics was more important than doing a presentation in German, so this year, I'm back to an all-English set of talks.  During breaks and lunch, I still plan to speak German, however, so if you're interested in hearing my funny accent and colorful grammatical constructs, don't worry. You'll have plenty of chances :-)

I look forward to seeing you in Stuttgart in September.

Scott

Monday, January 23, 2012

C++11 Training Materials now jibe with the Final Standard

I mentioned in my November announcement of an updated version of my C++11 training materials that I'd been made aware of a few places where my stuff wasn't fully in accord with the final standard.  In this most recent revision, I've addressed those issues.  To the best of my knowledge, everything in the materials now corresponds to the standard.

Achieving such conformance was my primary motivation for releasing a new set of materials so soon after the last revision, but I also clarified some explanations, fixed a few typos, and did other minor housekeeping chores. All in all, I revised things in about two dozen places. As always, people who've purchased the notes should have automatically been notified of the new release, and they should have received a list of changes I made. If you weren't notified, let me know.

Added 1/27/12: From Artima (publisher of the training materials):
You can log into Artima with the account you used to purchase the
book, click on "Your Settings", and redownload anytime. If you've
forgotten your password, you can get a reminder at
http://www.artima.com/account/mailpwd?d=%2Findex.jsp

Incidentally, I also increased the length of the free sample from 25 to 40 pages, thereby adding range-based for loops, nullptr, Unicode support, and raw string literals to the list of topics I cover there. That should make it easier for people to get a better feel for what they'll receive if they purchase the materials.

I hope you'll excuse my repeating myself from my November posting, but the following is still apt:
If you're interested in a book-like publication covering the most important parts of C++11 (both language and library), I encourage you to consider purchasing my training materials.  If you like my other publications, I think you'll like these, too.  To see exactly what you'll be getting, check out the free sample.

Because this publication is in an unconventional format (annotated training materials), is available from a lesser-known publisher (Artima), and is electronic-only (DRM-free PDF), getting the word out about it has been challenging.  I'd appreciate it if you'd let people know about it, whether through blogs, tweets, social networks (the politically correct term for Facebook), email, or that most retro of communications mechanisms, face-to-face conversation.
Thanks,

Scott

Monday, January 16, 2012

C++ and Beyond 2012 Announced

We've just announced dates and locations for C++ and Beyond 2012: August 5-8 in Asheville, North Carolina.  Like its predecessors, enrollment will be limited, and the centerpiece of the event will be all-new technical sessions by me, Herb Sutter, and Andrei Alexandrescu.

For more information, consult the announcement on the C++ and Beyond blog, then make plans to spend August 5-8 in Asheville for the premier C++ event of the year. I look forward to seeing you there!

Scott

Friday, January 6, 2012

New C++ and Beyond 2011 Panel Sessions Now Online

Microsoft's Channel 9 has posted two more sessions from last year's C++ and Beyond.  Both feature me, Herb Sutter, and Andrei Alexandrescu fielding questions from C&B attendees.
Session topics are:
These are the final sessions from last year's C&B that will be posted, but we're already hard at work on C++ and Beyond 2012. It will take place August 5-8 in the eastern USA.  I'll post details soon -- within days.

Scott

Tuesday, November 1, 2011

C++11 Training Materials Updated

Now that C++0x has become C++11, I updated the name of my training materials and released the latest revision to past buyers. This marks the third updated release of these materials since their original publication in April 2010.

Updating notes for a multiple-day training course (such as my three-day C++11 seminar) has an interesting constraint:  unless the changes involve adding or removing full days worth of material, the length of the course can't be changed.  For a topic like C++11, where I'm learning more all the time, this means that I sometimes want to add information without changing the length of the class.  One way I do that is by adding comments below the PowerPoint slides.  The comments don't get shown in class, but they elaborate on material in the slides.

For the most recent materials update, one of the ways I took advantage of this was by taking the following bullet point from a list of "Other Features" in C++11 (that the course doesn't really cover, typically because the features are less important or because there's currently little or no compiler support for them):
  • Contextual keywords for alignment control, preventing derivation, and constraining virtual function overrides.
I added the following elaboration in the comments:
The identifiers override and final are contextual keywords. Both classes and virtual functions may be declared final. final classes may not be used as bases (per 9/3), and final virtual functions may not be overridden in derived classes.  A virtual function declared override must override a function in a base class. The following is an amalgam of examples from 10.3/4-5:
struct B {
    virtual void f() const final;
    virtual void f(int);
};
struct D : B {
    void f() const;                      // error: D::f attempts to override final B::f
    void f(long) override;             // error: wrong signature overriding B::f
    void f(int) override;               // OK
};
Because elaborations like this generally don't get presented in class, this means that the information in the training materials is in some ways more comprehensive than the information I deliver during a presentation. On the other hand, during a live presentation, people can ask about whatever they want, so I typically address a variety of topics that aren't in the training materials at all.

To the best of my knowledge, my training materials are currently the best source of accessible information about C++11. The Internet is filled with pages about C++11, but many of them were written at a time when draft C++0x was still in a state of flux, and unless you already know the details of the final version of C++11, it's hard to judge whether what you read on a given page is up to date.  The final C++11 standard is definitive, of course, but it's currently expensive (about US$400 at the ISO store), and I don't think anybody will tell you it's easy to read or understand.  There is, as far as I know, only one book out that covers C++11, and although I have not read it, given its recent publication date, I'd be surprised if it takes into account the very latest changes that took place during standardization. (I'd hoped to link to this book, which I know about only from a press release, but now I can't find it. If you know which book it is -- or of other books currently available that cover C++11 -- please let me know.)

To be frank, my training materials aren't perfectly up to date, either.  I had hoped that they were, but it's a big standard (1353 pages), and just yesterday I received a set of bug reports from a member of the standardization committee pointing out places where my notes' treatment of some parts of C++11 are out of sync with the final standard.  I'll fix those problems in the next release of the training materials, a release that, like all releases, will be automatically pushed out to anybody who has purchased the materials.

If you're interested in a book-like publication covering the most important parts of C++11 (both language and library), I encourage you to consider purchasing my training materials.  If you like my other publications, I think you'll like these, too.  To see exactly what you'll be getting, check out the free sample.

Because this publication is in an unconventional format (annotated training materials), is available from a lesser-known publisher (Artima), and is electronic-only (DRM-free PDF), getting the word out about it has been challenging.  I'd appreciate it if you'd let people know about it, whether through blogs, tweets, social networks (the politically correct term for Facebook), email, or that most retro of communications mechanisms, face-to-face conversation.

Thanks,

Scott

Monday, October 24, 2011

C++11 Discussion with me, Herb Sutter, and Andrei Alexandrescu

One of the panel sessions at C++ and Beyond 2011 in August was devoted to C++11, the new standard for C++. That panel session is now live.  I hope you find it interesting.

Scott

Tuesday, September 20, 2011

"Final" C++11 Feature Availability Summary Updated

Since "freezing" my C++11 Feature Availability Summary about a month ago (per this post), I've had a couple of people point me to Stephan T. Lavavej's unbelievably detailed blog post summarizing C++11 feature availability in Visual C++ 11 (as well as VC10), plus I came across Michael Wong's corresponding post for C++11 support in xlC++, so I decided that I froze only the feature tables in my C++11 support summary.  I'll continue to update my links to sources summarizing C++11 feature support in various compilers, because that's not a lot of work for me, and I think the information is useful.  You'll find those links on the first page of my feature availability summary.

Enjoy the ever-burgeoning compiler support for C++11!

Scott

Thursday, August 25, 2011

Video Interview with me, Herb Sutter, and Andrei Alexandrescu

Immediately after the conclusion of C++ and Beyond on August 10, Charles Torre from Microsoft's Channel 9 rounded up me, Herb Sutter, and Andrei Alexandrescu for an hour-long discussion of a variety of issues related to, well, C++ and beyond.  That interview is now live, and I hope you enjoy it.

Scott

Tuesday, August 16, 2011

C++11 Feature Availability Spreadsheet Updated

Now that C++ and Beyond 2011 is behind me, C++0x has been officially christened C++11 (or, as I like to think of it, "C++:  The Spinal Tap Edition"), and Stephan T. Lavavej pointed me to his unbelievably easy to download and install binary of gcc 4.6 for Windows, I had time to play with gcc 4.6 and update my C++11 feature availability summary (now rechristened to reflect that "C++0x" is terminologically passé).  Once again I found myself cackling with glee as I successfully built and ran programs with wacky stuff like
constexpr int factorial(int n) noexcept {                 // define constexpr function!
  return (n == 1) ? 1 : (n * factorial(n-1));
}

std::array<int, factorial(5)> a;                          // use it!
and
for (auto i : { 1, 2, 3, 4, 5} ) std::cout << i << " ";   // range-based for!
I mean, really, who can't love that?   More complicated stuff works, too, like defaulting and deleting and automatically generating move operations.  And nullptr (already present in VC10) joins the party, too. Fun, fun, fun. 

Because C++11 is no longer a draft standard (even if there are still some bureaucratic levers to be moved) and compiler support for C++11 is increasingly common, there's no need for me to keep updating the feature availability summary, so, modulo bugs in the existing data (I'll fix those as they're brought to my attention), I'm freezing it as is.  That will give me more time to play around with the newly-minted and schnazzed up C++, and that's a lot more rewarding than putting little letters in boxes on a spreadsheet.

Have fun with C++11.  How can you not?

Scott

Monday, July 11, 2011

Only 10 Seats Left at C&B next month

Next month's C++ and Beyond is nearly sold out;  there are only 10 spots left.  Registration runs until the end of the month, but only if we don't sell out first, which seems likely.  If you've been thinking about registering for three highly technical days with Herb Sutter, Andrei Alexandrescu, me, and about 100 of the most experienced and insightful C++ developers on the planet (registrations have already come in from three continents), I encourage you to do it while you still can.

I'm especially looking forward to hearing Herb talk about taking advantage of GPUs' computational capabilities in general-purpose programs, and I suspect that Andrei's talk on Big Data will reflect the fact that he and his colleagues have hallway conversations that include offhand comments like, "it's taking too long to create a hash table with four billion elements."  In the meantime, I'm working on the materials for my talk on the C++0x memory model, and my research is showing that, pretty much as expected, there are some interesting subtlties very much worth exploring.  And that's only a third of the technical program!

I'm also looking forward to hanging out and talking with those ~100 experienced and insightful developers, because they -- you -- collectively comprise a gold mine of information.  Plus they -- you -- work on really interesting problems.  And you're all just so darn nice, too.

I hope to see you in Banff next month!

Scott

Sunday, June 5, 2011

C&B Early Bird Registration Expires Friday!

Early Bird registration (and, more importantly, the $300 per person discount that goes along with it) expires at the end of this week (i.e., at the end of the day on Friday, 10 June) for C++ & Beyond 2011, so if you've been thinking about joining Andrei Alexandrescu, Herb Sutter, and me in Banff in August to talk about topics such as programming GPGPUs, the C++0x memory model, processing BIG data, and more, be sure to sign up by the end of the week!

Scott

Sunday, May 8, 2011

Presentation Materials from ACCU Talks Now Available

Silly me. When I posted about the availability of videos of my ACCU talks, I forgot to also make available the presentation materials for those talks, even though in the talks I say I'll send copies to anybody who asks me for them.  Let's skip the you asking me and me sending them to you, okay?  Instead, just download them directly:
Scott

Wednesday, May 4, 2011

Blog posts now reflected to Twitter

If you're interested in knowing about new posts to this blog, but your preferred notification mechanism is twitter, you'll be pleased to know that I've set up a twitter account, and I've arranged for blog posts here to be reflected there. This is, at least for the time being, the only use I plan to make of twitter.

At twitter, I'm @Scott__Meyers, i.e., http://twitter.com/Scott__Meyers.

Scott

Tuesday, May 3, 2011

Videos from ACCU Talks Now Available

The fine folks behind the 2011 ACCU Conference recorded my technical presentations, and those videos are now online as follows:
Viewing these videos is the next best thing to having been to the sessions, provided your definition of the next best thing includes having a seat at the extreme left end of Row 1. The video is nothing to tweet home about (especially if you want to read the text on the slides), but the audio is quite nice. One thing you're likely to find attractive is that the way the video is exposed, I'm hidden much of the time.

Enjoy!

Scott

Monday, May 2, 2011

Updated C++0x Training Materials Published

In April of last year, I announced the publication of my training materials on C++0x.  In trying to win your interest, I wrote:
In some ways, they're better than a book. They make more extensive use of color, they "cut out the fat" to focus on the technical essentials, and my licensing terms grant buyers unlimited updates for life: as long as I update the materials, buyers are entitled to a revised version for free.
I published updates last May and August, but I decided to hold off on publishing additional revisions until C++0x had settled down.  With ratification of the FDIS in March, that settling has occurred, so I've updated my training materials to correspond to the essentially-final draft standard.  The revised version of my materials also includes all the modifications I've made based on my experience using them for professional training purposes, so the latest incarnation should be both the most accurate ever as well as the clearest and most useful.

If you've purchased a copy of the materials, you should already have received notification from Artima Press on how to download the latest PDF. If you haven't purchased a copy, but you've been thinking you'd like to learn more about C++0x, maybe this is the time to give my materials a try.  You can download the first ~25 pages as a free sample at the materials' sales page.

I hope you find these revised materials on C++0x useful.

Scott

Monday, April 25, 2011

C&B Talk on Perfect Forwarding

I've just posted a description of another presentation I'll be making at C++ & Beyond to the C&B blog.  Like all the other talks at C&B, it's of the all-new, world-debut variety.  The title is Adventures in Perfect Forwarding, and following the link will take you to the blog entry that will tell you all about it.

I continue to hope to see you in Banff in August.

Scott

Tuesday, April 12, 2011

C&B Talk on C++0x Memory Model

Herb Sutter, Andrei Alexandrescu, and I are in the process of fleshing out the technical program for this year's C++ & Beyond, and I've just posted my first session announcement.  The title is "The C++0x Memory Model and Why You Care," and rather than repeat the talk description here, I'll let you follow the link to the C&B blog entry for the details.  This will be a new talk I'm creating specifically for C&B, and it should cover topics of interest to anybody who cares about multithreaded programming under C++0x.

The other C&B talks that have been so far announced are:
I think this year's C&B is shaping up to offer an exceptionally strong set of technical talks, and I hope to see you in Banff in August.

Scott

Saturday, April 2, 2011

Appearing/Disappearing consts Article now at C++Next

Shortly after I posted about DDJ publishing and then "unpublishing" my article on appearing and disappearing consts, Eric Niebler suggested I publish it at C++Next. I was pleased to get the offer.  C++Next is emerging as a premier site for C++-related articles, and, unlike some other publishers I could mention, it doesn't demand exclusive worldwide rights to the content it publishes, nor does it insist on "the right in [its] sole and exclusive discretion to edit, rewrite, condense, abridge, or otherwise change" what I wrote. (In fairness, that last part was followed by "taking care, of course, not to change your meaning," but my experience is that the most appropriate person to retain sole and exclusive discretion over what I mean is me.)

Eric volunteered to do the hard work of taking my article and preparing it for publication at C++Next, and then, in a stunning departure from some other publishers I could mention, he worked with me as I tweaked things here and there for final publication.  The result is the best version of the article that exists, both in terms of content and presentation.

I'm grateful to Eric and also to Dave Abrahams, both of whom were instrumental in helping me publish this article in its current form.  In an era when anybody can publish anything with a few mouse clicks, it's a pleasure to work with people who remain dedicated to the hard and detailed work of making content available that's useful to readers and satisfying for authors. Even more than usual, any shortcomings that remain in the article are my fault, because Eric and Dave bent over backwards to accommodate my requests.

Scott