Sender Patterns to Wrangle Concurrency in Embedded Devicesthat return senders. auto sndr = async::just(42, 17); 1 18just just_result_of just_error just_error_result_of just_stopped Sender Factories Functions that return senders. auto sndr = async::just_result_of( [] { return 17; }); 1 2 3 4 19schedule Sender Factories Functions that return senders. auto sndr = sched.schedule(); 1 20continue_on start_on let_value let_error let_stopped then sequence upon_error 22Composition auto comp = s1.schedule() | async::then([] { return 42; }) | async::continue_on(s2) | async::then([] (int i) { return std::to_string(i); }) ; 1 2 3 4 5 6 7 8 auto r = comp | async::sync_wait();0 码力 | 106 页 | 26.36 MB | 6 月前3
Leveraging a Functional Approach for More Testable and Maintainable ROS 2 Codepre-checks */ auto const start = Position{request->start.data[0], request->start.data[1]}; auto const goal = Position{request->goal.data[0], request->goal.data[1]}; // Generate the path auto const path path = generate_global_path(start, goal); // Start populating the response message auto response_path = std_msgs::msg::UInt8MultiArray(); /* Code about populating the message here */ response->code pre-checks */ auto const start = Position{request->start.data[0], request->start.data[1]}; auto const goal = Position{request->goal.data[0], request->goal.data[1]}; // Generate the path auto const path0 码力 | 200 页 | 1.77 MB | 6 月前3
How Meta Made Debugging Async Code Easier with Coroutines and Sendersasync_main(unifex::spanargs, auto &pool, auto &io) { auto jobs = args | views::transform( [io](fs::path fileName) -> unifex::task { auto file = unifex::open_file_read_only(io y(io, fileName); return process_file(std::move(file)); }); auto stats = co_await unifex::on( pool.get_scheduler(), unifex::when_all_range(jobs.begin(), jobs.end())); for (std::size_t async_main(unifex::span args, auto &pool, auto &io) { auto jobs = args | views::transform( [io](fs::path fileName) -> unifex::task { auto file = unifex::open_file_read_only(io 0 码力 | 131 页 | 907.41 KB | 6 月前3
Thinking Functionally In C++Library (STL) • Lambdas • Ranges |std::rangesC++ has something for everyone: Imperative int main() { auto fh = fopen("script.txt", "r"); char line[255]; const char* ForbiddenWord[] = {"it", "It", "IT"}; numForbiddenWords = 0; while(fgets(line, sizeof line, fh) != nullptr){ const char* delims = " \n\r,;!-?\""; auto* nextWord = strtok(&line[0], delims); while(nextWord != nullptr) { for(int i = 0; i < 3; ++i) words: %d\n", numForbiddenWords); }C++ has something for everyone: Object Oriented int main() { auto fh = std::ifstream("script.txt"); std::stringstream text; text << fh.rdbuf(); int numForbiddenWords0 码力 | 114 页 | 3.14 MB | 6 月前3
From Eager Futures/Promises to Lazy Continuations: Evolving an Actor Library Based on Lessons Learned from Large-Scale Deploymentsk("..."))motivating example std::string SpellCheck(std::string text) { auto body = http::UrlEncode({"text", text}); auto response = http::Post("https://www.online-spellcheck.com", body); return response.body; }motivating example std::string SpellCheck(std::string text) { auto body = http::UrlEncode({"text", text}); auto response = http::Post("https://www.online-spellcheck.com", body); return response.body; }motivating example std::string SpellCheck(std::string text) { auto body = http::UrlEncode({"text", text}); auto response = http::Post("https://www.online-spellcheck.com", body); return0 码力 | 264 页 | 588.96 KB | 6 月前3
Taming the C++ Filter ViewViews C++20 ©2024 by josuttis.com 4 C++ C++20: Views void print(const T& coll) { for (const auto& elem : coll) { std::cout << elem << ' '; } std::cout << '\n'; } std::vectorcoll1{0, 8, 15 View @cppcon 2024-09-17 2©2024 by josuttis.com 5 C++ C++20: Views void print(const auto& coll) { for (const auto& elem : coll) { std::cout << elem << ' '; } std::cout << '\n'; } std::vector coll1{0 ©2024 by josuttis.com 6 C++ C++20: Views void print(const std::ranges::input_range auto& coll) { for (const auto& elem : coll) { std::cout << elem << ' '; } std::cout << '\n'; } std::vector coll1{0 0 码力 | 43 页 | 2.77 MB | 6 月前3
Object Lifetime: From Start to Finish"~Foo(" << m_i << ")" << endl; } int m_i; }; int main() { auto v1 = Foo(1); { auto v2 = Foo(2); } auto v3 = Foo(3); auto v4 = new Foo(4); } https://godbolt.org/z/4WroY5311 1 2 "~Foo(" << m_i << ")" << endl; } int m_i; }; int main() { auto v1 = Foo(1); { auto v2 = Foo(2); } auto v3 = Foo(3); auto v4 = new Foo(4); } https://godbolt.org/z/4WroY5311 1 2 << m_i << ")" << endl; } int m_i; }; int main() { auto v1 = Foo(1); // Foo(1) { auto v2 = Foo(2); } auto v3 = Foo(3); auto v4 = new Foo(4); } https://godbolt.org/z/4WroY53110 码力 | 214 页 | 9.34 MB | 6 月前3
Expressive Compile-time Parsers>>Example – Filter Transform vectorcats = { /*...*/ }; vector< tuple > result; for(auto itr = cats.cbegin(); itr != cats.cend(); ++itr) if(itr->age > 42) result.emplace_back(tuple{ Filter Transform vector cats = { /*...*/ }; vector< tuple > result; for(const auto& cat : cats) if(cat.age > 42) result.emplace_back(tuple{ cat.id, cat.name });Example });Example – Filter Transform vector cats = { /*...*/ }; namespace v = std::views; auto result = cats | v::filter([](const Cat& cat) { return cat.age > 42; }) | v::transform([](const 0 码力 | 134 页 | 1.73 MB | 6 月前3
Compile-Time Validationthat were pointing to it to become invalid void foo(){ vectorvec = { 0, 1, 2, /*...*/ }; auto& ref = vec[0]; vec.push_back(42); cout << ref; // ref may be invalid }Memory Safety - Out of Performance Validation void must_be_fast() { using namespace std::chrono; auto start = high_resolution_clock::now(); /*...*/ auto end = high_resolution_clock::now(); validate_performance(start, end); including printing to a console, writing to a file, or transmitting over a network. void foo(){ auto error = detect_error(); if (error) { report_error(error); } }Runtime Error Reporting Runtime 0 码力 | 137 页 | 1.70 MB | 6 月前3
Implementing Particle Filters with Rangesvoid filter( std::vector & particles, StateUpdateFn auto state_update_fn, ReweightFn auto reweight_fn) { ... } 1 2 3 4 5 6 7 8 11PARTICLE FILTER ALGORITHM UPDATE std::vector & particles, StateUpdateFn auto state_update_fn, ReweightFn auto reweight_fn) { auto states = particles | std::views::transform(&T::state); auto weights = particles | std::views std::vector & particles, StateUpdateFn auto state_update_fn, ReweightFn auto reweight_fn) { auto states = particles | std::views::transform(&T::state); auto weights = particles | std::views 0 码力 | 83 页 | 4.70 MB | 6 月前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100
相关搜索词
SenderPatternstoWrangleConcurrencyinEmbeddedDevicesLeveragingFunctionalApproachforMoreTestableandMaintainableROSCodeHowMetaMadeDebuggingAsyncEasierwithCoroutinesSendersThinkingFunctionallyInC++FromEagerFuturesPromisesLazyContinuationsEvolvinganActorLibraryBasedonLessonsLearnedfromLargeScaleDeploymentsTamingtheFilterViewObjectLifetimeStartFinishExpressiveCompiletimeParsersTimeValidationImplementingParticleFiltersRanges













