C++ Logo

std-proposals

Advanced search

Re: [std-proposals] New attribute to add implicit using statements for template parameter lists

From: Peter C++ <peter.cpp_at_[hidden]>
Date: Mon, 28 Nov 2022 10:56:35 +0100
FWIW

using an attribute that in theory should be ignorable might not be the best approach to change lookup rules in template argument context.

Regards
Peter

sent from a mobile device so please excuse strange words due to autocorrection.
Peter Sommerlad
peter.cpp_at_[hidden]
+41-79-432 23 32

> On 28 Nov 2022, at 02:40, Ryan Klaus via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> 
> Let's say I have a template class that takes two enums:
>
> template <ColorComponents T_components, ColorComponentLayout T_layout>
> class Color { ... };
>
> Because I'm a good boy, each enum is of course an enum class like so:
>
> enum class ColorComponentLayout
> {
> _332,
> _4444,
> ...
> };
>
> enum class ColorComponents
> {
> RGB,
> RGBA,
> ARGB,
> ...
> };
>
> And all of the above is inside the namespace "ABC".
>
> In a just world, I feel like I should be able to right something like this:
>
> auto color = ABC::Color<RGBA, _8888>{};
>
> The compiler knows it wants a ColorComponents followed by a ColorComponentLayout, so all of the contextual information is theoretically there.
> But this is not a just world and so I'm forced to write this incantation:
>
> auto color = ABC::Color<ABC::ColorComponents::RGBA, ABC::ColorComponentLayout::_8888>{};
>
> So my proposal is to create some new attribute, [[context(...)]], such that we could write:
>
> [[context(using enum ColorComponents, using enum ColorComponentLayout)]]
> template <ColorComponents T_components, ColorComponentLayout T_layout>
> class Color { ... };
>
> This essentially allows for any parameter list (function or template) to have using statements scoped only to the parameter list itself. This could also permit type aliases to allow for context specific parameter list aliases. Not sure when that would be useful, but I could see that potentially being a very handy space saver.
>
> What's everyone's thoughts on this? Is it possible? Is it not possible? Is it possible but we hate it?
>
> Thanks,
> Ryan Klaus
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-11-28 09:56:54