You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Boost.PFR library works with types that satisfy the requirements of SimpleAggregate: aggregate types without base classes, const fields, references, or C arrays:
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.
#include <boost/pfr/tuple_size.hpp>
void function()
{
auto lambda = [](void)mutable{};
using lambda_t = decltype(lambda);
static_assert(0 == boost::pfr::tuple_size_v<lambda_t>);
}
This gives the error:
D:\builds\cm-systest\system\pub\dists\boost\boost/pfr/detail/fields_count.hpp(285): error C2338: static_assert failed: '====================> Boost.PFR: Type must be aggregate initializable.'
D:\builds\cm-systest\system\pub\dists\boost\boost/pfr/tuple_size.hpp(33): note: see reference to function template instantiation 'size_t boost::pfr::detail::fields_count<T>(void) noexcept' being compiled
with
[
T=lambda_t
]
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).
The text was updated successfully, but these errors were encountered:
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).
The text was updated successfully, but these errors were encountered: