How to check whether T is an aggregate type?

后端 未结 1 968
旧时难觅i
旧时难觅i 2021-01-18 12:32

I know about std::is_pod. But it checks more than just aggregate types. Or, is std::is_pod just the best we can do?

Basically, I want to wr

相关标签:
1条回答
  • 2021-01-18 12:58

    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).

    0 讨论(0)
提交回复
热议问题