Open jonesmz opened 1 year ago
Lambdas are not aggregate types. See: https://eel.is/c++draft/expr.prim.lambda.closure#3
Definitely it will not work with lambdas :) Nobody discovered such technique
(These hacks are listed because if someone wants to experiment with lambdas):
It can check that it is layout compatible with a type list:
int a;
bool c;
auto xx = [a, c] {};
using type = decltype(xx);
struct CC {
int x;
bool y;
};
static_assert(std::is_layout_compatible_v<type, CC>);
Compiler and lambda-specific member getters: GCC uses public variables with double underscore.
int a;
auto l = [a] {};
int& lambda_a = l.__a;
MSVC uses the same named private variables :
int a;
auto l = [a] {};
// somehow get the &decltype(l)::a , ex: https://github.com/martong/access_private
Hi, I see in the Limitations section
A casual reader may have seen on the internet "Lambdas are just syntax sugar around a struct with
operator()
", and expect that Boost.PFR would be able to introspect the types of the capture list of a lambda, since they are "just structs".Sadly, this does not appear to work in Boost.PFR.
This gives the error:
on the visual studio 2022 compiler, with similar errors on clang 16. (Both in C++17 mode, if that makes a difference).
I think it might be helpful for people searching for libraries to do introspection if you clearly document that lambdas are or are not supported in the Limitations section, with a brief explanation of why not (e.g. not aggregate types, because compiler-magic).