public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Nathan Myers <ncm@cantrip.org> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: libstdc++/10783: std::vector::reverse_iterator could be smaller Date: Sun, 18 May 2003 22:46:00 -0000 [thread overview] Message-ID: <20030518224601.1319.qmail@sources.redhat.com> (raw) The following reply was made to PR libstdc++/10783; it has been noted by GNATS. From: Nathan Myers <ncm@cantrip.org> To: Paolo Carlini <pcarlini@unitus.it> Cc: gcc-prs@gcc.gnu.org, Sylvain.Pion@mpi-sb.mpg.de, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: libstdc++/10783: std::vector::reverse_iterator could be smaller Date: Sun, 18 May 2003 15:45:28 -0700 On Sun, May 18, 2003 at 09:35:50PM +0200, Paolo Carlini wrote: > Well, on second thought, and giving justice to the clear > explanation in V&J, in their ?16.2.2 it is clearly stated > that the EBCO has no equivalent for data members: this is > reasonable considering that it would create problems with > the representation of pointers to members. > > Therefore reverse_iterator is expected to have the same > size of its iterator empty base (thanks to EBCO) + the size > of its member current, that is two times the size of a > plain iterator. > > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10783 I agree it would be a Good Thing for the reverse iterators to be the same size as the regular iterators. It seems to me that this is one of those cases where the regular empty-base optimization can't be applied. That is, the ABI forbids it because two base-class subobjects of the same type would have the same type. Often you can get around this sort of thing by giving the base an extra, defaulted, dummy argument, and deriving from a variant, so the two base subobjects that share the same address have different types. I think that doesn't work here because the derivation hierarchy and the argument list to std::iterator<> might be fixed by the standard. We might be able to get around it by giving each container a private iterator type, and then deriving the public iterator type from that, mixing in std::iterator<>. Then the reverse iterator would (be specialized to just contain an instance of the base type, and also mix in std::iterator<>. Another would be simply to derive privately from the regular iterator type and override some members. It would be nice to make a template that does this, so it could be used for all the containers. A tricky way would be to arrange that the addresses of the two base subobjects are at opposite ends of the object: struct empty {}; struct notempty { int i; }; struct iterator : empty { notempty n; }; // sizeof is 4 struct riterator_base { iterator i; }; // has empty at offset 0 struct riterator // has empty at both offsets 0 and 4. : riterator_base, empty {}; // sizeof should still be 4. Unfortunately this doesn't work. sizeof(riterator) is 8. :-( This is probably a result of an unfortunate oversight by the ia64 ABI group. Nathan Myers ncm-nospam@cantrip.org
next reply other threads:[~2003-05-18 22:46 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-05-18 22:46 Nathan Myers [this message] -- strict thread matches above, loose matches on Subject: below -- 2003-05-18 19:36 Paolo Carlini 2003-05-18 18:48 paolo 2003-05-14 15:46 Sylvain.Pion
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20030518224601.1319.qmail@sources.redhat.com \ --to=ncm@cantrip.org \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).