C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Quick Idea: Enable/Disable Auto Gens

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 8 Jul 2022 13:13:04 +0200
Hi Oktlryk, this can be done with the current language.   class endis { public:     endis(bool& flag) : _flag(flag) {};     void enable() { _flag = true; };     void disable() { _flag = false; }; private:     bool& _flag; };   Then use it as MyClass { public:     bool setMe;     endis Stuff(setMe); };   MyClass myclass; myclass.Stuff.enable(); myclass.Stuff.disable();   You can even get "= enable" and "= disable" syntax by enable() returning an Object (or directly using endis for it), which supports assignment of enable and disable class enums.   It is more a question of, what the Unreal Engine requires. The first part is, how to find the boolean variable or the Disable and Enable functions. Are they explicitly inserted into C++ classes, or are they listed in arrays/vectors (by index) or maps (by numeric/symbolic/string key).   The second part is, why to use Disable and Enable functions in the first place. Do they provide additional functionality like logging/debugging/generating events or are they a customization point for changing the behavior. Then you have to decide, if all Enable and Disable functions can be programmed with one implementation or if you would provide a default, which can be overridden. The current language provides a lot of options, but those usable would be limited by the specific requirements of the design of the Unreal Engine.   For general auto generation there are plans to provide enhanced metaprogramming capabilities with C++ after the introduction of Reflection functionality. (Until then there are also C macros.)   But probably you would not need them for this use case.   Best, Sebastian   -----Ursprüngliche Nachricht----- Von:Oktlryk via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Fr 08.07.2022 11:57 Betreff:[std-proposals] Quick Idea: Enable/Disable Auto Gens An:std-proposals_at_[hidden]; CC:Oktlryk <oktlryk_at_[hidden]>; Hello  I was doing a course over at Udemy on Unreal Engine C++ programming, and tons of the code (I mean there were a lotta functions involving this) enabled or disabled some boolean or set some value to true/false, as like in semaphore types.  And I had to write two functions for each like: void EnableStuff() + void DisableStuff(). Which got me thinking, why not handle this at the language level. Like you could indicate if a function was a Enable/Disable actuator and only require the expressed inclusion of the function in definition. For example:  void endis Stuff(bool setMe); // endis (Enable/Disable keyword)  then when calling:  Stuff.enable() = enable // sets setMe to true Stuff.disable() = disable // sets setMe to false  And C++ automatically generates the enable/disable switches, not requiring further function defs and so on!! This will definitely be a super cool improvement to the C++ QOL.    -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals  

Received on 2022-07-08 11:13:06