Date: Wed, 13 Nov 2013 10:04:36 +0000 From: David Chisnall <theraven@FreeBSD.org> To: John Baldwin <jhb@FreeBSD.org> Cc: Eitan Adler <lists@eitanadler.com>, freebsd-current@FreeBSD.org, Steve Kargl <sgk@troutmask.apl.washington.edu> Subject: Re: Are clang++ and libc++ compatible? Message-ID: <9071A5A2-9F8D-4F5A-9EAD-66A680246AFE@FreeBSD.org> In-Reply-To: <201311121321.07330.jhb@freebsd.org> References: <20131112163219.GA2834@troutmask.apl.washington.edu> <20131112165422.GA2939@troutmask.apl.washington.edu> <CAF6rxgmRb3QALsSyVrpR683%2BVzcUnDN0VQja62xn8FTZaRxOKw@mail.gmail.com> <201311121321.07330.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 12 Nov 2013, at 18:21, John Baldwin <jhb@freebsd.org> wrote:
>> struct foo {
>> struct foo bar;
>> }
>
> Except it isn't. It's declaring the head of a container. This is more
> like:
>
> struct foo {
> TAILQ_HEAD(, foo) messages;
> };
Eitan is correct here. The definition of std::deque is that it copies the value that is the template argument and does not require modifications to the layout. A deque is more akin to an array, so in C it would be something like:
struct foo {
struct foo bar[10];
};
This is clearly nonsense - you can't have a structure that contains itself. The same is true for the deque. It's not clear what the pan people actually wanted, but an efficient implementation of a deque would most likely contain space for a small number of the template argument elements, so they are literally defining a structure containing a structure containing the parent structure. The same would be true if they did:
struct Entry {
std::vector<Entry> v;
};
An implementation of the vector class might allocate all of the elements on the heap lazily, but it's not required to and could equally have space for a small number inside the object, expanding to something like this:
struct Entry {
struct MangledNameOfVectorOfEntry {
size_t size;
Entry small[4];
Entry *ptr;
};
};
It would make sense to have a std:deque<Entry&> or std:deque<Entry*>, because then you're only storing references or pointers to the outer structure in the inner structure.
David
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9071A5A2-9F8D-4F5A-9EAD-66A680246AFE>
