--Hi all experts,
boost::compressed_pairis widely used as a replacement forstd::pairin order to save storage when one of the data members is an empty class.The
__compressed_pairhelper class, which is similar toboost::compressed_pair, is also widely used in libc++.I wonder if we could get this compression optimization at almost no cost if add the C++
[[no_unique_address]]attribute to the members ofstd::pair:namespace std { template<class T1, class T2> struct pair { using first_type = T1; using second_type = T2; [[no_unique_address]] T1 first; // <- here [[no_unique_address]] T2 second; // <- here }; }This looks reasonable to me, and almost achieves the equivalent of
boost::compressed_pair.What do you guys think about this? This seems like a great enhancement to me. Or does this kind of practice bring certain issues?
Comments are very welcome.
Hewill
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals