Reputation: 1534
I'm trying to see if it's possible to use a parameter that is not default constructible within a lambda as part of a fold expression. Following code works if T
is default constructible.
template <typename ...T>
struct X
{
void foo()
{
([](const T&)
{
if (sizeof(T) < 4)
{
std::cout << "Small block size: " << sizeof(T) << std::endl;
}
}(T{}), ...);
// Print sizes
((std::cout << sizeof(T) << std::endl), ...);
}
};
struct A {
int a[100];
};
struct B
{
};
int main()
{
X<A,B> x;
x.foo();
}
Output
Small block size: 1
400
1
Upvotes: 0
Views: 42
Reputation: 96791
The lambda doesn't need a parameter:
([]{
if (sizeof(T) < 4)
{
std::cout << "Small block size: " << sizeof(T) << std::endl;
}
}(), ...);
Upvotes: 4