Topic: operator { and }
Author: jonathanmcdougall@DELyahoo.ca (Jonathan Mcdougall)
Date: Mon, 3 May 2004 16:37:17 +0000 (UTC) Raw View
This is what I have been thinking of late :
class C
{
public:
void operator { (params) // operator opening-curly-bracket
{
// some initialization
}
void operator } (params) // operator closing-curly-bracket
{
// some clean-up
}
// ...
};
int main()
{
C c;
c (params)
{
// some operations
}
}
which would be resolved to
c.operator { (params);
{ // new scope
// operations
} // end of scope
c.operator } (params);
This would replace something like
c.start(params);
// operations
c.end(params);
The parameters passed to operators { and } would be the same, that is
c (2)
{
}
would resolve to
c.operator { (2);
{
}
c.operator } (2);
What do you think?
Jonathan Mcdougall
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: loic.actarus.joly@wanadoo.fr (=?ISO-8859-1?Q?Lo=EFc_Joly?=)
Date: Mon, 3 May 2004 20:30:29 +0000 (UTC) Raw View
Jonathan Mcdougall wrote:
> This is what I have been thinking of late :
>=20
> class C
> {
> public:
> void operator { (params) // operator opening-curly-bracket
> {
> // some initialization
> }
>=20
> void operator } (params) // operator closing-curly-bracket
> {
> // some clean-up
> }
>=20
> // ...
> };
[...]
> This would replace something like
>=20
> c.start(params);
> // operations
> c.end(params);
>=20
>=20
> The parameters passed to operators { and } would be the same, that is
>=20
> c (2)
> {
> }
>=20
> would resolve to
>=20
> c.operator { (2);
> {
> }
> c.operator } (2);
>=20
>=20
> What do you think?
I do not really see the advantages compared to the cannonical solution :
class C
{
C(){} // Some initialisation
~C() {} // Some clean-up
};
{
C c;
// Operations
}
--=20
Lo=EFc
I wonder if there if any symbol in the basic character set that has=20
never been proposed for operator overloading... Maybe ';' ?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: tom_usenet@hotmail.com (tom_usenet)
Date: Tue, 4 May 2004 15:31:06 +0000 (UTC) Raw View
On Mon, 3 May 2004 16:37:17 +0000 (UTC), jonathanmcdougall@DELyahoo.ca
(Jonathan Mcdougall) wrote:
>This is what I have been thinking of late :
> c (params)
> {
> // some operations
> }
>What do you think?
Well, I don't see any major syntatic or semantic benefit over the
proxy version:
{
mutex::scoped_lock cerberos(mymutex /*optional params*/);
foo();
bar();
//destructor of cerberos called here
}
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jonathanmcdougall@DELyahoo.ca (Jonathan Mcdougall)
Date: Tue, 4 May 2004 17:31:01 +0000 (UTC) Raw View
Lo=EFc Joly wrote:
> Jonathan Mcdougall wrote:
>=20
>> This is what I have been thinking of late :
>>
>> class C
>> {
>> public:
>> void operator { (params) // operator opening-curly-bracket
>> {
>> // some initialization
>> }
>>
>> void operator } (params) // operator closing-curly-bracket
>> {
>> // some clean-up
>> }
>>
>> // ...
>> };
>=20
> [...]
>=20
>> This would replace something like
>>
>> c.start(params);
>> // operations
>> c.end(params);
>>
>>
>> The parameters passed to operators { and } would be the same, that is
>>
>> c (2)
>> {
>> }
>>
>> would resolve to
>>
>> c.operator { (2);
>> {
>> }
>> c.operator } (2);
>>
>>
>> What do you think?
>=20
>=20
> I do not really see the advantages compared to the cannonical solution =
:
>=20
> class C
> {
> C(){} // Some initialisation
> ~C() {} // Some clean-up
> };
>=20
> {
> C c;
> // Operations
> }
Of course the example applied to cases where the object you get is=20
already constructed :
void f(C &c)
{
c
{
// ...
}
}
The syntax could at the same time be a vb-like With block :
c
{
.something(); // applies to c
}
Actually, I got that marvelous idea with something like
class graphics
{
public:
void start_render(context &c);
void end_render(context &c);
void draw(something s);
};
void f(graphics &g)
{
g.start_render( my_context );
g.draw( my_something );
g.end_render( my_context );
}
which could look like
class graphics
{
public:
operator{ (context &c); // no return type, parameters
operator} (context &c); // must match
void draw(something s);
};
void f(graphics &g)
{
g( my_context )
{
.draw ( my_something );
}
}
> I wonder if there if any symbol in the basic character set that has
> never been proposed for operator overloading... Maybe ';' ?
Heh.
Jonathan
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nobody@example.com (Ian McCulloch)
Date: Tue, 4 May 2004 18:02:12 +0000 (UTC) Raw View
Lo=EFc Joly wrote:
> Jonathan Mcdougall wrote:
[...]
>> The parameters passed to operators { and } would be the same, that is
>>=20
>> c (2)
>> {
>> }
>>=20
>> would resolve to
>>=20
>> c.operator { (2);
>> {
>> }
>> c.operator } (2);
>>=20
>>=20
>> What do you think?
>=20
> I do not really see the advantages compared to the cannonical solution =
:
>=20
> class C
> {
> C(){} // Some initialisation
> ~C() {} // Some clean-up
> };
>=20
> {
> C c;
> // Operations
> }
>=20
>=20
This is OK. But it is slightly awkward, and for most purposes you don't
need to refer to the object inside the block. I think it would be nice o=
f
there was a way to 'inject' a local variable into a block (like what can =
be
done with a for/while/if etc) but without having to give it a name. For
example, given
class mutex;
class scoped_lock
{
scoped_lock(mutex&);
// ...
};
To use this currently requires something like
mutex M;
// ...
{
scoped_lock dummy(M);
// critical section
}
I think it would be nice to be able to write something like
mutex M;
// ...
with (scoped_lock(M))
{
// critical section
}
Although, I think overloading operator{ is not a good way to achieve this=
;)
Cheers,
Ian
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: usenet-nospam@nmhq.net (Niklas Matthies)
Date: Wed, 5 May 2004 01:04:26 +0000 (UTC) Raw View
On 2004-05-04 17:31, Jonathan Mcdougall wrote:
:
> void f(graphics &g)
> {
> g( my_context )
> {
> .draw ( my_something );
> }
> }
You can have
void f(graphics & g)
{
scoped_rendering(g, context) sr;
g.draw(something);
}
today.
-- Niklas Matthies
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]