From 2536006594205888876
X-Google-Thread: f78e5,3c7d746be594880e
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII
Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!msrn-out!msrn-in!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: "Greg Herlihy" <greghe@pacbell.net>
Newsgroups: comp.std.c++
Subject: Re: Concerning n2157 and is_empty specification
Date: Tue, 13 Mar 2007 12:14:02 CST
Organization: http://groups.google.com
Lines: 90
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <1173805078.208591.62140@v33g2000cwv.googlegroups.com>
References: <1173648852.230192.11800@p10g2000cwp.googlegroups.com>
   <howard.hinnant-B96105.15010612032007@johnf2.biosci.ohio-state.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1173805083 8063 127.0.0.1 (13 Mar 2007 16:58:03 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 13 Mar 2007 16:58:03 +0000 (UTC)
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: v33g2000cwv.googlegroups.com; posting-host=71.141.241.225;
   posting-account=JdllFQ0AAAC-QghphnHMZz5q0GHnzGUJ
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
X-MIME-Autoconverted: from quoted-printable to 8bit by mulga.csse.unimelb.edu.au id l2DGw9CS029655
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Xref: g2news1.google.com comp.std.c++:7998

On Mar 12, 12:21 pm, howard.hinn...@gmail.com (Howard Hinnant) wrote:
> In article <1173648852.230192.11...@p10g2000cwp.googlegroups.com>,
>  "Daniel Kr�gler" <daniel.krueg...@googlemail.com> wrote:

> > Just recently I stumbled once again since a longer
> > time across chapter 16.2.1 of the first edition of
> > "C++ Templates" from Vandevoorde/Josuttis, which
> > explains the Empty Base Class Optimization (EBCO)
> > principle as well as its limits.
> > One interesting example is given, which must necessarily
> > forbid EBCO:
>
> > class Empty {
> > };
>
> > class EmptyToo : public Empty {
> > };
>
> > class NonEmpty : public Empty, public EmptyToo {
> > };
> > > The revised wording in n2157, found at
>
> >http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2157.html
>
> > does *not* exclude the above NonEmpty class from
> > is_empty categorization, because it says:
>
> > "    template <class T> struct is_empty : public
> > integral_constant<bool, b> {};
>
> > If is_class<T>::value is false then b is false. Otherwise T is
> > considered empty if and only if:
>
> >     * T has no non-static data members, or all non-static data
> > members, if any, are bit-fields of length 0, and
> >     * T has no virtual members, and
> >     * T has no virtual base classes, and
> >     * T has no base classes B for which is_empty<B>::value is false.
>
> > Requires: T shall be a complete type, an array type of unknown bounds,
> > or is a void type."
>
> > Now I wonder whether this is (a) an oversight in the is_empty
> > specification or (b) a deliberate design decision?
>
> It is an oversight.  This was an attempt to give meaning to "empty
> class".  Note the (marked out) definition it is replacing.  
> Unfortunately "empty class" isn't defined elsewhere in the standard,
> though the phrase is occasionally used.

According to the Vandevoorde/Josuttis book, an empty class object is
one "[whose] internal representation does not require any bits of
memory at run time." So by the book's own definition of "empty",
"NonEmpty" is an empty class - which it obviously is. After all,
NonEmpty has the same zero bits of runtime information content as each
of its two base classes either singly or combined.

Logically there is no connection between the Empty Base Class
Optimization and the "emptiness" of the complete class whose
subobjects to which it is applied. The EBC optimization applies to any
class (empty or non-empty) that has an empty base class. So the
conclusion that NonEmpty is not an empty class is a complete non-
sequitur. It seems that authors lost sight of the fact that the very
compact name, "NonEmpty", describes a "Non-(Empty-base-class-
optimized)" class object and not a "Non-Empty" class object - a
description which its name more closely resembles.

The NonEmpty example is in fact doubly misleading. Because (somewhat
paradoxically) a NonEmpty base class is still eligible for the empty
base class optimzation - and may in fact contribute zero bytes to the
size of subclass object (thereby affirming for a second time that
NonEmpty is an empty class). The only stipulation is that the size of
the derived class on its own (that is, without the NonEmpty base
class) would be at least equal to the size of a NonEmpty object.

So whether defined by its zero bits of information or by the zero
bytes of incremental storage - it's clear that the "oversight" and
(unsuccessful) attempt to define an "empty" class is found in the "C++
Templates" book and not in the proposed wording for is_empty<> type
trait - which is accurate in its current wording.

Greg


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



