I ran into a problem because
std::is_trivially_default_constructible<std::pair<T1,T2>>::value == false;
even if
std::is_trivially_default_constructible<T1>::value == true;
std::is_trivially_default_constructible<T2>::value == true;
I failed to find a good reason for this design. Wouldn't it appropriate for std::pair<T1,T2> to have a =default constructor if T1 and T2 have?
Is there a simple work around (simpler than defining my own pair<>)?
The simple reason is: history! The original std::pair<T0, T1> couldn't have a trivial default constructor as it had some other constructor. It was defined to initialize its members. Changing this behavior in std::pair<T0, T1> for trivially constructable types where people rely on the value getting initialized would be a breaking change.
In addition to the history reason, the default constructor of std::pair<...> is defined to be a constexpr constructor. A constexpr default constructor cannot be defaulted.
I'm not aware of a work-around other than creating a custom class.
Default constructor of std::pair value-initializes both elements of the pair, first and second, so it can't be trivial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With