c++ - What does (&) -- ampersand in parentheses -- mean in this code? -
in this answer, following code given (c++11):
template <typename t, size_t n> constexpr size_t size_of(t (&)[n]) { return n; }
what (&)
mean in context? sort of thing exceptionally difficult search for.
it's shorthand this:
template <typename t, size_t n> constexpr size_t size_of(t (&anonymous_variable)[n]) { return n; }
in function, don't need name of variable, template deduction on n
- can choose omit it. parentheses syntactically necessary in order pass array in reference - can't pass in array value.
Comments
Post a Comment