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
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
C++20 STL Features: 1 Year of Development on GitHub} cout << i << endl; // ordinary read, 1729 } 20span 21span Encapsulates Ptr-Len Pairs • span is a non-owning view of contiguous elements • spanis like a pair of T* and size_t, but better • spans accidental pointer arithmetic • span ➡ span ; span ❌ span • Shallow const, like T* • span can be reassigned, can't modify elements • const span can't be reassigned, can elements • MSVC's std::span checks debug; gsl::span always 22Contiguous Range Constructor • GH-142, GH-500, GH-587 implemented by miscco #include #include #include <span> #include 0 码力 | 45 页 | 989.72 KB | 6 月前3
C++20 STL Features: 1 Year of Development on GitHub} cout << i << endl; // ordinary read, 1729 }21 span22 span Encapsulates Ptr-Len Pairs • span is a non-owning view of contiguous elements • spanis like a pair of T* and size_t, but better • spans accidental pointer arithmetic • span span ; span 🐞 span • Shallow const, like T* • span can be reassigned, can't modify elements • const span can't be reassigned, • MSVC's std::span checks debug; gsl::span always23 Contiguous Range Constructor • GH-142, GH-500, GH-587 implemented by miscco #include #include #include <span> #include 0 码力 | 45 页 | 702.09 KB | 6 月前3
共 96 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
相关搜索词
UnravelingstringviewBasicsBenefitsandBestPracticesRegularRevisitedHowMetaMadeDebuggingAsyncCodeEasierwithCoroutinesSendersSecretsofC++ScriptingBindingsTheBeautyPowerPrimitiveHiddenOverheadFunctionAPIExplorationStronglytypedUnitsCaseStudyfromDigitalAudioBacktoTemplatesPart20STLFeaturesYearDevelopmentonGitHub













