The Surprising Costs of Void
destination? Neither this nor the argument are const, so the signature brings confusion…2122 A void function whose name starts with get is… uncomfortable. Supposing that this function gets stats pattern quite a lot… Is RVO misunderstood?3031 « Create », like « get », is a suspicious fit for void return types. Likewise for a number of other verbs (make, convert, count, etc.)32Picture from the String getName() { return "My name is " + super.getName(); } } public class Z { public static void main(String [] args) { Person p = new Student("Bob"); System.out.println(p.getName()); } }4041420 码力 | 189 页 | 60.10 MB | 5 月前3Template Metaprogramming: Type Traits
value (or void) void do_something(); int do_something_else(int, char const*); 10Metafunctions • Traditional functions have zero+ parameters and return a value (or void) void do_something(); 10Metafunctions • Traditional functions have zero+ parameters and return a value (or void) void do_something(); int do_something_else(int, char const*); • Mechanism for returning a value syntax 10Metafunctions • Traditional functions have zero+ parameters and return a value (or void) void do_something(); int do_something_else(int, char const*); • Mechanism for returning a value0 码力 | 403 页 | 5.30 MB | 5 月前3Reusable Code & Reusable Data Structures
2WHY THIS TALK? 344.1// https://github.com/think-cell/think-cell-library void vertical_center(WidgetContainer const& c) { } 1 2 auto rects = tc::make_vector(tc::transform(c, 3 [](widget const& widget.place(r); 9 } 10 11 ); 12 4.2// https://github.com/think-cell/think-cell-library void vertical_center(WidgetContainer const& c) { } 1 2 auto rects = tc::make_vector(tc::transform(c const& w) { return w.bounding_box(); } )); // https://github.com/think-cell/think-cell-library 1 2 void vertical_center(WidgetContainer const& c) { 3 4 5 // Magic happens 6 tc::for_each(tc::zip(c0 码力 | 132 页 | 14.20 MB | 5 月前3Building a Coroutine-Based Job System Without Standard Library
together. 67 void __sum_resume(void* ptr); struct __sum_frame { __sum_frame(int a, int b); promise_type promise; int resumeIndex = 0; void(* const resumefn)(void*) = __sum_resume; void(* const destroyfn)(void*); destroyfn)(void*); struct param_t { int a; int b; } params; union { initial_suspend_awaitable_t initial_suspend_awaitable; final_suspend_awaitable_t final_suspend_awaitable; }; }; tasksum(int b); decltype(auto) returnObject = frame->promise.get_return_object(); __sum_resume(static_cast<void*>(frame.release())); return returnObject; } template struct task; task sum(int 0 码力 | 120 页 | 2.20 MB | 5 月前3How Meta Made Debugging Async Code Easier with Coroutines and Senders
main(int argc, char** argv) { unifex::static_thread_pool pool; io_uring_context ctx; unifex::task<void> task = async_main({argv + 1, argc - 1}, pool, ctx); unifex::sync_wait(std::move(task)); return main(int argc, char** argv) { unifex::static_thread_pool pool; io_uring_context ctx; unifex::task<void> task = async_main({argv + 1, argc - 1}, pool, ctx); unifex::sync_wait(std::move(task)); return main(int argc, char** argv) { unifex::static_thread_pool pool; io_uring_context ctx; unifex::task<void> task = async_main({argv + 1, argc - 1}, pool, ctx); unifex::sync_wait(std::move(task)); return0 码力 | 131 页 | 907.41 KB | 5 月前3Calling Functions A Tutorial
Dispatch Deleting Functions Name Lookup(Un-)Qualified Name Lookup 16 void f( double ); // (1) namespace N1 { void f( int ); // (2) } // namespace N1 int main() { } // Unqualified (1) // Qualified lookup; calls (2) f( 1.0 ); f( 42 ); N1::f( 42 );(Un-)Qualified Name Lookup 17 void f( double ); // (1) namespace N1 { } // namespace N1 int main() { } // Unqualified lookup; N1::f( 42 );(Un-)Qualified Name Lookup 18 void f( double ); // (1) namespace N1 { void f( int ); // (2) void g() { N1::f( 1.0 ); } void h() { f( 1.0 ); } } // namespace N10 码力 | 111 页 | 5.11 MB | 5 月前3Breaking Dependencies: The SOLID Principles
getRotation(), … void translate( Vector3D const& ); void rotate( Quaternion const& ); private: double radius; // ... Remaining data members class Circle { public: void draw( Screen& Screen& s, /*...*/ ); void draw( Printer& p, /*...*/ ); void serialize( ByteStream& bs, /*...*/ ); }; // ... // ...19 The Single-Responsibility Principle (SRP) explicit Circle( double rad getRotation(), … void translate( Vector3D const& ); void rotate( Quaternion const& ); private: double radius; // ... Remaining data members class Circle { public: void draw( Screen&0 码力 | 96 页 | 2.14 MB | 5 月前3Coroutines and Structured Concurrency in Practice
the task to run alongside the rest of the programDetached tasks considered harmful // don’t do this void bad(tcp::socket& s) { std::arraybuf(1024); asio::co_spawn( ex, [&s no automatic object lifetime managementDetached tasks considered harmful // don’t do this either void slightly_better(tcp::socket& s) { auto buf = make_shared (1024); asio::co_spawn( }, asio::detached); }Detached tasks considered harmful // and also don’t do this void slightly_better(tcp::socket& s) { auto buf = make_shared (1024); asio::co_spawn( 0 码力 | 103 页 | 1.98 MB | 5 月前3Design Patterns
against ~Animal() = default; // “wrong” Derived class friend Derived; public: void make_sound() const { // ... } }; class Sheep : public Animal{ public: public: void make_sound() const { // ... } }; class Sheep : public Animal { public: //~Sheep(); Remember the Rule-of-5 // ... void make_sound() const { against ~Animal() = default; // “wrong” Derived class friend Derived; public: void make_sound() const { static_cast (*this).make_sound(); } }; class Sheep 0 码力 | 136 页 | 7.95 MB | 5 月前3Performance Matters
hard? Performance Analysis how to do it rightint main(int argc, char **argv) { topFrame = (void**)__builtin_frame_address(0); setHandler(Trap::TrapSignal, onTrap); setHandler(SIGALRM, f->setTrap(); } setTimer(interval); int r = stabilizer_main(argc, argv); return r; } void setTimer(int msec) { struct itimerval timer; timer.it_value.tv_sec = (msec - msec % 1000) setitimer(ITIMER_REAL, &timer, 0); } A Typical performance evaluation static void flush_icache(void* begin, size_t size) { uintptr_t p = (uintptr_t)begin & ~15UL; for (size_t i =0 码力 | 197 页 | 11.90 MB | 5 月前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100
相关搜索词
TheSurprisingCostsofVoidTemplateMetaprogrammingTypeTraitsReusableCodeDataStructuresBuildingCoroutineBasedJobSystemWithoutStandardLibraryHowMetaMadeDebuggingAsyncEasierwithCoroutinesandSendersCallingFunctionsTutorialBreakingDependenciesSOLIDPrinciplesStructuredConcurrencyinPracticeDesignPatternsPerformanceMatters