Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #80392 > unrolled thread
| Started by | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| First post | 2021-06-14 13:10 +0200 |
| Last post | 2021-06-14 13:16 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.c++
templated lambda issue Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-14 13:10 +0200
Re: templated lambda issue David Brown <david.brown@hesbynett.no> - 2021-06-14 14:23 +0200
Re: templated lambda issue Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-14 14:58 +0200
Re: templated lambda issue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-06-14 15:12 +0200
Re: templated lambda issue MrSpook_5fdc40@qvqo7xsmj4s.co.uk - 2021-06-14 13:16 +0000
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2021-06-14 13:10 +0200 |
| Subject | templated lambda issue |
| Message-ID | <sa7def$tmt$1@dont-email.me> |
int main()
{
auto f = []<typename T>() -> T
{
return 123;
};
f.operator ()<int>(); // only way ?
}
Is the above code the only way to call the lambda ?
[toc] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-06-14 14:23 +0200 |
| Message-ID | <sa7hor$brp$1@dont-email.me> |
| In reply to | #80392 |
On 14/06/2021 13:10, Bonita Montero wrote:
> int main()
> {
> auto f = []<typename T>() -> T
> {
> return 123;
> };
> f.operator ()<int>(); // only way ?
> }
>
> Is the above code the only way to call the lambda ?
You made a templated lambda - you have to give the type /somehow/. What
are you actually trying to do?
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2021-06-14 14:58 +0200 |
| Message-ID | <sa7jp8$vsg$1@dont-email.me> |
| In reply to | #80393 |
>> int main()
>> {
>> auto f = []<typename T>() -> T
>> {
>> return 123;
>> };
>> f.operator ()<int>(); // only way ?
>> }
>>
>> Is the above code the only way to call the lambda ?
> You made a templated lambda - you have to give the type /somehow/.
No, I just want to return a value of that type.
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2021-06-14 15:12 +0200 |
| Message-ID | <sa7kk7$a5c$1@dont-email.me> |
| In reply to | #80392 |
On 14 Jun 2021 13:10, Bonita Montero wrote:
> int main()
> {
> auto f = []<typename T>() -> T
> {
> return 123;
> };
> f.operator ()<int>(); // only way ?
> }
>
> Is the above code the only way to call the lambda ?
I've never used a templated lambda, but if I needed something like that
I think I'd use a type-indicating argument, like (off the cuff)
template< class T > struct Use_type_{ using Type = T; };
auto main() -> int
{
const auto f = []( auto t )
{ return static_cast<decltype(t)::Type>( 123 ); };
return f( Use_type_<int>() );
}
- Alf
[toc] | [prev] | [next] | [standalone]
| From | MrSpook_5fdc40@qvqo7xsmj4s.co.uk |
|---|---|
| Date | 2021-06-14 13:16 +0000 |
| Message-ID | <sa7kr8$1u31$1@gioia.aioe.org> |
| In reply to | #80397 |
On Mon, 14 Jun 2021 15:12:37 +0200
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> wrote:
>On 14 Jun 2021 13:10, Bonita Montero wrote:
>> int main()
>> {
>> auto f = []<typename T>() -> T
>> {
>> return 123;
>> };
>> f.operator ()<int>(); // only way ?
>> }
>>
>> Is the above code the only way to call the lambda ?
>
>I've never used a templated lambda, but if I needed something like that
>I think I'd use a type-indicating argument, like (off the cuff)
>
> template< class T > struct Use_type_{ using Type = T; };
>
> auto main() -> int
Or back in the real world: int main()
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web