dr_strangetemplate icon indicating copy to clipboard operation
dr_strangetemplate copied to clipboard

First example no good?

Open MCGallaspy opened this issue 8 years ago • 2 comments

The internet at large has suggested that the first example doesn't really improve using a C API. While I don't think those criticisms are without merit, I've decided to keep it up for now because it serves my main goal of introducing concepts like SFINAE.

As for whether it is actually a detriment to wrap a C-style API in the way I've suggested, in my opinion it's neither clearly a detriment nor a great improvement. The argument seems to be that it makes the code needlessly more complex. I consider that a matter of opinion.

But please feel free to comment here if you feel strongly about it!

MCGallaspy avatar Sep 27 '16 06:09 MCGallaspy

This is a fantastic guide. Thank you for taking the time to write it.

Could you elaborate on why you go from

void api_exec(int func(Args...), Args... args) { ... }

to

void api_exec(Function func, Args... args) { ... )

It seems the make the function overly generic in a way that causes you next problem with

api_exec(epsilon)

That you then need to fix with extra tricks. If you were to keep the original, more constrained,version, wouldn't it then check the return type in a more intuitive fashion?

gkontsevich avatar Jul 26 '17 14:07 gkontsevich

I think you are right, it is overly generic for my given example. I guess what I was thinking originally is that I find function types like int func(Args...) hard to parse, whereas a type like Function telegraphs intent to me much better.

MCGallaspy avatar Jul 26 '17 18:07 MCGallaspy