On 2016-11-29 07:46, Marduk wrote:
Aha! Interesting. Thanks.
Then you can call a custom method that acts as a constructor when the
instance is created this way, if there's a need for it.
--
/Jacob Carlborg
On Sunday, 27 November 2016 at 20:57:28 UTC, Namespace wrote:
class Example(L, R)
{
L _left;
R _right;
this(L l, R r)
{
_left = l;
_right = r;
}
}
That was fast! But I needed the second reply in order to
understand yours. Thanks anyway.
On Sunday, 27 November 2016 at 21:06:58 UTC, ag0aep6g wrote:
Turn Example into a template, and add a free function for nice
construction:
class Example(Type_left, Type_right)
{
/* ... as you had it ... */
}
Example!(L, R) makeExample(L, R)(L x, R y)
{
return new Example!(L, R)(x,
On Monday, 28 November 2016 at 09:33:08 UTC, Jacob Carlborg wrote:
It's possible to bypass the constructors [1].
[1]
https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L166
Aha! Interesting. Thanks.
On Sunday, 27 November 2016 at 21:28:52 UTC, ag0aep6g wrote:
Ok, that's a hypothetical. It's "if D had a 'dynamic mixin',
then we could do fancy things with it." D doesn't have a
'dynamic mixin', so you can't do those fancy things, at least
not in the envisioned way.
You are right. I misread
On Monday, 28 November 2016 at 14:35:36 UTC, Namespace wrote:
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.
Just out of interest: it loo
On 11/27/16 2:10 AM, panmengh wrote:
How to get hash value of an object?
Use hashOf? or typeid(T).getHash(&o)?
hashOf is kind of this horrible hacky thing that nobody should be using.
It literally takes whatever you pass it and hashes the local bytes. It
doesn't care about opHash or if any o
On 29/11/2016 3:35 AM, Namespace wrote:
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.
Just out of interest: it looks like a dynamic_cast in C
On Saturday, November 26, 2016 00:43:04 Artur Skawina via Digitalmars-d-
learn wrote:
> IOW you want to improve IFTI, so that `n` is inferred from the
> length of the passed argument. That would indeed work for array
> literals and CTFE-able expressions. Any improvement to IFTI is a
> good thing, b
On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi
wrote:
The point is that I was trying to avoid some cycle between
modules, detected by 2.072. This bug leads to pollution in the
use of static this only to workaround the limitation...
Wasn't someone working on a Associative Array
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.
Just out of interest: it looks like a dynamic_cast in C++ which
is considered as slow oper
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 29/11/2016 2:56 AM, dm wrote:
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-progr
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
On Monday, 28 November 2016 at 11:26:41 UTC, dm wrote:
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 MyClassFl
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 exist in
the assembly and are unique. Unlike Java who did the implem
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 2016-11-27 22:19, Marduk wrote:
Sure, it's here:
http://forum.dlang.org/post/xmnnsdiuwyjrhkasy...@forum.dlang.org
In that thread they also mention Object.factory, but the documentation
says that the class must have either no constructor or the default
constructor, which is not my case.
It'
On Sunday, 27 November 2016 at 22:25:51 UTC, John Colvin wrote:
On Saturday, 26 November 2016 at 17:37:57 UTC, Paolo Invernizzi
wrote:
This is stated in documentation [1]:
immutable long[string] aa = [
"foo": 5,
"bar": 10,
"baz": 2000
];
unittest
{
assert(aa["foo"] == 5);
assert(
20 matches
Mail list logo