
On Jun 14, 2006, at 5:04 PM, Gottlob Frege wrote:
Actually, after thinking about it a bit, I'm now tempted to say a 5 byte buffer should have 1 byte alignment. eg (given a typical platform):
struct test_alignment { int x; char y; };
<snip>
So, If sizeof(test_alignment) == 5, then the alignment must really be 1 (ie there is probably a pragma pack(1) in play).
Sure. Another way of stating it is that if alignment of test_alignment is 1, sizeof must be 5. However if the alignment of test_alignment is 4, then its sizeof must be 8 (on a typical desktop platform). On my system sizeof(test_alignment) is 8. The alignment and sizeof test_alignment is what it is for a given platform, and neither the standard nor the type_traits lib is going to change that. What the type_traits lib can do is help report those facts.
Also, in any case, for boost::type_with_alignment<5> doesn't compile. I think it should at least do something (or else the standard/docs need to have lots of wording explaining which ints work and which do not).
Similarly, aligned_storage has the same 'problem' and basically only works with alignment_of (or something that does the same thing).
I think failing to compile is exactly what should happen for unsupported alignments. Requesting an unsupported alignment is an error, and finding out at compile time is a feature, not a bug.
Since that is the case anyhow, I would suggest that aligned_storage be replaced with:
storage_for
; (which can be written in terms of aligned_storage and alignment_of, but since the two are tied together, and typically used together, why not just supply what is really wanted).
So really I'd like:
storage_for_type
and storage_for_size where storage_for_size determines the minimum necessary alignment based on the size, as discussed.
<shrug> storage_for_type