C++ Logo

std-proposals

Advanced search

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

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Thu, 8 Dec 2022 16:33:33 +0000
On Thu, 8 Dec 2022 at 16:23, Erik Aronesty via Std-Proposals <
std-proposals_at_[hidden]> 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;
> }
> ---
>

How would this differ from concepts?


>
> 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
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-12-08 16:33:47