Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #117606
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Do you like that ? |
| Date | 2023-11-05 21:42 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87a5rr6fo2.fsf@bsb.me.uk> (permalink) |
| References | <ui8p3t$3rpn$1@raubtier-asyl.eternal-september.org> <20231105115656.935@kylheku.com> |
Kaz Kylheku <864-117-4973@kylheku.com> writes:
> On 2023-11-05, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> using XHANDLE = std::unique_ptr<void, decltype([]( void *h ) { h !=
>> INVALID_HANDLE_VALUE && h && CloseHandle( h ); })>;
>>
>> A Win32 HANDLE-wrapper in just one line in C++20.
>> C++20 allows lambdas in an unevaluated context.
>
> So what?
>
> 1960 Lisp allows lambdas in unevaluated context.
>
> (QUOTE (LAMBDA (H)
> (AND (NOT (INVALIDHANDLE H))
> (CLOSEHANDLE H))))
>
> This is just C++ catching up to something that existed when
> Stroustrup was in elementary school.
I was going to say the usage here is not a good look for C++. As a
language with compile-time type checking why is decltype needed? It's
usually because C++ can't express the type involved any other way and
that's not something to shout about.
But then it turns out I don't know what's going on. This program:
#include <iostream>
#include <memory>
using uptr_int = std::unique_ptr<int, decltype([](int *ip) {
std::cout << "delete (" << *ip << ")\n";
})>;
int main()
{
int x = 42;
uptr_int ip(&x);
}
prints "delete (42)". Why? I thought decltype was just being used to
give a type for the std::unique_ptr template instantiation, but it seems
to supply the function too. What's going on?
Having used C++ from the early CFront days, and watched balloon in size
and complexity, I knew the day would come when even a short C++ program
would be mystery to me. That day has come!
--
Ben.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Do you like that ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-11-05 20:06 +0100
Re: Do you like that ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-11-05 20:02 +0000
Re: Do you like that ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-05 21:42 +0000
Re: Do you like that ? David Brown <david.brown@hesbynett.no> - 2023-11-05 23:09 +0100
Re: Do you like that ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-11-06 09:33 +0100
Re: Do you like that ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-11-06 17:50 +0000
Re: Do you like that ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-11-06 19:01 +0100
Re: Do you like that ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-11-06 18:59 +0000
Re: Do you like that ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-11-06 20:07 +0100
Re: Do you like that ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-11-06 19:10 +0000
Re: Do you like that ? David Brown <david.brown@hesbynett.no> - 2023-11-07 08:57 +0100
Re: Do you like that ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-06 12:17 -0800
csiph-web