C++ Logo

std-proposals

Advanced search

Re: User-defined conversion for strongly

From: Michael Hava <mfh_at_[hidden]>
Date: Mon, 13 Apr 2020 14:56:10 +0000
In my (arguably limited) view metaclasses are a means to generate class definitions based on a meta-program instead of relying on an external code generators.
IMHO: No language feature should be limited to metaclasses and everything metaclasses can do, regular code should be able to do aswell.

Given that almost all operators are already overloadable(*) for enums as free functions, I guess it's really a matter of special casing "special member functions" and conversion operators.



(*) For reference, operators you can't currently overload for enums: =, [], ->, (), T()
For some of these I'd have to find the rationale of why they can't be free functions myself...

> -----Original Message-----
> From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of
> David Ledger via Std-Proposals
> Sent: Tuesday, April 7, 2020 2:19 AM
> To: std-proposals_at_[hidden]
> Cc: David Ledger <DavidLedger_at_[hidden]>
> Subject: Re: [std-proposals] User-defined conversion for strongly
>
> I like the idea of supporting member functions with C++.
> Would meta-classes allow this functionality with an enum-like object?
>
> -----Original Message-----
> From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of
> std-proposals-request_at_[hidden]
> Sent: 7 April 2020 12:59 AM
> To: std-proposals_at_[hidden]
> Subject: Std-Proposals Digest, Vol 13, Issue 2
>
> Send Std-Proposals mailing list submissions to
> std-proposals_at_[hidden]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
> lists.isocpp.org%2Fmailman%2Flistinfo.cgi%2Fstd-
> proposals&amp;data=02%7C01%7C%7C623a67fd43154889187108d7da3aad83
> %7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637217817860600116
> &amp;sdata=Ffa7BapqxpP81LqJ5NcCfpfmp6cuMwz7KjzA2tMPxsM%3D&amp;r
> eserved=0
> or, via email, send a message with subject or body 'help' to
> std-proposals-request_at_[hidden]
>
> You can reach the person managing the list at
> std-proposals-owner_at_[hidden]
>
> When replying, please edit your Subject line so it is more specific than "Re:
> Contents of Std-Proposals digest..."
>
>
> Today's Topics:
>
> 1. Re: User-defined conversion for strongly typed enums (Zhihao Yuan)
> 2. Re: User-defined conversion for strongly typed enums
> (Micha? Policht)
> 3. Re: User-defined conversion for strongly typed enums
> (Przemek Kozio?)
> 4. Re: User-defined conversion for strongly typed enums
> (Micha? Policht)
> 5. Re: User-defined conversion for strongly typed enums
> (Michael Hava)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 06 Apr 2020 03:02:59 +0000
> From: Zhihao Yuan <zy_at_[hidden]>
> To: "std-proposals_at_[hidden]" <std-proposals_at_[hidden]>
> Subject: Re: [std-proposals] User-defined conversion for strongly
> typed enums
> Message-ID:
> <0XRDJWL_7uME-
> fJDz3WWg9WOf7ppuflE8zbVJtmOP3t5CFi8Bn6ZoFS7KagajpfjWYXoKtxQNmyKAl
> hLuyoLltIKs5HsrsvM0v0C6CkbZBE=_at_[hidden]>
>
> Content-Type: text/plain; charset="utf-8"
>
> On Saturday, April 4, 2020 3:17 PM, Przemek Kozio? via Std-Proposals <std-
> proposals_at_[hidden]> wrote:
>
> > Strongly typed enums provide type safety.
> >
> > I believe, however, the programmer should have an option to define explicit
> conversions to the desired types.
>
> I believe enum class should support
> member functions.
>
> --
> Zhihao Yuan, ID lichray
> The best way to predict the future is to invent it.
> _______________________________________________
> -------------- next part --------------
> HTML attachment scrubbed and removed
>
> ------------------------------
>
> Message: 2
> Date: Mon, 6 Apr 2020 14:23:37 +0200
> From: Micha? Policht <michal_at_[hidden]>
> To: std-proposals_at_[hidden]
> Subject: Re: [std-proposals] User-defined conversion for strongly
> typed enums
> Message-ID: <8ce37859-7b78-3eaf-8bb1-d34ff189414a_at_[hidden]>
> Content-Type: text/plain; charset=utf-8
>
>
> > class X {
> > public:
> > ? ? struct ID {
> > ? ? ? ? enum {
> > ? ? ? ? ? ? NAME = 0x0,
> > ? ? ? ? ? ? SIZE = 0x2,
> > ? ? ? ? };
> > ? ? };
> >
>
> An what's wrong with the above? I'd rather go in that direction and try to
> unify all C++ constructs instead of introducing enum-specific syntax.
>
> Regards,
> Micha?
>
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 6 Apr 2020 14:29:45 +0200
> From: Przemek Kozio? <przemkoz85_at_[hidden]>
> To: std-proposals_at_[hidden]
> Subject: Re: [std-proposals] User-defined conversion for strongly
> typed enums
> Message-ID:
> <CAALK0dSYBE5Q+_NJ9dfdEdAgvKxTPEFNMSgM-
> 20Gn3Py4U7KTA_at_[hidden]>
> Content-Type: text/plain; charset="utf-8"
>
> I think the main purpose of a struct is not name scoping.
>
> On Mon, Apr 6, 2020 at 2:23 PM Micha? Policht via Std-Proposals < std-
> proposals_at_[hidden]> wrote:
>
> >
> > > class X {
> > > public:
> > > struct ID {
> > > enum {
> > > NAME = 0x0,
> > > SIZE = 0x2,
> > > };
> > > };
> > >
> >
> > An what's wrong with the above? I'd rather go in that direction and
> > try to unify all C++ constructs instead of introducing enum-specific syntax.
> >
> > Regards,
> > Micha?
> >
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
> > s.isocpp.org%2Fmailman%2Flistinfo.cgi%2Fstd-
> proposals&amp;data=02%7C01
> >
> %7C%7C623a67fd43154889187108d7da3aad83%7C84df9e7fe9f640afb435aaaa
> aaaaa
> >
> aaa%7C1%7C0%7C637217817860600116&amp;sdata=Ffa7BapqxpP81LqJ5NcCf
> pfmp6c
> > uMwz7KjzA2tMPxsM%3D&amp;reserved=0
> >
> -------------- next part --------------
> HTML attachment scrubbed and removed
>
> ------------------------------
>
> Message: 4
> Date: Mon, 6 Apr 2020 14:46:34 +0200
> From: Micha? Policht <michal_at_[hidden]>
> To: Przemek Kozio? <przemkoz85_at_[hidden]>,
> std-proposals_at_[hidden]
> Subject: Re: [std-proposals] User-defined conversion for strongly
> typed enums
> Message-ID: <bb42e871-dc38-455d-2d26-c97f4c4be8e0_at_[hidden]>
> Content-Type: text/plain; charset=utf-8
>
>
> > I think the main purpose of a struct is not name scoping.
>
> It is one of its characteristics.
>
>
> ------------------------------
>
> Message: 5
> Date: Mon, 6 Apr 2020 14:55:18 +0000
> From: Michael Hava <mfh_at_[hidden]>
> To: "std-proposals_at_[hidden]" <std-proposals_at_[hidden]>
> Subject: Re: [std-proposals] User-defined conversion for strongly
> typed enums
> Message-ID:
> <VI1PR04MB46882760D8C428B6A71E2B42B4C20_at_[hidden]
> prd04.prod.outlook.com>
>
> Content-Type: text/plain; charset="utf-8"
>
> Gotta agree ? is there a rationale why we don?t have those?
>
> From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of
> Zhihao Yuan via Std-Proposals
> Sent: Monday, April 6, 2020 5:03 AM
> To: std-proposals_at_[hidden]
> Cc: Zhihao Yuan <zy_at_[hidden]>
> Subject: Re: [std-proposals] User-defined conversion for strongly typed enums
>
> On Saturday, April 4, 2020 3:17 PM, Przemek Kozio? via Std-Proposals <std-
> proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>> wrote:
>
> Strongly typed enums provide type safety.
>
> I believe, however, the programmer should have an option to define explicit
> conversions to the desired types.
>
> I believe enum class should support
> member functions.
>
> --
> Zhihao Yuan, ID lichray
> The best way to predict the future is to invent it.
> _______________________________________________
>
>
>
> -------------- next part --------------
> HTML attachment scrubbed and removed
>
> ------------------------------
>
> Subject: Digest Footer
>
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.iso
> cpp.org%2Fmailman%2Flistinfo.cgi%2Fstd-
> proposals&amp;data=02%7C01%7C%7C623a67fd43154889187108d7da3aad83
> %7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637217817860600116
> &amp;sdata=Ffa7BapqxpP81LqJ5NcCfpfmp6cuMwz7KjzA2tMPxsM%3D&amp;r
> eserved=0
>
>
> ------------------------------
>
> End of Std-Proposals Digest, Vol 13, Issue 2
> ********************************************
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2020-04-13 09:59:07