最佳答案
libstdc++'s implementation of pair has the following oddity
template<typename, typename> class __pair_base
{
template<typename T, typename U> friend struct pair;
__pair_base() = default;
~__pair_base() = default;
__pair_base(const __pair_base&) = default;
__pair_base& operator=(const __pair_base&) = delete;
};
template<typename T, typename U>
struct pair
: private __pair_base<T, U>
{ /* never uses __pair_base */ };
__pair_base
is never used, neither can it, considering it's empty. This is particularly confusing since std::pair
is required to be conditionally structural
pair<T, U>
is a structural type ifT
andU
are both structural types.
And having private bases makes it non-structural.