How to check if T is a cumulative type?

I know about std::is_pod . But he checks not only aggregate types. Or, std::is_pod just the best we can do?

Basically, I want to write a function template for this :

 template <typename T> aggregate_wrapper<T> wrap(T&& x); 

which is activated only when T is an aggregate type.

+5
source share
1 answer

Cannot synthesize is_aggregate pattern. The rules of whether something is involved in aggregate initialization cannot be detected by C ++ 14 metaprogramming methods (this will require reflection support).

A common reason for not having this is the lack of a clear need. Even in the case of your wrapper , there is little harm in applying to non-aggregate types, since the syntax syntax can be applied to non-aggregates. You will not make all the transformations explicit , but this is something that can be fixed using clever metaprogramming / enable_if gymnastics.

The most useful place for such a thing would be in allocator::construct , which would allow using aggregate initialization to construct an object if T was an aggregate, and otherwise direct design calls (to avoid the "no" uniform "part of uniform initialization) .

+4
source

Source: https://habr.com/ru/post/1241420/


All Articles