On 12 Nov 2013, at 18:21, John Baldwin <jhb_at_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. DavidReceived on Wed Nov 13 2013 - 09:04:44 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:44 UTC