hashtable local iterator
Jonathan Wakely
jwakely.gcc@gmail.com
Mon Dec 19 21:17:00 GMT 2011
On 19 December 2011 21:01, Marc Glisse wrote:
> On Mon, 19 Dec 2011, Jonathan Wakely wrote:
>
>> If you use std::tuple to store the members it will automatically use
>> EBO if possible.
>>
>> If two types might be the same use std::tuple<X,Y,X> where X might be
>> empty and Y is not empty, that ensures the two X objects will not have
>> the same address so can have zero size.
>
>
> I just tried this:
>
> #include <iostream>
> #include <tuple>
> struct A{};
> int main(){
> std::cout << sizeof(std::tuple<A,A,int>) << std::endl;
> std::cout << sizeof(std::tuple<A,int,A>) << std::endl;
> std::cout << sizeof(std::tuple<int,A,A>) << std::endl;
> }
>
> and it output 8, 8 and 4.
> (if I have more than 4 A at the end, the size will increase)
I suppose I should have tested it before making that claim :)
Still, using tuple can use the EBO, even if not always optimally, and
definitely avoids ambiguous base classes if two types can be the same.
If we were writing the library from scratch then all components in
the library that want to exploit the EBO would use the same component,
but for historical reasons many of them don't. For new code there's
no reason to keep reinventing the wheel each time, just use
std::tuple (and when I fix PR 51365 for std::tuple you get the fix for
free.)
More information about the Libstdc++
mailing list