Boost logo

Boost :

From: Erdei Andras (ccg_at_[hidden])
Date: 2003-04-25 01:53:54


On Thu, 24 Apr 2003, Augustus Saunders wrote:

> 1) We normally pay a lot of attention to safety of usage,
clarity of
> intent, confusion from subtle semantics etc in our
discussions.
> Sometimes we might even belabour the point (though I think
it's
> healthy). This question goes to the library writers here.
 Would you
> replace:
<snip>

generally not. when i was new to c++, this was a thing that
really bothered me, but it turned out that on well designed
interfaces it's quite obvious which args are in, and which ones
are in-out.

otoh atm i'm using a badly designed api, where half the
parameters
are in-out (embedded system, no exception-handling, all return
values are error codes), and it isn't obvious at all which half.

it's not that problematic when writing new code, but when
reading
or debugging code already writen it's a real pain in the lower
region.

so the proposed original usage (using the helper class to turn
badly designed legacy code into something comprehensible in a
fairly painful, mechanical way) seems very appealing to me.

another usage i can imagine is function overloads:

bool f( T const & ) ;
bool f( in_out< T > & ) ;

somethimes you only want to know if a computation is doable,
and sometimes you also need the result. this can be better than
having two functions with different names -- goof names are hard
to come by.

but, as someone suggested, only experience call tell whether
this
is really usable; someone brave enough please try it, and let us
know after a few months whether it works :O)

> Lastly, if the proposed implementation has been posted, I
missed it,
> so can somebody post it or a link again?

i don't remember any implementation, but just off the top of
my head:

  template < typename value_type_ >
struct in_out_arg
  {
    typedef value_type_ value_type ;
    value_type & value ;
    explicit in_out_arg( value_type & value ) : value( value
) {}
        operator value_type & () { return value ; } ;
  } ;

  template < typename value_type >
        in_out_arg< value_type >
in_out( value_type & value )
  {
    return in_out_arg< value_type >( value ) ;
  }

  bool
f( in_out_arg< int > i )
  {
          i = 1 ;
          ++i ;
          return false ;
  }

        int i = 0 ;
        f( in_out( i ) ) ;

br,
andras


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk