public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Problems with lambda implementation
@ 2009-09-10 19:45 Sergey Sadovnikov
  2009-09-13  0:11 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Sergey Sadovnikov @ 2009-09-10 19:45 UTC (permalink / raw)
  To: gcc

Hello,

Recently I made some tests with lambda (mingw build) I found some
problems. Here they are:

1. Lambda and template type deduction.

Try this sample:

#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

typedef std::function<double(double)> FnType;

template<typename T>
FnType average_damp(T fn)
{
    return [fn](double x) {return (x + fn(x)) / 2;};
}

int main(int argc, char* argv[])
{
    auto fn = average_damp([](double x){return x * 2;});

    std::cout << fn(10.0) << std::endl;

    return 0;
}

This sample successfully built with VS 2010, but under gcc there are
some compilation errors:
P:\projects\Tests\Sandbox\C++0x\gcc43>g++ -std=c++0x -Os -IP:\Projects\common\boost_1.36.0 lambda.cpp
In file included from s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/functional:70:0,
                 from lambda.cpp:4:
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional: In static member function 'static void std::_F
unction_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::false_type) [with _Functor
= average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)>]::<lambda>(doubl
e), std::false_type = std::integral_constant<bool, false>]':
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional:1543:8:   instantiated from 'static bool std::_
Function_base::_Base_manager<_Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [wit
h _Functor = average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)>]::<la
mbda>(double)]'
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional:2013:6:   instantiated from 'std::function<_Res
(_ArgTypes ...)>::function(_Functor, typename __gnu_cxx::__enable_if<(! std::is_integral::value), std::function<_Res(_Ar
gTypes ...)>::_Useless>::__type) [with _Functor = average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType
= std::function<double(double)>]::<lambda>(double), _Res = double, _ArgTypes = double, typename __gnu_cxx::__enable_if<(
! std::is_integral::value), std::function<_Res(_ArgTypes ...)>::_Useless>::__type = std::function<double(double)>::_Usel
ess]'
lambda.cpp:11:51:   instantiated from 'FnType average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = st
d::function<double(double)>]'
lambda.cpp:16:55:   instantiated from here
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional:1507:4: error: no matching function for call to
 'average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)>]::<lambda>(doubl
e)::__lambda0(average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)>]::<l
ambda>(double)&)'
lambda.cpp:11:25: note: candidates are: average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::fun
ction<double(double)>]::<lambda>(double)
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional: In static member function 'static void std::_F
unction_base::_Base_manager<_Functor>::_M_init_functor(std::_Any_data&, const _Functor&, std::false_type) [with _Functor
 = average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)>]::<lambda>(doub
le), std::false_type = std::integral_constant<bool, false>]':
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional:1555:4:   instantiated from 'static void std::_
Function_base::_Base_manager<_Functor>::_M_init_functor(std::_Any_data&, const _Functor&) [with _Functor = average_damp(
T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)>]::<lambda>(double)]'
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional:2014:6:   instantiated from 'std::function<_Res
(_ArgTypes ...)>::function(_Functor, typename __gnu_cxx::__enable_if<(! std::is_integral::value), std::function<_Res(_Ar
gTypes ...)>::_Useless>::__type) [with _Functor = average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType
= std::function<double(double)>]::<lambda>(double), _Res = double, _ArgTypes = double, typename __gnu_cxx::__enable_if<(
! std::is_integral::value), std::function<_Res(_ArgTypes ...)>::_Useless>::__type = std::function<double(double)>::_Usel
ess]'
lambda.cpp:11:51:   instantiated from 'FnType average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = st
d::function<double(double)>]'
lambda.cpp:16:55:   instantiated from here
s:/programming/mingw/lib/gcc/../../include/c++/4.5.0/tr1_impl/functional:1584:4: error: no matching function for call to
 'average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)>]::<lambda>(doubl
e)::__lambda0(const average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::function<double(double)
>]::<lambda>(double)&)'
lambda.cpp:11:25: note: candidates are: average_damp(T) [with T = main(int, char**)::<lambda>(double), FnType = std::fun
ction<double(double)>]::<lambda>(double)

What's wrong?

2. Lambdas and result_of or something similar.

How I can determine return type of lambda in compile time? As far as I
could understood there is no way to do so. Is it right?

-- 
Best Regards,
 Sergey                          mailto:flex_ferrum@artberg.ru



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problems with lambda implementation
  2009-09-10 19:45 Problems with lambda implementation Sergey Sadovnikov
@ 2009-09-13  0:11 ` Jason Merrill
  2009-09-13  5:26   ` Jason Merrill
  2009-09-15 19:47   ` Re[2]: " Сергей Садовников
  0 siblings, 2 replies; 4+ messages in thread
From: Jason Merrill @ 2009-09-13  0:11 UTC (permalink / raw)
  To: Sergey Sadovnikov; +Cc: gcc

On 09/10/2009 03:45 PM, Sergey Sadovnikov wrote:
> 1. Lambda and template type deduction.

A patch I've been holding off on committing happens to fix this bug. 
This is surprising, as I thought it was just a code cleanup.  I guess 
I'll go ahead and commit it soon.

> 2. Lambdas and result_of or something similar.
>
> How I can determine return type of lambda in compile time? As far as I
> could understood there is no way to do so. Is it right?

Use decltype?

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problems with lambda implementation
  2009-09-13  0:11 ` Jason Merrill
@ 2009-09-13  5:26   ` Jason Merrill
  2009-09-15 19:47   ` Re[2]: " Сергей Садовников
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2009-09-13  5:26 UTC (permalink / raw)
  Cc: Sergey Sadovnikov, gcc

On 09/12/2009 08:11 PM, Jason Merrill wrote:
> On 09/10/2009 03:45 PM, Sergey Sadovnikov wrote:
>> 1. Lambda and template type deduction.
>
> A patch I've been holding off on committing happens to fix this bug.
> This is surprising, as I thought it was just a code cleanup. I guess
> I'll go ahead and commit it soon.

Done.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re[2]: Problems with lambda implementation
  2009-09-13  0:11 ` Jason Merrill
  2009-09-13  5:26   ` Jason Merrill
@ 2009-09-15 19:47   ` Сергей Садовников
  1 sibling, 0 replies; 4+ messages in thread
From: Сергей Садовников @ 2009-09-15 19:47 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc

Hello, Jason.

Sunday, September 13, 2009 at 4:11:03 AM you wrote:

>> 1. Lambda and template type deduction.

JM> A patch I've been holding off on committing happens to fix this bug. 
JM> This is surprising, as I thought it was just a code cleanup.  I guess 
JM> I'll go ahead and commit it soon.

>> 2. Lambdas and result_of or something similar.
>>
>> How I can determine return type of lambda in compile time? As far as I
>> could understood there is no way to do so. Is it right?

JM> Use decltype?

Thanks. I'll try it.

-- 
Best Regards,
 цЁц┘ц▓ц┤ц┘ц┼                          mailto:flex_ferrum@artberg.ru



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-09-15 19:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-10 19:45 Problems with lambda implementation Sergey Sadovnikov
2009-09-13  0:11 ` Jason Merrill
2009-09-13  5:26   ` Jason Merrill
2009-09-15 19:47   ` Re[2]: " Сергей Садовников

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).