Do the C++20
's 严格的别名规则 [基本.lval]/11 http://eel.is/c++draft/expr.prop#basic.lval-11任意允许以下...
- 之间投射
char*
and char8_t*
string str = "string";
u8string u8str { (char8_t*) &*str.data() }; // c++20 u8string
u8string u8str2 = u8"zß水????"
string str2 { (char*) u8str2.data() };
- 之间投射
uint32_t*
, uint_least32_t*
and char32_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() };
- 之间投射
uint16_t*
, uint_least16_t*
and char16_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 构造函数过载 (6) https://en.cppreference.com/w/cpp/string/basic_string/basic_string
template< class InputIt >
basic_string( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
向量构造函数过载 (4) https://en.cppreference.com/w/cpp/container/vector/vector
template< class InputIt >
vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
我想知道是否可以一起去遗留输入迭代器构造函数?...
-
char*
and char8_t*
as 遗留输入迭代器
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*
and char32_t*
as 遗留输入迭代器
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*
and char16_t*
as 遗留输入迭代器
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() };