There is no way to synthesize an is_aggregate
template. The rules for whether something participates in aggregate initialization cannot be detected by C++14 metaprogramming techniques (they would require reflection support).
The general reason for not having this is the lack of an explicit need. Even in the case of your wrapper, there's little harm in applying it to non-aggregate types, since uniform initialization syntax can be applied to non-aggregates. You'll make all conversions non-explicit
, but that's something which can be fixed via clever metaprogramming/enable_if
gymnastics.
The most useful place for such a thing would be in allocator::construct
, which would allow you to use aggregate initialization to construct the object if T
were an aggregate, while using direct constructor calls otherwise (to dodge the "not uniform" part of uniform initialization).
is_aggregate
. E.g. it doesn't help with serialization. – Prefacememcpy
is safe, then you wantstd::is_trivially_copyable
. – Morinwrap()
function template for this, which is only enabled ifT
is an aggregate type. – Timotheastd::is_object
orstd::is_compound
not meet your needs? – Damnation{}
, but not()
. – Timotheastd::is_aggregate
. – Elyn