C++ Logo

sg10

Advanced search

Re: [SG10] New is_aggregate trait

From: Eric Fiselier <eric_at_[hidden]>
Date: Fri, 31 Mar 2017 02:20:12 -0600
+1 for the feature test macro. What would the value of the macro be?

It's particularly important in this case because the availability of
std::is_aggregate is dependent
on both the compiler version, because a builtin is required, and the STL
version.

/Eric

On Thu, Mar 30, 2017 at 8:14 PM, Agustín Bergé <agustinberge_at_[hidden]>
wrote:

> LWG2911 gave us the new `is_aggregate` trait, but no feature-test macro.
> I would like to suggest `__cpp_lib_is_aggregate`. What follows is a
> motivational use case, courtesy of Jonathan Wakely:
>
> #include <vector>
> template<typename T, typename... Args>
> T make(Args&&... args)
> {
> #if __cpp_lib_is_aggregate
> if constexpr (std::is_aggregate_v<T>)
> return { std::forward<Args>(args)... };
> else
> #endif
> return T(std::forward<Args>(args)...);
> }
> struct Agg { int i; };
> int main()
> {
> auto v = make<std::vector<int>>(1, 2);
> #if __cpp_lib_is_aggregate
> // make<> only supports aggregates if std::is_aggregate is
> available
> auto a = make<Agg>(1);
> #endif
> }
>
> Regards,
> --
> Agustín K-ballo Bergé
> http://talesofcpp.fusionfenix.com
> _______________________________________________
> Features mailing list
> Features_at_[hidden]
> http://www.open-std.org/mailman/listinfo/features
>

Received on 2017-03-31 10:20:13