Re: [question] Access from UDA constructor to parent symbol

2016-12-26 Thread Ali Çehreli via Digitalmars-d-learn

On 12/26/2016 02:04 PM, crimaniak wrote:


So my main question: how it is possible to do such thing?


Just to make sure we're on the same page: :)

* There is 'interface' in addition to 'class'

* If all you want is to check, then you can write template constraints 
by following the example of std.range.isInputRange.


With that aside, what you need is generally achieved by a mixin:

@implements!I1
struct S1
{
// ...
}

template ValidateInterfaces() {
// Go through all members of the module here
// Identify the ones having the 'implements' UDA
// The useful tools here are
// __traits(getAttributes)
// __traits(allMembers)
// __traits(getMember)
}

mixin ValidateInterfaces;

Ali



Re: [question] Access from UDA constructor to parent symbol

2016-12-26 Thread crimaniak via Digitalmars-d-learn

On Monday, 26 December 2016 at 21:15:03 UTC, Adam D. Ruppe wrote:

On Monday, 26 December 2016 at 20:07:56 UTC, crimaniak wrote:
 // I want to see Foo here and use it's reflection to 
iterate fields and methods.


then pass foo to it

What do you mean parent symbol? I assumed you mean subclass but 
your example shows one class and one struct. So is it the 
structure containing the class? Or what?


I mean the character to which the attribute belongs, Foo in this 
case.





But, the answer of just passing the argument is probably the 
best one anyway. You can use a factory function, or pass the 
type from a constructor to a super method, or something like 
that.
Let me explain. I want to have struct Foo : BarInterface {}. I 
read forums and found some discussion. Arguments against this 
feature has no sense on my opinion. But in fact I don't think it 
will be implemented. So I try to implement it as library. My idea:


class implements(Interface)
{
this()
{
// iterate all members of Interface and check if this element
// exists in parent symbol and check if parameters the same.
// Write clean error message if contract fails.
}
}

unittest
{
interface I1
{
void foo();
int bar(int i);
}


@implements!I1
struct S1
{
void foo()
{
import std.stdio;
writeln("foo");
}

		// I want error message like "function int bar(int i) should be 
implemented according to interface I1" in this case

}
}

So, if I pass both types in parameters it will not be so clean. 
It will be some separate from struct expression, but I want 
attribute like above.


It seems I can find symbol iterating all symbols in __MODULE__but 
in this case it will be O(N^2), there N is amount of @implements 
usages in module.


I also thought about such option:

struct S1
{
mixin implements!I1;
...
}

But this option I like less, and I have not researched it.

So my main question: how it is possible to do such thing?




Re: Is there anything other than nullable to work with optional types?

2016-12-26 Thread aliak via Digitalmars-d-learn

On Monday, 26 December 2016 at 04:55:30 UTC, Seb wrote:

Then help to push it forward!!
There are many ways:
- review the PR and point out anything problematic you see 
(lack of reviews/interest  is a main reason why PRs get stalled)
- post reasons and arguments for merging this PR (seems like 
you have a couple of good real world examples - post them!)
- revive the PR (it's quite old and the author probably lost 
interest. There's absolutely nothing wrong with taking the diff 
and resubmitting it - on the contrary that's often the only 
possible way to revive/save old PRs)

...


Sure, will take a gander. Might try and revive if I feel up to it 
after reading through but I don't think I'm comfortable enough 
with D yet to do that. But lets see.




Re: [question] Access from UDA constructor to parent symbol

2016-12-26 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 26 December 2016 at 20:07:56 UTC, crimaniak wrote:
 // I want to see Foo here and use it's reflection to 
iterate fields and methods.


then pass foo to it

What do you mean parent symbol? I assumed you mean subclass but 
your example shows one class and one struct. So is it the 
structure containing the class? Or what?



But, the answer of just passing the argument is probably the best 
one anyway. You can use a factory function, or pass the type from 
a constructor to a super method, or something like that.


[question] Access from UDA constructor to parent symbol

2016-12-26 Thread crimaniak via Digitalmars-d-learn

```
class uda
{
this()
{
 // I want to see Foo here and use it's reflection to 
iterate fields and methods.

}
}


@uda
struct Foo
{

}

```
Is there a way to do it?


Build your own Trie entry table

2016-12-26 Thread Remi Thebault via Digitalmars-d-learn

Hello

I want to map a dchar to its Bidi_Class.

I've built an utility that reads UnicodeData.txt into an AA and 
builds a trie with std.uni.codepointTrie from it.
I use Trie.store() to export the trie entry table into a D 
module. (I believe in a similar manner than phobos' 
unicode_tables.d)


Now I want to use this table to efficiently create a Trie in my 
code, the same way std.uni does, but found out that Trie 
constructor is private.


I've copy-pasted the asTrie function (and also TrieEntry struct) 
in my code and it works well (which I don't understand because my 
code still ends up calling the private ctor).


Can you give indication on the workflow one should follow for 
this use case?


Thanks
Rémi