Generic Lambda
int
main
()
{
// Generic lambdas have a method template call operator.
auto
x = [](
auto
x) {
return
x * x; };
x(2);
// int
x(3.0);
// double
}
main
int main()
Definition
OptionDocumentationGenerator.cpp:46
Here is the transformed code:
int
main
()
{
class
__lambda_4_14
{
public
:
template
<
class
type_parameter_0_0>
inline
/*constexpr */
auto
operator()(type_parameter_0_0 x)
const
{
return
x * x;
}
#ifdef INSIGHTS_USE_TEMPLATE
template
<>
inline
/*constexpr */
int
operator()<
int
>(
int
x)
const
{
return
x * x;
}
#endif
#ifdef INSIGHTS_USE_TEMPLATE
template
<>
inline
/*constexpr */
double
operator()<
double
>(
double
x)
const
{
return
x * x;
}
#endif
private
:
template
<
class
type_parameter_0_0>
static
inline
/*constexpr */
auto
__invoke(type_parameter_0_0 x)
{
return
__lambda_4_14{}.operator()<type_parameter_0_0>(x);
}
};
__lambda_4_14 x = __lambda_4_14{};
x.operator()(2);
x.operator()(3.0);
return
0;
}
Live view
Generated by
1.9.8