|
Boost : |
From: Maxim Shemanarev (mcseem_at_[hidden])
Date: 2002-09-20 18:27:38
That's me again with my stupid questions :-)
It's not explicitely indicated in the BOOST guidelines what I should
prefer - pointer or reference when I have to use semantically "out" or
"in-out" arguments. I know it's better to use "functional" style when we
have only one return value, but that's not always desirable for the sake of
performance and/or resource usage. I'm in doubts about it. One of the
fundamental rules says that the semantics of a call should be clear itself,
i.e, if written
some_very_complex_class v;
foo(v);
I should expect that the status of "v" won't change after the call. If it
can be changed, use
foo(&v);
which explicitely tells you about it. In other words, "all reference
arguments must be const, otherways use pointers". It's a good rule from the
point of view that when you read someone's code it's more self-documented
because in this case you don't have to look at the function
definition/docs/implementation.
But there's another rule: "Use pointers when and only when it potentially
can be 0, otherways use references". This rule also looks logical, although
I technically can pass "a reference to the null-pointer", but I don't
consider this case because it's not well-formed code.
So, my question is just about BOOST gurus' preferences. What do you
prefere - non-const references or non-const pointers when you have to use
them as function arguments and when a pointer (if used) cannot be 0?
I'm sorry if this question had been already discussed - just point me out.
McSeem
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk