On Friday, 16 June 2023 at 01:54:22 UTC, Jonathan M Davis wrote:
```d
doSomething();
scope(exit) undoSomething();
```
Thank you for your `wonderful summary`. It's worth saving the
link.
On Friday, 16 June 2023 at 01:45:35 UTC, CM wrote:
```d
auto m = Man();
assert(m.name == defaultName);
```
Do note that one cannot simultaneously have a constructor and a
static opCall, even if their parameters differ.
Thank you for your reply. This should be enough, as this type of
RAII
On Thursday, June 15, 2023 7:54:22 PM MDT Jonathan M Davis via Digitalmars-d-
learn wrote:
> On Thursday, June 15, 2023 7:18:25 PM MDT zjh via Digitalmars-d-learn wrote:
> > On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer
> >
> > wrote:
> > > B b = B.make(); // call factory function
On Thursday, June 15, 2023 7:18:25 PM MDT zjh via Digitalmars-d-learn wrote:
> On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer
>
> wrote:
> > B b = B.make(); // call factory function
> >
> > -Steve
>
> Thank you for your tip.
> If could simplify it a bit more, it would be even
On Friday, 16 June 2023 at 01:18:25 UTC, zjh wrote:
On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer
wrote:
B b = B.make(); // call factory function
-Steve
Thank you for your tip.
If could simplify it a bit more, it would be even better. It's
really uncomfortable without
On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer
wrote:
B b = B.make(); // call factory function
-Steve
Thank you for your tip.
If could simplify it a bit more, it would be even better. It's
really uncomfortable without `this()`.
On 6/15/23 8:52 PM, zjh wrote:
On Friday, 16 June 2023 at 00:35:48 UTC, Steven Schveighoffer wrote:
Instead, you can use factory functions to initialize.
How can `factory functions` be used to achieve effects similar to `'RAII'`?
Thank you.
B b;
becomes
B b = B.make(); // call factory
On Friday, 16 June 2023 at 00:35:48 UTC, Steven Schveighoffer
wrote:
Instead, you can use factory functions to initialize.
-Steve
How can `factory functions` be used to achieve effects similar to
`'RAII'`?
Thank you.
On 6/15/23 8:45 PM, zjh wrote:
On Friday, 16 June 2023 at 00:35:48 UTC, Steven Schveighoffer wrote:
But there is no way in D to have e.g.:
```d
B b; // runs a constructor
```
As a `C++` user, it is very terrible to simplify `RAII` without such a
method. Why must `this()` be disabled?
On Friday, 16 June 2023 at 00:35:48 UTC, Steven Schveighoffer
wrote:
But there is no way in D to have e.g.:
```d
B b; // runs a constructor
```
-Steve
As a `C++` user, it is very terrible to simplify `RAII` without
such a method. Why must `this()` be disabled? Can't there be a
On Thursday, 15 June 2023 at 21:48:10 UTC, Ali Çehreli wrote:
I have difficulty understanding the question. I think the
nested structs, extern(C), static members, etc. confuse me. I
am assuming they are not related to this question.
Ali
I used the `class` to call the`
On 6/15/23 8:31 PM, zjh wrote:
Because disabled `this()`, the behavior of `this(int i)`is inconsistent
and cannot achieve similar `RAII` as `C++`. What should I do?
You cannot have parameter-less constructors in D structs. However,
destruction works the same.
Instead, you can use factory
On Thursday, 15 June 2023 at 21:48:10 UTC, Ali Çehreli wrote:
And this is by design: In D, we rename the type and be done
with it. In C++, one needs to rename a number of functions as
well.
Ali
```d
static int e=40;
struct B{
int m;
this(int i){
On 6/15/23 08:15, zjh wrote:
> I want `B` to become the following version similar to 'C++'. What should
> I do?
I have difficulty understanding the question. I think the nested
structs, extern(C), static members, etc. confuse me. I am assuming they
are not related to this question.
> ```cpp
```d
import core.stdc.stdio;
struct A{
static int e=40;
struct B{
int m;
this(int i){
printf("%i",e);m=i;
}
~this(){
e=m;
printf("%i",e);
}
}
void f(){
B b=e;e=6;
}
void g(){
On Thursday, 10 October 2019 at 16:33:47 UTC, H. S. Teoh wrote:
On Thu, Oct 10, 2019 at 03:58:02PM +, jmh530 via
Digitalmars-d-learn wrote:
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
> In C# you can do something like:
>
>
> if (obj is Person)
> {
> var
On Thu, Oct 10, 2019 at 03:58:02PM +, jmh530 via Digitalmars-d-learn wrote:
> On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
> > In C# you can do something like:
> >
> >
> > if (obj is Person)
> > {
> > var person = obj as Person;
> > // do stuff with
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
In C# you can do something like:
if (obj is Person)
{
var person = obj as Person;
// do stuff with person...
}
where you can check the type of an object prior to casting.
Does D have a similar
On Thursday, 10 October 2019 at 15:53:20 UTC, Adam D. Ruppe wrote:
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
if (obj is Person person)
Looks the same as D's
if(auto person = cast(Person) obj) {
// use person in here
} else {
// it was some other type
}
On Thursday, October 10, 2019 9:47:58 AM MDT Just Dave via Digitalmars-d-
learn wrote:
> In C# you can do something like:
>
>
> if (obj is Person)
> {
> var person = obj as Person;
> // do stuff with person...
> }
>
> where you can check the type of an object prior
On 10/10/19 6:47 PM, Just Dave wrote:
In C# you can do something like:
if (obj is Person)
{
var person = obj as Person;
// do stuff with person...
}
where you can check the type of an object prior to casting. Does D have
a similar mechanism? It's so widely
On Thursday, 10 October 2019 at 15:47:58 UTC, Just Dave wrote:
if (obj is Person person)
Looks the same as D's
if(auto person = cast(Person) obj) {
// use person in here
} else {
// it was some other type
}
Even though static solutions would be more performance minded,
I'd actually prefer to see the runtime equivalent so I don't have
to rethink how I think as performance isn't really my major
concern right now.
In C# you can do something like:
if (obj is Person)
{
var person = obj as Person;
// do stuff with person...
}
where you can check the type of an object prior to casting. Does
D have a similar mechanism? It's so widely useful in the C# realm
that they even added
24 matches
Mail list logo