Click here to Skip to main content
15,921,454 members

Comments by hans.sch (Top 13 by date)

hans.sch 12-Sep-23 12:50pm View    
@Phil J Pearson - arg_dummy is an empty array which corresponds to the empty parameter list. If I remove it, the compiler complains because Invoke requires 2 parameters. The second parameter to Invoke is of type 'object?[]?'. And in fact arg_dummy is null because I don't assign it a value.
hans.sch 22-Aug-23 8:51am View    
@Maxim, thank you for your reply!

The line `IntCallback^ callback = gcnew IntCallback(MyCallback);` generates compiler error C3352: 'int (__cdecl *__cdecl cb)(int)': the specified function does not match the delegate type 'int (int)'. It only compiles when I declare 'int (__clrcall MyCallback)(int)' but when I do that, I have to propagate the __clrcall attribute into native code, and would have to compile the native code with /clr which may or may not work, but which I don't want to do for reasons beyond this discussion.
hans.sch 24-Dec-22 13:40pm View    
Thank you for the explanation! "can't specialize by number of template arguments" did surprise me. With your trick I can continue to explore templates. Just found that with a "requires" clause you can even specialize on the value of the template arguments :-) But I'll leave that for a later post.
hans.sch 12-Apr-15 2:38am View    
This is not about inverting a bit pattern, rather it is about learning about templates. In the long run, other stuff will take the place of bit inversion. My question is not whether it makes sense (I agree it doesn't) but whether it can be done.

I want to write a template implementation that does 'A' for for all types, except for a certain category of types (categorized by IsSuitableType<t>::value) for which it does 'B' - but 'B' won't compile for non-suitable types. 'A' could be an empty function body (if it were not that the function must return a value).
hans.sch 11-Apr-15 12:35pm View    
Thanks Philippe for the quick reply. The issue is that I don't want a compiler error when using an inadequate type but I want the 'dummy' implementation be used. The background is that the call to Invert goes into a template function, and for inadequate types, it simply doesn't get called, so I don't care about the return value. All I need is that it compiles error free.

To see the compiler error in the sample, add the dummy implementation above the specialized one.

I know the 'dummy' code won't compile if T::T() is not public, but I'll deal with this later...