On Tuesday, 29 November 2016 at 15:56:23 UTC, Jerry wrote:
To avoid having to use the Object class directly you can make
an base class of the class template.
Like:
```
abstract class MyClass {}
abstract class MyClassImpl(T)
{
public:
@property const(T) value(){return _value;}
@property
We have a handy dandy syntax for this:
if (MyClassInt subclass = cast(MyClassInt)value) {
writeln(subclass.value);
}
If it doesn't cast to said type (it will be null) that branch
won't execute.
Hell yeah! It's works!
Thank you!
Thats because MyClass is a template class. Templates are note
types, instansiations of templates can be types.
e.g.
Myclass!float[] arr; // note this is not MyClass!(float[]);
will work. As Rikki suggested using Object[] instead will allow
use to store classes of different types.
Maybe
On Monday, 28 November 2016 at 11:30:23 UTC, rikki cattermole
wrote:
In your case I'd just swap out ``MyClass[] someArray;`` to
``Object[] someArray;``.
But only because there are no members added without the extra
typing in MyClass.
Remember types in meta-programming in D are not erased, they
Hi.
Is it possible to write in D something like this?
```
abstract class MyClass(T)
{
public:
@property const(T) value(){return _value;}
@property void value(T val){_value = val;}
...
private:
T _value;
...
}
...
class MyClassFloat: MyClass!float
...
class MyClassInt: MyClass!int
..
On Thursday, 27 October 2016 at 13:37:29 UTC, Steven
Schveighoffer wrote:
Hm... what about:
import std.traits: Parameters;
auto mySpawn(F)(F func, Parameters!F params)
{
static auto callIt(F func, Parameters!F params)
{
try
{
return func(params);
}
I found http://arsdnet.net/this-week-in-d/2016-aug-07.html
Maybe it's helps me.
On Friday, 28 October 2016 at 03:38:05 UTC, dm wrote:
On Thursday, 27 October 2016 at 13:37:29 UTC, Steven
Schveighoffer wrote:
Hm... what about:
...
Main thread still running.
Actually it's depends on compiler.
With ldc2 main thread doesn't stop, but with dmd seems all ok:
root@proxytest:~#
On Thursday, 27 October 2016 at 13:37:29 UTC, Steven
Schveighoffer wrote:
Hm... what about:
...
Main thread still running.
Thanks all.
I gues I must rewrote my app to send exeptions to other threads,
use non blocking io, etc, etc.
On Wednesday, 26 October 2016 at 10:09:05 UTC, rikki cattermole
wrote:
If you throw an error it should crash the entire application.
But really you need to set up sync points within your
application to allow it to die gracefully.
I tried throw new Error... But main thread still working.
Tried
On Wednesday, 26 October 2016 at 09:43:10 UTC, rikki cattermole
wrote:
```D
void entryPoint(alias func)() {
try {
func();
} catch (Exception e) {
import std.stdio;
writeln(e.toString());
}
}
void main() {
auto tid =
On Wednesday, 26 October 2016 at 08:53:13 UTC, rikki cattermole
wrote:
Simple, handle the exceptions on each thread.
I don't want handle exceptions. I want my application crash with
exception description. Can you change my code above to show how
it can be made?
Hi. I tried code below:
import std.concurrency;
import std.stdio;
void func()
{
throw new Exception("I'm an exception");
}
void main()
{
auto tID = spawn(&func);
foreach(line; stdin.byLine)
send(tID, "");
}
I expect my application will die immediatly, but main thread
still
14 matches
Mail list logo