Skip to content

Latest commit

 

History

History
67 lines (54 loc) · 1.51 KB

File metadata and controls

67 lines (54 loc) · 1.51 KB

Generic Lambda {#example_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
}

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