C++ Logo

std-proposals

Advanced search

Re: [std-proposals] c++ interfaces vs templates

From: Erik Aronesty <erik_at_[hidden]>
Date: Thu, 8 Dec 2022 14:59:22 -0500
it's just like "concepts" thanks! haven't gotten up to speed on 20, i'll
modify a couple so answers on interfaces to point to this

On Thu, Dec 8, 2022 at 2:44 PM Magnus Fromreide <magfr_at_[hidden]>
wrote:

> On Thu, Dec 08, 2022 at 11:23:38AM -0500, Erik Aronesty via Std-Proposals
> wrote:
> > Has anyone proposed something like this?
> >
> > ---
> > interface sizeable {
> > size_t size() cost;
> > }
> >
> > bool too_big(sizeable thing) {
> > return thing.size() > 100;
> > }
> >
> > void main() {
> > std::cout << too_big(string("sdfkjhsdfjh")) << std::endl;
> > std::cout << too_big(vector<int>(1000,0)) << std::endl;
> > }
>
> This is rather similar and there is even a reference to a paper:
>
> https://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_5.html#SEC112
>
> That extension has been removed from gcc since then, I think it was about
> the turn of the century.
>
> /MF
>
> > ---
> >
> > the precompiler can then generate specializations as needed, in the same
> > way that templates generate specializations, so the resulting code can be
> > as efficient as templates
> >
> > the advantage is that
> >
> > - it's just as efficient as templates
> > - it's easier to teach/understand
> > - avoids virtual stuff
> > - avoids complex inheritance
> > - works with existing libs
> > - should result in much better error messages than templates
>

Received on 2022-12-08 19:59:34