This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++ "with" keyword


The example

	struct S
	{
	    int x;
	    int y;
	};
	
	int main()
	{
	    S s;
	    with (s)
	    {
	        .x = 1;
	        .y = 2;
	    }
	    return 0;
	}

can easily be rewritten by introducing temporary references, as in

	int main()
	{
	    S s;
	    {
	        S& t = s;
	        t.x = 1;
	        t.y = 2;
	    }
	    return 0;
	}

This requires only one additional variable reference each time the 
"with" object is used.  Additionally, it allows several "with" objects 
(with different names) at the same time.  In C, the same thing can be 
done by using pointers.

-erik

-- 
Erik Schnetter <schnetter@uni-tuebingen.de>
Web: http://www.tat.physik.uni-tuebingen.de/~schnette/

My email is as private as my paper mail.  I therefore support encrypting
and signing email messages.  Get my PGP key from www.keyserver.net.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]