C++ Logo

std-discussion

Advanced search

Are pairs/tuples of arrays legitimate?

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Tue, 8 Jun 2021 05:29:57 +0200
Hi,

I'm wondering if something like std::pair<int[2], X> is "legitimate".
[pairs] doesn't seem to require anything special from its members, and
all implementations accept it. The resulting type behaves in a strange way:

1) It is copyable because pair's copy constructor is defaulted, and the
copy is "structural" (the array is deep copied).

2) It is not copy-assignable because pair's copy assignment operator is
declared as deleted unless both members are copy assignable (which they
aren't). If the copy assignment operator were simply defaulted, then it
would copy-assign structurally. P1997 may change this, yet this
asymmetry sounds weird...

3) operator== is not defaulted; its specification says to compare each
member with operator==. This means that it'll decay the array member to
a pointer, and compare the pointers; as a consequence, copy of a pair
would never compare equal to the original. It also means that the
comparison operators cannot be replaced with, say, a defaulted
operator<=> (which would again be structural).

Am I missing something?

(I understand that some of these quirks are historical and are
unfortunately kept to avoid breaking ABI, but maybe one may want to ban
the usage of arrays altogether.)

Thanks,
-- 
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2021-06-07 22:30:09