Re:TOML for Modern C++
by rpasquay on Friday February 28, 2020 @02:42AM
(#22441190)
I'm a bit surprised by this snippet from the "Traversing and manipulating data" example:
I thought constexpr would work at compile time but how can the compile here inside a loop "know" when this labmda will encounter an int or a string ?
[ Parent
| on HN ]
It's tricky but I think visit is being passed a generic (templated) lambda, which is statically instantiated for each type that a node might be. (Once for int, once for string, etc) Since the type is static per template instantiation, constexpr works here.
Thank you for the explanation!