On a piece of code in a previous question in stackoverflow I saw this, strange to me, declaration with using
:
template <std::size_t SIZE>
class A
{
public:
...
using const_buffer_t = const char(&)[SIZE];
...
};
Could someone please address the following questions:
That's a type alias, a new syntax available since c++11.
What you're actually doing is typedefing the type of an array
const_buffer_t
will be an array of const char with length = SIZE
That using
declaration is a new syntax introduced in C++11; it introduces a type alias, specifying that const_buffer_t
is now an alias for the type const char(&)[SIZE]
. In this respect, this use of using
is substantially identical to a typedef
(although using
type aliases are more flexible).
As for the actual type we are talking about (const char(&)[SIZE]
), it's a reference to an array of size SIZE
; references to array are rarely used, but can have their use:
int param[5]
in a function declaration it's parsed as int *
);See also the array FAQ, where much of this stuff is explained in detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With