Re: Aliasing in C++11
On Thursday, 21 February 2013 23:27:25 UTC+2, molw...@gmail.com wrote:
Based on my reading of the standard the compiler is free to assume a poin=
ter
to a strongly typed enumeration aliases only other pointers to the same t=
ype
and raw character pointers. For example, I would like to define a more=
restrictive byte array for interacting with binary data as follows:
enum byte : uint8_t {};
No you are wrong. Your's is traditional enum with underlying type. This is
strongly typed enum:
enum class byte : uint8_t {};
std::vector <byte> buffer;
Even with yours 'byte' it is definitely more restrictive.
Specifically, I believe string-like classes could benefit greatly from th=
is
sort of implementation by defining their internal state using definitions
similar to the above:
class string
{
...
private:
enum byte : char {};
std::unique_ptr <byte[]> buffer;
};
Do not perhaps write yet another text-containing class. The market is full
there are way too lot of such.
The tests I've performed with GCC support the above interpretation =96 do=
es a
strict reading of the standard support the above, and/or is there some ot=
her
well-known alternative? Thanks in advance,
What is the "this"? It should work. Currently most people use std::string
(that actually contains UTF-8 encoded text) for storing texts. I fully
agree with you that it is loose and unsafe thing. However it is unlikely
that some revolution is coming. Billions of lines of code and millions of
interfaces all over the world use that std::string and problems are
consistently elsewhere.