geode-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Kimura <>
Subject [DISCUSS] Using out parameters and its effects on function overload resolution
Date Wed, 27 Sep 2017 19:22:11 GMT
Is there a use case in our C++ client code to ever use out parameters?

Currently code uses out parameters to return multiple values from a
function.  [1]

virtual int64_t* PdxReader::readLongArray(const char* fieldName, int32_t&
length) = 0;

In this case, we could return a tuple instead.  I think the advantage of
this is it doesn't force a separation between the variable declaration and
assignment, which may lead to spaghetti code.  I think avoiding out
parameters also leads to more well defined behavior.  What would one expect
if they called getCqListeners with an already partially populated vector?

virtual void CqAttributes::getCqListeners(std::vector<CqListenerPtr& v) = 0;

As a counter argument, could function overload resolution be a valid use
case of out parameters?  In PdxReader::readType methods, Type seems
redundant.  As a user, why should I have to call readLongArray(int64_t[]&)
rather than just call read(int64_t[]&)?  In this case, if we didn't use out
parameter our signature clashes with other read methods.




  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message