Boost logo

Boost :

From: Justin M. Lewis (boost_at_[hidden])
Date: 2003-05-02 03:29:50


Oh, there's posted code for these things.
http://groups.yahoo.com/group/boost/files/in_out/

----- Original Message -----
From: "John Torjo" <john_at_[hidden]>
To: "Boost mailing list" <boost_at_[hidden]>
Sent: Friday, May 02, 2003 12:55 AM
Subject: Re: [boost] Re: in/out parameters, codingstylesandmaintenance

> Hi all,
>
> Sorry, there have been way too many messages on this thread and I could
not
> have read them all. However, if the code for out, in_out has not been
posted
> yet, I guess a simple solution would be the following:
>
> ----------------------------
> // works for gcc 3.2
> #include <string>
> #include <iostream>
>
> template< class type>
> struct out_t : public type
> {
> template< class other_type> type & operator=( other_type val)
> {
> type::operator=( val);
> return *this;
> }
> };
>
> template< class type>
> struct in_out_t : public type
> {
> template< class other_type> type & operator=( other_type val)
> {
> type::operator=( val);
> return *this;
> }
> };
>
> template< class type>
> inline out_t< type> & out( type & val)
> { return (out_t< type> &)val; }
>
> template< class type>
> inline in_out_t< type> & in_out( type & val)
> { return (in_out_t< type> &)val; }
>
> void f( out_t< std::string> & a, const std::string & b, in_out_t<
> std::string> & c)
> {
> a = "a";
> c = "c";
> }
>
>
> int main()
> {
> std::string x, y, z;
> std::cout << "x=" << x << std::endl;
> std::cout << "z=" << z << std::endl;
> f( out( x), y, in_out( z));
> // f( x, y, z); // ERROR - could not convert from ... to ...
>
> std::cout << "x=" << x << std::endl;
> std::cout << "z=" << z << std::endl;
> std::cin.get();
> }
> -----------------------------
>
>
> (this would not work for fundamental types, but we could provide a
> specialization for them)
>
> Of course, it's not a full implementation, but it's a good start. What do
> you think?
>
> Best,
> John
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


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