How to wrap SDL?

Christopher Nicholson-Sauls ibisbasenji at gmail.com
Sat Jan 22 13:25:16 PST 2011


On 01/22/11 14:53, Sean Eskapp wrote:
> == Quote from Andrej Mitrovic (andrej.mitrovich at gmail.com)'s article
>> You can use scoped!() from std.typecons:
>> import std.stdio;
>> import std.typecons;
>> class A
>> {
>>     ~this()
>>     {
>>         writeln("A destructor");
>>     }
>> }
>> void foo()
>> {
>>     auto a1 = scoped!A();
>> }
>> void main()
>> {
>>     foo();
>>     writeln("exiting..");
>> }
>> You must not escape a reference to the object outside of the foo()
>> scope. Note that you will get a runtime error if you try to do
>> something like this:
>> import std.stdio;
>> import std.typecons;
>> class A
>> {
>>     ~this()
>>     {
>>         writeln("A destructor");
>>     }
>> }
>> auto foo()
>> {
>>     auto a1 = scoped!A();
>>     return a1;
>> }
>> void main()
>> {
>>     auto result = foo();
>>     writeln("exiting..");
>> }
>> Illegal call to Scoped this(this)
>> A destructor
>> core.exception.AssertError at std.typecons(2506): Assertion failure
> 
> But these can't be passed to functions either, meaning I can't pass a Screen,
> Text, or Font wrapper around, all of which I use in my project!

Then try struct, with parameters mostly defined as ref.  And possibly
take a look at std.typecons.RefCounted.

-- Chris N-S



More information about the Digitalmars-d-learn mailing list