We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
Hey Tom, yeah, C/C++ syntax for complicated types is pretty ridiculous. :)
The return type of <tt>dim_helper</tt> is the same as its parameter type---a reference to array of size N---but the array type is char instead of T. In other words, the return type is <tt>char(&)[N]</tt>.
To make a function, you just stick the function name and parameters inside the parentheses. Thus, <tt>char(& dim_helper(T(&)[N]) )[N]</tt> with it all spaced out for a bit more clarity.
BTW, cdecl.org is a nice tool to help disentangle things like this. (Although it's strictly C-only, so no template parameters or references.)
AAaaaaaaah I see! Awesome! It makes sense now! :) Thank you very much for clarifying this. I agree sometimes C++ syntax can be pretty horrible (pointer to member function springs to mind :)) cdecl.org looks great too, I was not aware of it. Thanks again!
If we want to be "more correct", shouldn't "N" be defined as size_t? Not entirely nitpicking but making sure i'm reading and understanding it right.
Hmm, yes, you're probably right! In principle we could have a very large array that would need size_t to fit its dimension.
The coderwall.com site community explains in Some detail the theory of how best to get the size of an array in C++ https://coderwall.com/p/nb9...
I am afraid I still don't quite understand the syntax of this line
char(&dim_helper(T(&)[N]))[N];
I get the parameter to dim_helper, but what is the 'char(&..' doing? Is it returning a char&? Is it casting to a char? Is there another way of writing it? How is the final [N] working. Looks so strange :P Any information would be greatly appreciated. It's really interesting I just want to make sure I totally understand it.
Thanks!
Tom