The following compiles fine, N is implicitly captured in the lambda fn (C++17):
void f()
{
const int N{42};
auto fn = []() { return N; };
}
(https://godbolt.org/z/JpyZHC)
The following does not compile (delay is not captured), and I have a hard time figuring out what the exact reason is. Because delay is not a POD? After reading cppreference.com it seems it has something to do with ODR-usage, but I fail to grasp what the significant difference between N and delay is in terms of ODR-usage. Changing const to constexpr below does not make a difference.
#include <chrono>
#include <thread>
void g()
{
using namespace std::chrono_literals;
const auto delay{42ms};
auto fn = []() { std::this_thread::sleep_for(delay); };
}