[SG10] New is_aggregate trait

Richard Smith richard at metafoo.co.uk
Fri Apr 7 22:19:04 CEST 2017


On 30 March 2017 at 19:14, Agustín Bergé <agustinberge at gmail.com> 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);
>

What does the #else look like here? I'm not yet seeing how this feature
test macro is useful.

     #endif
>      }
>
> Regards,
> --
> Agustín K-ballo Bergé
> http://talesofcpp.fusionfenix.com
> _______________________________________________
> Features mailing list
> Features at isocpp.open-std.org
> http://www.open-std.org/mailman/listinfo/features
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/features/attachments/20170407/eb11e894/attachment.html 


More information about the Features mailing list