Do the C++20
's strict aliasing rules [basic.lval]/11 arbitrarily allow following...
- cast between
char*
andchar8_t*
string str = "string";
u8string u8str { (char8_t*) &*str.data() }; // c++20 u8string
u8string u8str2 = u8"zß水🍌"
string str2 { (char*) u8str2.data() };
- cast between
uint32_t*
,uint_least32_t*
andchar32_t*
vector<uint32_t> ui32vec = { 0x007a, 0x00df, 0x6c34, 0x0001f34c };
u32string u32str { (char32_t*) &*ui32vec.data(), ui32vec.size() };
u32string u32str2 = U"zß水🍌"
vector<uint32_t> ui32vec2 { (uint32_t*) &*u32str2.begin(),
(uint32_t*) &*u32str2.end() };
- cast between
uint16_t*
,uint_least16_t*
andchar16_t*
vector<uint16_t> ui16vec = { 0x007a, 0x00df, 0x6c34, 0xd83c, 0xdf4c };
u16string u16str { (char16_t*) &*ui16vec.data(), ui16vec.size() };
u16string u16str2 = u"zß水\ud83c\udf4c"
vector<uint16_t> ui16vec2 { (uint16_t*) &*u16str2.begin(),
(uint16_t*) &*u16str2.end() };
Update
basic_string contructor overload (6)
template< class InputIt >
basic_string( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
vector constuctor overload (4)
template< class InputIt >
vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
I wonder whether it is okey to go with LegacyInputIterator constructors?...
char*
andchar8_t*
as LegacyInputIterator
string str = "string";
u8string u8str { str.begin(), str.end() };
u8string u8str { &*str.begin(), &*str.end() };
u8string u8str2 = u8"zß水🍌"
string str2 { u8str2.begin(), u8str2.end() };
string str2 { &*u8str2.begin(), &*u8str2.end() };
uint32_t*
,uint_least32_t*
andchar32_t*
as LegacyInputIterator
vector<uint32_t> ui32vec = { 0x007a, 0x00df, 0x6c34, 0x0001f34c };
u32string u32str { ui32vec.begin(), ui32vec.end() };
u32string u32str { &*ui32vec.begin(), &*ui32vec.end() };
u32string u32str2 = U"zß水🍌"
vector<uint32_t> ui32vec2 { u32str2.begin(),
u32str2.end() };
vector<uint32_t> ui32vec2 { &*u32str2.begin(),
&*u32str2.end() };
uint16_t*
,uint_least16_t*
andchar16_t*
as LegacyInputIterator
vector<uint16_t> ui16vec = { 0x007a, 0x00df, 0x6c34, 0xd83c, 0xdf4c };
u16string u16str { ui16vec.begin(), ui16vec.end() };
u16string u16str { &*ui16vec.begin(), &*ui16vec.end() };
u16string u16str2 = u"zß水\ud83c\udf4c"
vector<uint16_t> ui16vec2 { u16str2.begin(),
u16str2.end() };
vector<uint16_t> ui16vec2 { &*u16str2.begin(),
&*u16str2.end() };
char*_t
, I assumed that's what you were talking about. Those are not typedefs, and cplusplus.com doesn't say that they are. – Coracletypedef
(uint32_t
,uint_least32_t
,uint16_t
,uint_least16_t
); it depends which type they represent. – Kershaw