Unraveling string_view: Basics, Benefits, and Best Practicesand their interoperability • When to use string_view • Using string_view safely • Intro to span • span vs. string_view • Case study of an optimization using string_view. 2Motivation • Consider a Caught with -Wdangling Check out MSVC’s Lifetime Rules of the C++ Core Guidelines (-WLifetime).span: Motivation Consider the following functions void foo(int* arr, int n) { for (int i = 0; i < n; type which can consume all these contiguous containers with a single interface? 36span: Motivation void foo(spans) { for (const auto i : s) { cout << i << ' '; } cout << '\n'; } int arr[] 0 码力 | 61 页 | 1.11 MB | 6 月前3
Regular, Revisiteddata 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, copies 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. Titus Winters, 2018 abseil.io/bl Ciura | @ciura_victor - Regular, Revisited 93 Slide Title std::spanC++20 https://en.cppreference.com/w/cpp/container/span Think "array view" as in std::string_view, but mutable on underlying 0 码力 | 180 页 | 19.96 MB | 6 月前3
How Meta Made Debugging Async Code Easier with Coroutines and Senderspool, ctx); unifex::sync_wait(std::move(task)); return 0; }unifex::taskasync_main(unifex::span args, auto &pool, auto &io) { auto jobs = args | views::transform( [io](fs::path fileName) std::printf("Average word length in %s is %g\n", args[i], mean); } }unifex::task async_main(unifex::span args, auto &pool, auto &io) { auto jobs = args | views::transform( [io](fs::path fileName) std::printf("Average word length in %s is %g\n", args[i], mean); } }unifex::task async_main(unifex::span args, auto &pool, auto &io) { auto jobs = args | views::transform( [io](fs::path fileName) 0 码力 | 131 页 | 907.41 KB | 6 月前3
Secrets of C++ Scripting Bindingsconcrete function (not a template) that can take any number of parameters. 1 Type generic_function(std::span); 12 . 11Copyright Jason Turner @le�icus emptycrate.com/idocpp A Generic Function Signature concrete function (not a template) that can take any number of parameters. 1 Type generic_function(std::span ); What should this placeholder Type be? 12 . 11Copyright Jason Turner @le�icus emptycrate concrete function (not a template) that can take any number of parameters. 1 Type generic_function(std::span ); What should this placeholder Type be? It needs to be able to hold all of the types we care 0 码力 | 177 页 | 1.65 MB | 6 月前3
The Beauty and Power of Primitive C++accessor for an Vectorcalled vs: Span vs() { return mbuf->vs; } Stroustrup - "Primitive" - CppCon 2020 14 std::string Flat::String Flat::Span Message descriptor User code access access type initializer type placement new flat type a Span is a range of elementsType mapping • Initializer types: ordinary types to initialize objects in the buffer • char, int32_t, uint32_t, … TimeStamp • char, int32_t, uint32_t, … • Flat::Span , Flat::Span_ref Stroustrup - "Primitive" - CppCon 2020 15 std::string Flat::String Flat::Span User code Message descriptorThe first 0 码力 | 53 页 | 1.03 MB | 6 月前3
Hidden Overhead of a Function API24: Use a spanor a span_p to designate a half-open sequence Reason Informal/non-explicit ranges are a source of errors. “use span” + “use a span”: 16 occurrences 110C++20 std::span vs raw pointer pointer and size #include <span> int raw_back(int const* ptr, size_t size) { return ptr[size - 1]; } int span_back(std::span span) { return span[span.size() - 1]; } 111 https://godbolt add eax, DWORD PTR [esp+4] mov eax, DWORD PTR [eax] ret mov ecx, DWORD PTR _span$[esp] mov eax, DWORD PTR _span$[esp-4] mov eax, DWORD PTR [eax+ecx*4-4] ret 0 S P A N 112 ?C++23 std::mdspan 0 码力 | 158 页 | 2.46 MB | 6 月前3
Exploration of Strongly-typed Units: A Case Study from Digital AudioInterfacing with 3rd-party APIs …namespace tp { class Processor { public: virtual void Process(std::spanbuf) = 0; }; }namespace ni { using ProcessQuantityT = mp_units::quantity span {}); }; template class ProcessorImpl : public tp::Processor { public: void Process(std::span buf) { m_impl.Process({ size()}); } private: T m_impl{}; }; }namespace ni { class LevelPrinter { public: void Process(std::span buf) { std::cout << '{'; for (auto i = 0u; i < buf.size(); ++i) { 0 码力 | 106 页 | 5.66 MB | 6 月前3
廖雪峰JavaScript教程p.innerHTML = 'ABC'; //ABC
5. // 设置HTML: 6. p.innerHTML = 'ABC <span style="color:red">REDspan> XYZ'; 7. //...
的内部结构已修改 用 innerHTML 时要注意,是否需要写入HTML。如果写入的字符串是通过网络拿到了,要注意对字符 节点内插入新的DOM,应该如何做? 如果这个DOM节点是空的,例如, <div></div> ,那么,直接使用 innerHTML = '<span>child</span>' 就可以修改DOM节点的内容,相当于“插入”了新的DOM节点。 如果这个DOM节点不是空的,那就不能这么做,因为 innerHTML 会直接替换掉原来的所有子节点。 $('#test-ul li.js'); 3. var j2 = $('#test-ul li[name=book]'); 4. 5. j1.html('<span style="color: red">JavaScriptspan>'); 6. j2.text('JavaScript & ECMAScript'); 一个jQuery对象可以包含0个或任意个DOM对象,它的方法实际上会作用在对应的每个DOM节点上。在0 码力 | 264 页 | 2.81 MB | 10 月前3
Back to Basics: C++ Templates - Part 1away. ■ For example span ■ Can hold both CArray and std::array. ■ Of course, rangebased forready. ■ Cleaned up the code safely and with little overhead. 1 bool Send(const span& data) 2 { 3 return return write(data.data(), data.size()); 4 } 5 6 void Read(span data) 7 { 8 int i = 1; 9 // fill buffer with data 10 for(auto& c : data) { 11 c = i; 12 ++i; 13 } 14 } 15 16 void Main() 17 { For example span ■ Can hold both CArray and std::array. ■ Of course, rangebased forready. ■ Cleaned up the code safely and with little overhead. ■ C++20 Single Header Version of span: [2]. 1 template 0 码力 | 17 页 | 817.47 KB | 6 月前3
Python 3.6.15 正则表达式 HOWTO <_sre.SRE_Match object; span=(0, 5), match='tempo'> 现在你可以检查 匹配对象以获取有关匹配字符串的信息。匹配对象实例也有几个方法和属性;最重要的是: 方法 / 属性 目的 group() 返回正则匹配的字符串 start() 返回匹配的开始位置 end() 返回匹配的结束位置 span() 返回包含匹配 (start, end) 位置的元组 start(), m.end() (0, 5) >>> m.span() (0, 5) group() returns the substring that was matched by the RE. start() and end() return the starting and ending index of the match. span() returns both start and end None >>> m = p.search('::: message'); print(m) <_sre.SRE_Match object; span=(4, 11), match='message'> >>> m.group() 'message' >>> m.span() (4, 11) 在实际程序中,最常见的样式是在变量中存储 匹配对象,然后检查它是否为 None。这通常看起来像: p = re0 码力 | 18 页 | 391.58 KB | 11 月前3
共 145 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
相关搜索词
UnravelingstringviewBasicsBenefitsandBestPracticesRegularRevisitedHowMetaMadeDebuggingAsyncCodeEasierwithCoroutinesSendersSecretsofC++ScriptingBindingsTheBeautyPowerPrimitiveHiddenOverheadFunctionAPIExplorationStronglytypedUnitsCaseStudyfromDigitalAudio雪峰JavaScript教程BacktoTemplatesPartPython3.615正则表达达式表达式正则表达式HOWTO













