c++ - Using boost::ref to indicate intention in coding conventions -
When a function takes a non-conference riff as a logic, it can make a hard-to-read code Because on the calling site it is not clear what input can be changed for example, for example
zero function (int input, int * output) instead of those pointers applied Have to lead some code conferences; Int input = 1, output = 0; Funk (input, and output); instead of
zero function (int input, int and output); Int input = 1, output = 0; Funk (input, output); Personally, I hate using the pointers because I need to check the null. It is surprising to me that to promote: Riff (or CT + :: 11 for std :: ref) can be used to indicate intent:
Void func (int input, int & amp;; output); Int input = 1, output = 0; Funk (input, boost :: ref (output)); This will be used as the company coding conference. My question is, is there any reason why it would not be a good idea?
This is not a bad idea, but it's not really implemented (as Piorranez notes). It is effectively just a comment.
We can do better though:
template & lt; Typename T & gt; Class Output_argent {public: template & lt; Typename u & gt; Friend's output_gangement & lt; U & gt; Outside (U & amp; re;); T & amp; Get () const {return MRF; } Operator T & amp; () Const {return find (); } Private: Clear Output_Certement (T & amp): MRF (RF) {} Output_Argument & amp; Operator = (console output_arugment & amp;); // not defined T & amp; MRef; }; Template & lt; Typename u & gt; Output_argument & lt; U & gt; Out (U & amp; Ref) {Return Output_Argument & lt; U & gt; (Referee); } give:
zero foo (int x, output_argument & lt; float & gt; f) {int i = static_cast & lt; Int & gt; (F); F.get () = Static_cast & lt; Float & gt; (I + x); } Int main () {float f = 5.0f; // failed: foo (1, f); Fu (1, outside (f)); } But generally these types of utilities are not required, because the name of the function should be argued what is happening with the argument: swap (x, y) Modification is quite clearly debated! And returning values should be done with the return type, this utility can be used to limit further cases.
Comments
Post a Comment