Static data members? Forget their static-ness

Here’s a very rough entry that I hope to refine a bit later.

Recently I’ve started writing things like:

str.find( pattern ) == str.npos // (*)


in.setstate( in.badbit ) ;

I’ll leave the latter for another post (or an expansion of this one). As to the former consider what the alternatives are:

  1. str.find( pattern ) == std::string::npos

    But what if the type of str changes, for instance to std::wstring? You’d have to change the expression on the right, too (npos has the maximum value of the Allocator‘s size_type; implementations are *permitted* –not required– to assume that size_type = std::size_t for all allocators. Thus, in practice, it’s almost always std::size_t but there’s no guarantee.)

  2. typedef std::string string_type ;
    str.find( ... ) == string_type::npos

    Note that if str is actually a data member then you’d better have the typedef in the class.
  3. str.find() >= str.size()

Well, I think that (*) is the best of all these alternatives.

Categories: Idioms

The fate of export

June 12, 2010 1 comment

Eventually they managed to do it: export has been removed from C++0x.

When C++98 was being drafted, the EDG guys were among the opponents of this feature. In the end, it went into the standard and —just guess— EDG turned out to be the only company (ever) to implement it. The implementation work took them about three man-years (one year each —AFAIK William Miller, who is now part of the group, wasn’t there yet).

Then, when Microsoft hired H. Sutter and began to ship a compiler with some minimal consideration of the standard, a paper by H. Sutter himself was presented to the committee which explained to them why export was just not affordable.

That was the very moment (early 2003, IIRC) when I gave up any hope to see export anywhere else than in EDG’s front-end and Comeau C++.

By reading (quickly) some of Herb’s blog it seems that EDG has been explicitly asking for removal of the feature, at least as of late, but other sources seem to be on a different nuance. For instance, Michael Wong simply writes that (see his blog on IBM’s Rational Caf├ęs) “even their [EDG’s] lead is not opposing its [of export] removal”. The differences might simply boil down to an evolution of their opinions… I don’t know and I haven’t verified the dates of the various posts. Or, as a reply on Herb’s blog itself seems to hint at, at differences between “the official EDG position” and e.g. what Daveed Vandevoorde might have expressed about export on the C++ newsgroups. Uh.

In any case, in the current Final Committee Draft for C++0x (n3092) export has been removed.

It would be hard to convince me that there hasn’t been a lot of politics in all this.