Unraveling string_view: Basics, Benefits, and Best PracticesUnraveling string_view: Basics, Benefits, and Best Practices ## JASMINE LOPEZ & PRITHVI OKADE 20 24 September 15 - 20 ## Topics • Motivation • Performance benefits & basics • string_view: Constructors Constructors, useful functions • string vs. string_view and their interoperability • When to use string_view • Using string_view safely • Intro to span • span vs. string_view • Case study of an optimization void foo(const char* str); And the code will miss the niceties of using the string API set. string_view helps in resolving this problem elegantly. ## Motivation Instead of the following 3 functions:0 码力 | 61 页 | 1.11 MB | 1 年前3
Regular, Revisitedrequirements for its data structures and algorithms to work properly. STL vocabulary types such as string_view, span, optional, expected etc., raise new questions regarding values types, whole-part semantics This analysis provides us some basis to evaluate non-owning reference parameters types (like string_view and span) in a practical fashion, without discarding Regular design. Let's go back to the roots and std::expected - Victor Ciura ## std::string_view An object that can refer to a constant contiguous sequence of char-like objects A string_view does not manage the storage that it refers to0 码力 | 180 页 | 19.96 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - 15 C++ 系列课:字符与字符串vector 容器初体验 & 迭代器入门 (BV1qF411T7sd) 2. 你所不知道的 set 容器 & 迭代器分类 (BV1m34y157wb) 3. string, string_view, const char * 的爱恨纠葛(本期) 4. 万能的 map 容器全家桶及其妙用举例 5. 函子 functor 与 lambda 表达式知多少 6. 通过实战案例来学习 STL operator“”i32 了。 • 其实 cpp 这种自定义挺好的,把自由度给到用户。 例如标准库说 “hello”s 是 std::string,“hello”s 是 std::string_view。 - 我也可以定义一个 “hello”ms 是 mylib::String,而且还是受 namespace 限制的,用户可以自己 using namespace,不会存在强迫别人接受你的那一套后缀名规范。 • find 拥有众多重载,我们一个个来看。 • size_t find(char c, size_t pos = 0) const noexcept; • size_t find(string_view svt, size_t pos = 0) const noexcept; • size_t find(string const &str, size_t pos = 0) const0 码力 | 162 页 | 40.20 MB | 2 年前3
Modern C++ Error Handling2019 ## Part 1 ## a Series (total) of disappointments int parse_int(std::string_view number) ## - int parse_int(std::string_view number) { int acc = 0; for(char c : number) { if(c < acc *= 10; acc += c - '0'; } return acc; } int parse_int(std::string_view number) { int acc = 0; for(char c : number) { if(c < '0' || c > '9') [Image](/uploads/documents/5/d/e/4/5de47281421dd7c7e5210729c4ee6acc/p8_1.jpg) bool is_int(std::string_view number) { for(char c : number) { if(c < '0' || c > '9')0 码力 | 66 页 | 36.65 MB | 1 年前3
Many Ways to Kill an Orc (or a Hero)std; // or #include, ## What this is about? // the easy case // ... class Character { /* ... */ */ }; class Orc; class Hero : Character { int strength_; public: constexpr Hero(std::string_view name, int life, int strength); : Character { name, life }, strength_{strength} { } constexpr, <string_view>, class Character { std::string name_; int life_; public: constexpr Character(std::string_view name, int life) : name_{name}, life_{life} void suffer(int damage) { life_ -= damage; } }; A Character can suffer (among other things)string_view> 0 码力 | 202 页 | 1.26 MB | 1 年前3
Design PatternsShapesFactory { public: virtual ~ShapesFactory() = default; virtual Shapes create(std::string_view filename) const = 0; }; void drawAllShapes(Shapes const& shapes) { for (auto const& ShapesFactory { public: virtual ~ShapesFactory() = default; virtual Shapes create( std::string_view filename ) const = 0; }; void drawAllShapes( Shapes const& shapes ) { for ( auto const& s->draw(); } } void createAndDrawShapes( ShapesFactory const& factory, std::string_view filename ) { ## A Classic Object-Oriented Solution0 码力 | 136 页 | 7.95 MB | 1 年前3
A Case-study in Rewriting a Legacy GUI Library for Real-time Audio Software in Modern C++CreateProperty(string_view name, string_view typeName, any value); templateoptional templateGetProperty(string_view name); template SetProperty(string_view name, T value); private: unordered_map m_properties; optional GetProperty(string_view name) { cbegin(), m_propertyValues.cend(), &](const auto& e) { return std::string_view{e.first} == name; } }; }; auto* value = boost::any_cast (&it->second.value); 0 码力 | 138 页 | 2.75 MB | 1 年前3
Lifetime Safety in C++: Past, Present and Futurecomes next? ## Statement-local lifetime analysis void prettyPrint(const string& thing) { string_view pretty = thing.empty() ? ": thing; cout << pretty << '\n'; } string& thing) { string_view pretty = thing.empty() ? ": thing; cout << pretty << '\n'; } ## Statement-local lifetime analysis string_view pretty = thing.empty() Statement-local lifetime analysis string_view pretty = thing.empty() ? ": thing; const char[6] string ## Statement-local lifetime analysis string_view pretty = thing.empty() ? ": 0 码力 | 124 页 | 2.03 MB | 1 年前3
Security Beyond Memory SafetyExecution Environment 1 struct ShowMessageCommand 1 enum class Status { 2 { 2 waiting, 3 std::string_view message; // [input] text to display 3 accepted, 4 Status* status; 5}; // [output] reports ved.message, *received.status); 1 struct ShowMessageCommand 2 { 3 std::string_view message; 4 Status* status; 5}; // [input] text to display // [output] reports status to user process_message_command(received.message, *received.status); void process_message_command(std::string_view message, Status& status) { status = is_friendly(message) ? Status::accepted : Status::rejected;0 码力 | 79 页 | 4.15 MB | 1 年前3
A Multithreaded, Transaction-Based Locking Strategy for Containersprn_gen = mt19937_64; using int_dist = uniform_int_distribution<}; using hasher = hash<string_view>;string_view> ## Testing – test_item //- An updatable type susceptible to data prn_gen& gen, int_dist& char_dist) { char local_chars[buf_size]; string_view local_view(local_chars, buf_size); string_view shared_view(ma_chars, buf_size); hasher hash; for (size_t i prn_gen& gen, int_dist& char_dist) { char local_chars[buf_size]; string_view local_view(local_chars, buf_size); string_view shared_view(ma_chars, buf_size); hasher hash; for (size_t i0 码力 | 142 页 | 474.78 KB | 1 年前3
共 66 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
相关搜索词
string_viewstd::stringspan性能优化内存分配Regular typesSTLC++C字符串小字符串优化vectorstd::expectedstd::optionalmonadic operationsparse_interror handlingCharacterHeroOrchitperformance设计模式依赖结构虚拟函数CRTP模式桥接模式Legacy GUI LibraryReal-time Audio SoftwareModern C++PerformanceThreading ModelLifetime SafetyCrubitCore GuidelinesP2771Memory SafetyVulnerabilitiesRecallCybersecuritymultithreadedtransaction-based lockingcontainerstrict timestamp orderingconcurrency tools













