C++高性能并行编程与优化 - 课件 - 15 C++ 系列课:字符与字符串C++ 的 vector 采用了 [ptr, ptr + len, ptr + capacity] 构型。 vector 没有采用小字符串优化…这是因为 string 面对的都 是 char , wchar_t 这种比较小的类型,且用户常用的字符 串往往比较短很容易放进 15 字节的局部栈空间里;然而 vector 面对的往往是比较大的数据结构,有时还有智能指 针, std::thread 这种具有非平凡构造 表示这么宽的字符?有很多种解决方案。 • 一种方案是:索性放弃 char ,改用 wchar_t 做字符类型 。 • wchar_t 在 Linux 上为 4 字节,完全足够表示 Unicode 这 0x000000~0x10FFFF 的范围,甚至还有 1 字节浪费 。 wchar_t 的普及 • 所以他们提议:以后用 const wchar_t * 代替 const char * 。 • 或者继续用 组。并且现在 ‘ \0’ 也不能用作结束符了,因为 wchar_t 的最高位始终 0 (因为 Unicode 只有 3 字节, wchar_t 的 4 字节有一个字节总是为 0 的),这会导致现有的 C 语言函数用不了,例如 strlen(s) 现在总是会返回 3 了。 • 因此 C 语言为了适应这个变化,推出了专门针对 wchar_t 的 wcslen 、 wcscpy 、 wmemset0 码力 | 162 页 | 40.20 MB | 1 年前3
Template Metaprogramming: Type Traitstypes • Corresponding, but different, unsigned integer types • char, char8_t, char16_t, char32_t, wchar_t is_integral 49• Five standard signed integer types: signed char, short int, int, long int, long types • Corresponding, but different, unsigned integer types • char, char8_t, char16_t, char32_t, wchar_t • bool is_integral 49• Five standard signed integer types: signed char, short int, int, long types • Corresponding, but different, unsigned integer types • char, char8_t, char16_t, char32_t, wchar_t • bool • Requires 16*4 = 64 specializations is_integral 49is_integral 50 template0 码力 | 403 页 | 5.30 MB | 6 月前3
Making Libraries Consumable for Non-C++ Developersng_view const dev); The types char and wchar_t do not indicate encoding. The size of wchar_t: • Windows, sizeof(wchar_t) == 2 • Non-Windows, sizeof(wchar_t) == 4 std::basic_stringhas memory 0 码力 | 29 页 | 1.21 MB | 6 月前3
LITERALS SAFELY for Types that Behave as though Built-in - Pablo Halpern - CppCon 2021and string literals can each have up to 5 overloads, one for each built-in character width: char, wchar_t, char8_t, char16_t, and char32_t. ■ Integer overflow results in an error; floating-point over/underflow 45e-6_udl T operator""_udl(long double); 'a'_udl T operator""_udl(char); L'b'_udl T operator""_udl(wchar_t); u8'c'_udl T operator""_udl(char8_t); (since C++20) u'\u2190'_udl T operator""_udl(char16_t); "Hello"_udl T operator""_udl(const char*, std::size_t); L"World"_udl T operator""_udl(const wchar_t*, std::size_t); u8"Alpha\U0001F600"_udl T operator""_udl(const char8_t*, std::size_t); u"Beta0 码力 | 66 页 | 1.47 MB | 6 月前3
Implementing C++ Modules: Lessons Learned, Lessons Abandoned_WINRT_WindowsCreateString@12 referenced in function "void * __cdecl winrt::impl::create_string(wchar_t const *,unsigned int)" (?create_string@impl@winrt@@YAPAXPB_WI@Z) app3.obj : error LNK2019: unresolved referenced in function "private: int __thiscall winrt::param::hstring::create_string_reference(wchar_t const * const,unsigned int)" (?create string reference@hstring@param@winrt@@AAEHQB WI@Z) 17 (C)0 码力 | 53 页 | 1.33 MB | 6 月前3
Back to Basics: C++ Templates - Part 2} 7 auto Normalize(const char* t, locale_s) { return std::string{t}; } 8 auto Normalize(const wchar_t* t, locale_s) { return Normalize(std::wstring{t}, locale_s{}); } 9 templateauto Normalize(const char* t, locale_ws) { return Normalize(std::string{t}, locale_ws{}); } 15 auto Normalize(const wchar_t* t, locale_ws) { return std::wstring{t}; } 16 template auto Normalize(const T& t, locale_ws) 0 码力 | 12 页 | 787.22 KB | 6 月前3
Exceptional C++"sourceFile:lineNo" if (::SymGetLineFromAddr(mProcess, aAddress, &displacement, &line)) { wchar_t origin[MAX_PATH]; swprintf_s(origin, MAX_PATH, L"%s:%ld", line.FileName, line.LineNumber); tion(EXCEPTION_POINTERS * aExceptionInfo) { wstring message(L"[EXCEPTION_UNHANDLED] "); wchar_t buf[MSG_BUFFER_LEN]; swprintf_s(buf, MSG_BUFFER_LEN, L"(0x%.8x) at address " ADDRESS_FORMAT SW_EOL0 码力 | 113 页 | 24.39 MB | 6 月前3
C++20 Modules: The Packaging and Binary Redistribution Storyinclude\fmt\xchar.h(236): note: could be 'void fmt::v10::print<>(fmt::v10::basic_format_string<wchar_t>)' With msvc this actually works But if there are compiler errors, non existent files might be0 码力 | 76 页 | 2.09 MB | 6 月前3
So You Think You Can Hashchar>; template<> struct hash; template<> struct hash ; template<> struct hash<wchar_t>; template<> struct hash ; template<> struct hash ; template<> struct hash ; 0 码力 | 119 页 | 6.54 MB | 6 月前3
Unraveling string_view: Basics, Benefits, and Best Practices> u16string_view; typedef basic_string_viewu32string_view; typedef basic_string_view<wchar_t> wstring_view; // C++ 20 typedef basic_string_view u8string_view; } // namespace std Type 0 码力 | 61 页 | 1.11 MB | 6 月前3
共 121 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
相关搜索词
C++高性性能高性能并行编程优化课件15TemplateMetaprogrammingTypeTraitsMakingLibrariesConsumableforNonDevelopersLITERALSSAFELYTypesthatBehaveasthoughBuiltinPabloHalpernCppCon2021ImplementingModulesLessonsLearnedAbandonedBacktoBasicsTemplatesPartExceptional20ThePackagingandBinaryRedistributionStorySoYouThinkCanHashUnravelingstringviewBenefitsBestPractices













