- Nested (not early exit) returns - 3 Updates
- Factory pattern and MIRSA C++ Guidelines on Dynamic Allocation - 1 Update
- Array member initialization, gcc vs. clang - 1 Update
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 07 06:09PM +0200 I think this code is just fine, nothing particularly wrong, but I'm concerned I've changed into a mindset where I think so because I don't /see/ how wonderfully clearly it could be expressed otherwise? I remember discussing SESE/SEME with Andrei Alexandrescu over in clc++m once, where I insisted on SESE being more clear and less error prone. That view was, I now think, very much colored by experience maintaining some ugly C code with umpteen-hundred line functions. But anyway I now see things very differently, and I can't recall how I then thought. Is there some natural non-`return` way to code this that isn't needlessly complex or inefficient, perhaps even better in some way? class Key_event_stream : public Non_copyable , public Non_movable { private: Ref_<Event_stream> all_events_ = Event_stream::singleton(); ~Key_event_stream() {} public: auto has_event() const -> bool { for( ;; ) { if( all_events_.has<Key_event>() ) { return true; } else if( all_events_.has<Event>() ) { all_events_.next_event(); // Consume non-key event. } else { return false; } } } auto next_event() -> Key_event { for( ;; ) { Boxed_event result{ all_events_.next_event() }; if( result.pointer_to<Key_event>() != nullptr ) { return *result.pointer_to<Key_event>(); } } } static auto singleton() -> Ref_<Key_event_stream> { static Key_event_stream the_instance; return the_instance; } }; Cheers!, - Alf |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 07 06:12PM +0200 On 07.07.2016 18:09, Alf P. Steinbach wrote: > I think this code is just fine, nothing particularly wrong, but I'm Oh yes, the `if` can be simplified I see just after posting. Sorry 'bout that, :) - Alf |
"K. Frank" <kfrank29.c@gmail.com>: Jul 07 01:34PM -0700 Hello Alf! On Thursday, July 7, 2016 at 12:11:37 PM UTC-4, Alf P. Steinbach wrote: > ... > I remember discussing SESE/SEME with Andrei Alexandrescu ... All this talk of SESE/SEME reminds me of fortran with its support for multiple entry points into the same subroutine. > Cheers!, > - Alf Cheerio! K. Frank |
"Öö Tiib" <ootiib@hot.ee>: Jul 07 07:25AM -0700 On Wednesday, 6 July 2016 04:43:30 UTC+3, Mark wrote: > > /Flibble > Do you have a reference or can you provide sample code illustrating > factory design use withouth dynamic freestore-based allocation? Can you be more specific what you see there as a challenge? Reference ... perhaps C++ FAQ ... may be that one: https://isocpp.org/wiki/faq/dtors#placement-new |
ram@zedat.fu-berlin.de (Stefan Ram): Jul 07 02:42AM >>What do you mean "explicit initializer"? The array is being initialized >>in both cases. >Explicit initializer in the declaration of each constant. The section »12.6.1« of C++ indeed is titled »Explicit initialization«, but the syntactic category is just called »initializer« without »explicit« IIRC. However, the informative annex C uses »explicit or implicit initializer«. I am not sure if I know what an »implicit initializer« is, though. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment