Isn't it about time that lambda functions could be used directly as STL comparitors instead of it being an ugly 2 step process?
ie instead of:
auto comp = [](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
};
map<string,int,decltype(comp)> m(comp);
which is no simpler than just using a functor, why can't we just do:
map<string,int,[](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
}) m;
I'm sure updating the compilers so a lambda could be a template parameter wouldn't be beyond the wit of man.
Rather than adding esoteric functionality no one uses wouldn't it be better to tidy up what there is already?
m;
Am 07.10.2024 um 09:32 schrieb [email protected]:
Isn't it about time that lambda functions could be used directly as STL
comparitors instead of it being an ugly 2 step process?
ie instead of:
auto comp = [](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
};
map<string,int,decltype(comp)> m(comp);
which is no simpler than just using a functor, why can't we just do:
map<string,int,[](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
}) m;
I'm sure updating the compilers so a lambda could be a template parameter
wouldn't be beyond the wit of man.
Rather than adding esoteric functionality no one uses wouldn't it be better >> to tidy up what there is already?
Lambdas can be used in an unevaluated context since C++20, i.e
you could write <, decltype([]( ... ) { })> as you did. Try it
with -std=c++20 / -std:c++29.
which is no simpler than just using a functor, why can't we just do:
map<string,int,[](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
}) m;
I'm sure updating the compilers so a lambda could be a template parameter wouldn't be beyond the wit of man.
[email protected] writes:
which is no simpler than just using a functor, why can't we just do:
map<string,int,[](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
}) m;
I'm sure updating the compilers so a lambda could be a template parameter
wouldn't be beyond the wit of man.
The reason we cannot do that is because the third parameter to std::map is a >type, and not an object. A lambda expression is an instance of an anonymous >type, and not a type in of itself.
Isn't it about time that lambda functions could be used directly as STL comparitors instead of it being an ugly 2 step process?
ie instead of:
auto comp = [](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
};
map<string,int,decltype(comp)> m(comp);
which is no simpler than just using a functor, why can't we just do:
map<string,int,[](const string &s1, const string &s2)
{
return strcasecmp(s1.c_str(),s2.c_str()) < 0;
}) m;
I'm sure updating the compilers so a lambda could be a template parameter wouldn't be beyond the wit of man.
Am 07.10.2024 um 16:06 schrieb [email protected]:
Its a definition, not a value, ...
Wrong, a lambda is a PR-value.
Am 07.10.2024 um 16:53 schrieb [email protected]:
On Mon, 7 Oct 2024 16:13:48 +0200
Bonita Montero <[email protected]> boring babbled:
Am 07.10.2024 um 16:06 schrieb [email protected]:
Its a definition, not a value, ...
Wrong, a lambda is a PR-value.
I don't see why it can't be cast to std::function. It is a function after >all.
Of course you can cast it to a compatible function, i.e. the parmeters
of the lambda and the parameter supplied to the function must match.
Am 07.10.2024 um 17:46 schrieb [email protected]:
The compiler knows exactly what the parameters are. ..
The parameters of a function-object must be convertible to
those of the lambda. That's all.
Am 08.10.2024 um 10:23 schrieb [email protected]:
So make it convertable. I find it perverse that the declaration of a struct/ >> class and the declaration of a function/lambda are considered different types
of declarations. ..
In one case you have a variable-_defintiion_, in the other a declaration.
On Mon, 07 Oct 2024 07:35:34 -0400
Sam <[email protected]> boring babbled:
The reason we cannot do that is because the third parameter to std::map is a >type, and not an object. A lambda expression is an instance of an anonymous >type, and not a type in of itself.
Its a definition, not a value, so why can't it silently be converted internally
by the compiler? Presumably it does just that when it sees decltype anyway.
[email protected] writes:
On Mon, 07 Oct 2024 07:35:34 -0400
Sam <[email protected]> boring babbled:
The reason we cannot do that is because the third parameter to std::map is a
type, and not an object. A lambda expression is an instance of an anonymous >> >type, and not a type in of itself.
Its a definition, not a value, so why can't it silently be converted
internally
by the compiler? Presumably it does just that when it sees decltype anyway.
Because it's not the compiler's job to invent new templates. If there was an
On Tue, 08 Oct 2024 08:25:33 -0400
Sam <[email protected]> boring babbled:
Because it's not the compiler's job to invent new templates. If there was an
Its the compilers job to interpret the template. Given the semantic hoops, gotchas,hacks and generalinconsistencies C++ already has, another one that might actually be useful isn't going to hurt.
[email protected] writes:
On Tue, 08 Oct 2024 08:25:33 -0400
Sam <[email protected]> boring babbled:
Because it's not the compiler's job to invent new templates. If there was an
Its the compilers job to interpret the template. Given the semantic hoops, >> gotchas,hacks and generalinconsistencies C++ already has, another one that >> might actually be useful isn't going to hurt.
Hm, I'm beginning to think you're right. After all, C++ has always had a >reputation of being too simplistic, straightforward, and easy to learn and >understand. It's about time some complexity was added to the language.
[email protected] writes:
On Tue, 08 Oct 2024 08:25:33 -0400
Sam <[email protected]> boring babbled:
Because it's not the compiler's job to invent new templates. If there was an
Its the compilers job to interpret the template. Given the semantic hoops, >> gotchas,hacks and generalinconsistencies C++ already has, another one that >> might actually be useful isn't going to hurt.
Hm, I'm beginning to think you're right. After all, C++ has always had a >reputation of being too simplistic, straightforward, and easy to learn and >understand. It's about time some complexity was added to the language.
Am 09.10.2024 um 09:15 schrieb [email protected]:
I happen to think the removal of the need for decltype() would actually
simplify things. ...
It wouldn't make sense since a lambda is a pr-_value_ !
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 37:30:50 |
| Calls: | 12,109 |
| Files: | 15,006 |
| Messages: | 6,518,371 |