public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "alvaro.begue at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108667] Spurious "may be used uninitialized [-Wmaybe-uninitialized]" warning Date: Mon, 06 Feb 2023 15:19:56 +0000 [thread overview] Message-ID: <bug-108667-4-C5rNZdj7sj@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-108667-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108667 --- Comment #4 from Alvaro Begue <alvaro.begue at gmail dot com> --- Original code: #include <functional> #include <vector> #include <iostream> template <typename ReturnType, typename... ArgumentTypes> class Signal { public: using Slot = std::function<ReturnType(ArgumentTypes...)>; using FoldingFunction = std::function<ReturnType(ReturnType, ReturnType)>; Signal(FoldingFunction fold, ReturnType initial) : fold(fold), initial(initial) {} void connect(Slot slot) { slots.push_back(slot); } ReturnType operator() (ArgumentTypes... arguments) { ReturnType result = initial; for (const auto &slot : slots) result = fold(result, slot(arguments...)); return result; } private: std::vector<Slot> slots; FoldingFunction fold; ReturnType initial; }; int four() { return 4; } int five() { return 5; } int main() { Signal<int> get_total([](int cumulative_value, int new_term){ return cumulative_value + new_term; }, 0); get_total.connect(four); get_total.connect(five); std::cout << get_total() << '\n'; }
prev parent reply other threads:[~2023-02-06 15:19 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-03 22:02 [Bug c++/108667] New: Spurious "maybe " alvaro.begue at gmail dot com 2023-02-04 0:07 ` [Bug tree-optimization/108667] Spurious "may be " pinskia at gcc dot gnu.org 2023-02-04 0:33 ` alvaro.begue at gmail dot com 2023-02-06 7:47 ` rguenth at gcc dot gnu.org 2023-02-06 15:19 ` alvaro.begue at gmail dot com [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108667-4-C5rNZdj7sj@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).