C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Generic code, not the API you are looking for

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Sat, 20 Aug 2022 12:29:46 +0200
sob., 20 sie 2022 o 06:36 Zhihao Yuan via Std-Proposals
<std-proposals_at_[hidden]> napisaƂ(a):
>
> On Friday, August 19th, 2022 at 12:27 PM, Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> >
>
> > First, I'm decidedly unsure about what... any of that actually is.
> > What is `String S` here?
>
> Declare a parameterized type S that satisfies String.
>
> > Is `String` a type concept?
>
> A protocol, just like Swift's protocol.
>
> >
>
> > I'm guessing that you probably meant something like:
> >
>
> > ```
> > generic<String S>
> > void function(S s) {
> > using char_t = S::char_type;
> > // ...
> > if(s.starts_with(something))
> > { ... }
> > }
> > ```
>
> Sure.
>
> >
>
> > Does this `generic` declaration mean that if I have some type `T`
> > which happens to satisfy the concept `String`, there will
> > automatically be a function named `function` with that implementation?
>
> You need to use `override` to claim
> that your type satisfies `String`
> rather than "happens to satisfy."
>
> >
>
> > Does the `override` declaration mean that `vector<char>::starts_with`
> > is a legitimate expression?
>
> No.
>
> > Isn't that highly dangerous, as it
> > effectively allows you to modify a class's interface without actually
> > being the owner/maintainer of that type?
>
> No either. It is outside class. It's
> an entry of the protocol rather than
> the type. The only way to use it is
> through a parameterized type.
>
> >
>
> > Injecting definitions into a class without that class's explicit
> > knowledge and consent should be a non-starter.
>
> Doesn't apply. Never needed.
>

Is this simply "C++0x concept maps"?
Initially Bjarne Stroustrup like to have option to map diffrent type
"shapes" to one using concepts,
but it was too complex and was strip down to current basic version.

Best would be to see what was the most problematic part of this
proposal. It could be possible that simply
scope of C++0x concepts was a problem not what Bjarne initially proposed.

Maybe we should reanimate this old version and try to push it again
through the committee.



> --
> Zhihao Yuan, ID lichray
> The best way to predict the future is to invent it.
> _______________________________________________--
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-08-20 10:29:55