I tried to make std::pair
with this style:
#include <iostream>
struct A {
A() noexcept {
std::cout << "Created\n";
}
A(const A&) noexcept {
std::cout << "Copy\n";
}
A(A&&) noexcept {
std::cout << "Move\n";
}
};
int main() {
std::pair<A, A> a{ {},{} };
return 0;
}
and got such output:
Created
Created
Copy
Copy
instead of
Created
Created
Move
Move
But if I define my anonymous object type (e.g. std::pair<A, A> a{A{}, A{}}
)
or use std::make_pair<A, A>({}, {})
I get right result.
std::pair
constructor must use std::forward<U1>
and std::forward<U2>
to initialize objects, thus I think that my pair uses wrong constructor. Why?