Thread overview
Meaning of Scoped! ??
Jul 30, 2019
Ron Tarrant
Jul 30, 2019
rikki cattermole
Jul 30, 2019
Andrea Fontana
Jul 30, 2019
Ron Tarrant
Jul 31, 2019
Ali Çehreli
July 30, 2019
Some things are almost impossible to research. For instance, in the GtkD wrapper code—specifically the Widget.d file—the following function definition appears:


	gulong addOnDraw(bool delegate(Scoped!Context, Widget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
	{
		return Signals.connect(this, "draw", dlg, connectFlags ^ ConnectFlags.SWAPPED);
	}


With contemporary search engines, it's impossible to search for '!' and get meaningful results. And searching for 'Scoped!' results in every variation of the word 'scope' and ignores the '!' altogether, even with Google's Verbatim tool turned on. Worse, Google ignores case as well.

I also searched all three D-language books and found nothing.

Here are my questions:

1) What exactly does the '!' mean? For instance, '=' means "is equal to," but I don't know what words to 'think' while looking at a '!'

2) What does 'Scoped' mean?

3) In the specific instance above, what does 'Scoped!Context' mean as opposed to just 'Context'? In other words, what are the differences between 'Scoped!Context' and 'Context'?

The last question needs more explanation...

In Widget.d, there are two overloads of addOnDraw(), the one cited above and this one:


	deprecated gulong addOnDraw(bool delegate(Context, Widget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
	{
		return Signals.connect(this, "draw", dlg, connectFlags ^ ConnectFlags.SWAPPED);
	}


The former works, but the latter spits out a 'deprecated' error (naturally).

July 30, 2019
On 30/07/2019 9:33 PM, Ron Tarrant wrote:
> Some things are almost impossible to research. For instance, in the GtkD wrapper code—specifically the Widget.d file—the following function definition appears:
> 
> 
>      gulong addOnDraw(bool delegate(Scoped!Context, Widget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
>      {
>          return Signals.connect(this, "draw", dlg, connectFlags ^ ConnectFlags.SWAPPED);
>      }
> 
> 
> With contemporary search engines, it's impossible to search for '!' and get meaningful results. And searching for 'Scoped!' results in every variation of the word 'scope' and ignores the '!' altogether, even with Google's Verbatim tool turned on. Worse, Google ignores case as well.
> 
> I also searched all three D-language books and found nothing.
> 
> Here are my questions:
> 
> 1) What exactly does the '!' mean? For instance, '=' means "is equal to," but I don't know what words to 'think' while looking at a '!'
>

Template

https://dlang.org/spec/template.html

> 2) What does 'Scoped' mean?

Its a type defined by GtkD by the looks.

https://github.com/gtkd-developers/GtkD/blob/e14091fb2df4d05348061f274c131700af89fb16/generated/gtkd/glib/c/types.d#L56

> 3) In the specific instance above, what does 'Scoped!Context' mean as opposed to just 'Context'? In other words, what are the differences between 'Scoped!Context' and 'Context'?

Auto destruction of the argument and you cannot copy its value around.
July 30, 2019
On Tuesday, 30 July 2019 at 09:33:04 UTC, Ron Tarrant wrote:
> Some things are almost impossible to research. For instance, in the GtkD wrapper code—specifically the Widget.d file—the following function definition appears:
>
>
> 	gulong addOnDraw(bool delegate(Scoped!Context, Widget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
> 	{
> 		return Signals.connect(this, "draw", dlg, connectFlags ^ ConnectFlags.SWAPPED);
> 	}
>

Scoped is a struct defined here:
https://github.com/gtkd-developers/GtkD/blob/e14091fb2df4d05348061f274c131700af89fb16/generated/gtkd/glib/c/types.d#L56

Looking at its source code, it seems it's a way to force the call of "destroy" method of wrapped object (Context in your case) when the struct goes out of its scope (and d-tor is called)

Andrea


July 30, 2019
On Tuesday, 30 July 2019 at 09:46:07 UTC, Andrea Fontana wrote:

> Looking at its source code, it seems it's a way to force the call of "destroy" method of wrapped object (Context in your case) when the struct goes out of its scope (and d-tor is called)
>
> Andrea

Thanks, Andrea (and rikki). I actually learned this a while back (even wrote about it in a blog post) but I've noticed my memory is playing tricks on me lately.

In fact, don't be surprised if I ask this same question (or a close variation of it) next month. (sigh)
July 31, 2019
On 07/30/2019 02:33 AM, Ron Tarrant wrote:

> With contemporary search engines, it's impossible to search for '!' and
> get meaningful results.

I recommend this Index section for such cases:

  http://ddili.org/ders/d.en/ix.html

Like most of Phobos, Scoped is not there but the "!, template instance" entry answers the other question. :)

Ali