2911. An is_aggregate type trait is needed

Section: 21.3.5.4 [meta.unary.prop] Status: C++17 Submitter: United States Opened: 2017-02-03 Last modified: 2020-09-06

Priority: Not Prioritized

View other active issues in [meta.unary.prop].

View all other issues in [meta.unary.prop].

View all issues with C++17 status.

Discussion:

Addresses US 143

An is_aggregate type trait is needed. The emplace idiom is now common throughout the library, but typically relies on direct non-list initalization, which does not work for aggregates. With a suitable type trait, we could extend direct non-list-initlaization to perform aggregate-initalization on aggregate types.

Proposed change:

Add a new row to Table 38:

template <class T>
struct is_aggregate;

T is an aggregate type ([dcl.init.aggr])

remove_all_extents_t<T> shall be a complete type, an array type, or (possibly cv-qualified) void.

[2017-02-26, Daniel comments and completes wording]

The proposed wording is incomplete, since it doesn't update the <type_traits> header synopsis, also ensuring that the corresponding is_aggregate_v variable template is defined.

[2017-03-01, Daniel comments and adjusts wording]

There is only one minor change performed, namely to mark the constant in the is_aggregate_v variable template as inline following the LWG preferences for "full inline" bullet list (B2) from P0607R0.

[2017-03-03, Kona, LEWG]

No interest in doing the is-list-initializable instead. No objection to getting that proposal also.

Want this for C++17?

SF | F | N | A | SA

2 | 8 | 1 | 3 | 0

Want this for C++20?

SF | F | N | A | SA

6 | 5 | 2 | 0 | 0

Remember to correct the wording to: "remove_all_extents_t<T> shall be a complete type or cv-void."

[2017-03-03, Daniel updates wording]

In sync with existing writing, this was changed to "remove_all_extents_t<T> shall be a complete type or cv void"

[Kona 2017-03-02]

Accepted as Immediate to resolve NB comment.

This will require a new complier intrinsic; Alisdair checked with Core and they're OK with that

Proposed resolution:

This wording is relative to N4640.

  1. Modify 21.3.3 [meta.type.synop], <type_traits> header synopsis, as indicated:

    // 20.15.4.3, type properties
    […]
    template <class T> struct is_final;
    template <class T> struct is_aggregate;
    
    […]
    // 20.15.4.3, type properties
    […]
    template <class T> constexpr bool is_final_v
      = is_final<T>::value;
    template <class T> inline constexpr bool is_aggregate_v
      = is_aggregate<T>::value;
    […]
    
  2. Add a new row to Table 42 — "Type property predicates":

    template <class T> struct is_aggregate;
    

    T is an aggregate type (9.4.2 [dcl.init.aggr])

    remove_all_extents_t<T> shall be a complete type or cv void.