Why does the following code compile?
#include <memory>
#include <vector>
int main()
{
std::vector<std::unique_ptr<int>> uncopyableStuff;
for(int i = 0; i < 5; ++i)
uncopyableStuff.emplace_back(std::make_unique<int>(i));
auto lambda = [uncopyableStuff = std::move(uncopyableStuff)](){};
static_assert(std::is_copy_constructible<decltype(lambda)>::value);
}
It seems to me that lambda is uncopyable, because when I try to copy it like:
auto copy = lambda;
This gives me a compile error (as I would expect). Is there some exception for lambda's and copy constructability traits?
See link for godbolt example: https://godbolt.org/z/GByclH
EDIT:
What is the correct way to find out whether a lambda will compile when attempted to copy. I geuss I'm not interested in the theoretical copy constructibility of a given callable, but a detection of successful copy construction. It still seems very strange to me that the vector copy constructor is defined in this way.