You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
D offers only scoped destruction and not resource acquisition is initialization. Basically the resource is not always acquired during initialization as struct in D can't have default constructors. Library implementations like Automem makes using RAII in D as easy as C++, but only for heap memory and not for all kinds of resources (like mutex, etc). It is unfair to say that D supports RAII. Its RAII is nowhere close to what C++ offers that it shouldn't be called RAII by definition.
The text was updated successfully, but these errors were encountered:
Adding a dummy argument is the common workaround for lack of default struct constructors:
structA{
T data;
this(int dummy){
// initialize data
}
~this(){
// deinitialize data
}
}
voidmain(){
voidfun(){
auto a = A(0);
// ~A called deterministically upon scope exit
}
}
What are the limitations of this workaround pattern? (honest question)
D offers only scoped destruction and not resource acquisition is initialization. Basically the resource is not always acquired during initialization as
struct
in D can't have default constructors. Library implementations like Automem makes using RAII in D as easy as C++, but only for heap memory and not for all kinds of resources (like mutex, etc). It is unfair to say that D supports RAII. Its RAII is nowhere close to what C++ offers that it shouldn't be called RAII by definition.The text was updated successfully, but these errors were encountered: