Re: Slow UDF call?

2019-08-18 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Aug 17, 2019 at 09:42:00PM +, Giovanni Di Maria via 
Digitalmars-d-learn wrote:
[...]
> I have also compiled with:
> dmd program.d -O -release -inline -boundscheck=off
> 
> and the execution speed is very very fast.
[...]

If performance is important to you, I recommend checking out LDC. IME,
it consistently produces code that outperforms dmd-generated code by
about 20-30%, sometimes even as high as 40-50%, depending on the nature
of your code.


T

-- 
Never ascribe to malice that which is adequately explained by incompetence. -- 
Napoleon Bonaparte


Re: can DDOC generate files names including the full path ?

2019-08-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 14, 2019 3:43:10 AM MDT wjoe via Digitalmars-d-learn 
wrote:
> For example if the source tree looks like this:
> >source/
> >
> >   foo/
> >
> >  baz.d
> >
> >   bar/
> >
> >  baz.d
>
> and generating the docs with something like this:
> >  dmd -D -Dd=docs foo/baz.d bar/baz.d
>
> the output looks like this:
> >docs/
> >
> >  baz.html
>
> one baz overwrites the other.
>
> I'd like to have something like this:
> >docs/
> >
> >foo.baz.html
> >bar.baz.html
>
> There's the  -op  flag, but that litters the source tree with
> html files.
> Neither the docs https://dlang.org/spec/ddoc.html nor google
>
> Also there's more annoying behavior:
>
> - Documentation generation fails if  -version  s are not provided
> resulting in a rather long command and it's tedious to manually
> keep track of it. Is there a way to make it only honor
> version(none) and treat all other -version s as a given ?
>
> - if the  -o-  isn't provided, dmd complains about missing
> symbols. Why ? -D enables documentation mode, doesn't it?

For better or worse, a documentation build is basically just a normal build
except that the version identifier D_Ddoc is declared, and the documentation
is generated. There are people who actually generate documentation as part
of their normal build. Personally, I don't think that that's a good approach
in general, because sometimes, you need to declare a version block that's
just for documentation and as such won't actually work (e.g. a declaration
for a symbol which is different on each platform would often require a
separate version just for the documentation where that version has the
documentation and a declaration but no actually definition). In order to
allow people to build with -D as part of their normal build and have it
work, Phobos actually has its own version identifier that it declares for
its documentation build instead of relying on D_Ddoc, since if it used
D_Ddoc, pretty much no one could build their documentation as part of their
normal build.

In any case, because a documentation build is basically normal build, it
certainly isn't the case that you can have all of the version identifiers
declared, and you're going to get complaints about missing symbols if stuff
is missing. Also, the compiler doesn't really have a good way built in to
deal with directories when generating documentation. It wants to shove
everything in the same directory and just use the module name (not the
package) when picking the names for the html files, which can be
problematic.

Realistically, what you tend to need to do if you actually want some control
over how files are named is to compile each file individually with -o- and
using -o to specify the actual file name you want with the appropriate path.

Alternatively, you can use other documentation generators. dub comes with
ddox built in, or you can use Adam Ruppe's adrdox:

https://github.com/adamdruppe/adrdox

The built-in documentation generation can work quite well, but it's not
quite as plug-and-play as would be nice and does tend to require that you
put together a build script to generate your documentation instead of just
being able to pass a single command and have it all just work.

- Jonathan M Davis






Re: Problem with aliasing member function

2019-08-18 Thread rjframe via Digitalmars-d-learn
On Sun, 18 Aug 2019 19:17:16 +, Andrey wrote:

> Here in tester I want to alias a template method and call it on object
> if this object isn't null. But I don't understand how to do it.
> How to solve the problem?

I don't think you can alias an object method directly; three methods I 
know of:

---
struct Struct {
void run(int number) {
import std.stdio;
writeln("run ", number);
}
}

// Pass the object itself.
void func1(alias obj)(int number) if (isFunction!(obj.run)) {
obj.run(number);
}

// Pass the object and the name of the method.
void func2(alias obj, string method)(int number)
if (__traits(compiles, "obj." ~ method ~ "(number);")) 
{
mixin("obj." ~ method ~ "(number);");   
}

// Pass the method at runtime.
void func3(void delegate(int) f, int number) {
f(number);
}

void main() {
Struct obj;
func1!(obj)(1);
func2!(obj, "run")(2);
func3(, 3);
}
---

Also, you don't want to name something "Object"; the base class is called 
Object -- the struct shadows it but you may run into some bug or confusion 
later.

--Ryan


Problem with aliasing member function

2019-08-18 Thread Andrey via Digitalmars-d-learn

Hello,
I can't compile this piece of code:

struct Object
{
void run(wstring ending, uint index)(int number)
{

}
}

void tester(alias callback, T)(int number, T object = null)
{
static if(is(T == typeof(null))) alias handler = callback;
else auto handler(wstring ending, uint index) = 
object.callback!(ending, index);

handler!("rfv", 5)(word);
}

void main()
{
Object obj;
tester!(Object.run)(10, );
}


Here in tester I want to alias a template method and call it on 
object if this object isn't null. But I don't understand how to 
do it.

How to solve the problem?


Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Ron Tarrant via Digitalmars-d-learn

On Sunday, 18 August 2019 at 17:10:38 UTC, Andre Pany wrote:


It looks now very nice, thanks a lot.


Excellent. Glad to do it.

Wheter you chose 2, 3 or 4 is up to you. 4 is mentioned in 
Phobos style guide, but it is up to you, what you prefer.


I've always been partial to three, but I'm also more of a tab 
person. Less work, if you see what I'm saying.




Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Andre Pany via Digitalmars-d-learn

On Sunday, 18 August 2019 at 16:34:21 UTC, Ron Tarrant wrote:

On Sunday, 18 August 2019 at 14:44:29 UTC, Andre Pany wrote:

the indentation level are 8 spaces.


Turns out it's settable in CSS. Tab size for quoted code blocks 
in the blog posts is now set to three. If you could check a few 
out and let me know if it's any better. If not, I'll take it 
down to two... now that I know how easy it is.


It looks now very nice, thanks a lot.
Wheter you chose 2, 3 or 4 is up to you. 4 is mentioned in Phobos 
style guide, but it is up to you, what you prefer.


Kind regards
Andre


Re: advise about safety of using move in an opAssign with __traits(isRef

2019-08-18 Thread aliak via Digitalmars-d-learn

On Saturday, 17 August 2019 at 16:43:51 UTC, Paul Backus wrote:

On Friday, 16 August 2019 at 08:07:28 UTC, aliak wrote:
Hi, I'm trying to fix a use-case where you have a wrapper 
template type (it's an optional) and the wrapping type has 
@disable this(this). And having this scenario work:


struct S {
  @disable this(this);
}
Optional!S fun() {...}

Optional!S a;
a = fun.move;

Now that won't work because of the disabled copy


Are you sure? I tried to reproduce the error you're describing, 
and I couldn't do it. The following compiles and runs without 
any issues:


struct Wrapper(T) { T value; }
struct NoCopy { @disable this(this); }

Wrapper!NoCopy fun()
{
return Wrapper!NoCopy();
}

void main()
{
Wrapper!NoCopy a;
a = fun(); // already an rvalue, so moved implicitly
}

Can you give a more complete example of the problem you're 
having?


You'll get the error if you define an opAssign:

struct Wrapper(T) {
T value;
void opAssign(U : T)(Wrapper!U other) {
this.value = other.value;
}
}

struct S {
  @disable this(this);
}

Wrapper!S fun() { return Wrapper!S(S()); }

void main() {
Wrapper!S a;
a = fun;
}




Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Ron Tarrant via Digitalmars-d-learn

On Sunday, 18 August 2019 at 14:44:29 UTC, Andre Pany wrote:

the indentation level are 8 spaces.


Turns out it's settable in CSS. Tab size for quoted code blocks 
in the blog posts is now set to three. If you could check a few 
out and let me know if it's any better. If not, I'll take it down 
to two... now that I know how easy it is.





Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Ron Tarrant via Digitalmars-d-learn

On Sunday, 18 August 2019 at 14:44:29 UTC, Andre Pany wrote:
Hm I am not sure, i just tried lynx (on raspberry pi) and here 
also the indentation level are 8 spaces.


For testing purposes, I replaced each tab with three spaces in 
this post: 
http://gtkdcoding.com/2019/05/31/0040-messagedialog.html


If this works better for you, let me know and I can do a quick 
s-n-r on all blog posts and add this as the final prep step as 
the posts go up.


Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Ron Tarrant via Digitalmars-d-learn

On Sunday, 18 August 2019 at 14:44:29 UTC, Andre Pany wrote:

Hm I am not sure, i just tried lynx (on raspberry pi) and here 
also the indentation level are 8 spaces.


Turns out, it's GitHub inserting 8 spaces per tab. No idea why 
anyone would think this appropriate, but there it is.


A workaround you can try for now is to click through to an 
example code (this won't work on the blog pages, just the code 
pages) and, at the end of the URL, type: ?ts=3 to get tabs that 
are three spaces. Any number between 1 and 12 will work, 
apparently.


Hope this helps for now. I'm still looking into this to find a 
more permanent solution. This 8 spaces per tab bugs me, too.




Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Ron Tarrant via Digitalmars-d-learn

On Sunday, 18 August 2019 at 14:44:29 UTC, Andre Pany wrote:

Hm I am not sure, i just tried lynx (on raspberry pi) and here 
also the indentation level are 8 spaces.


Perhaps if I switched from using tabs to spaces... I'll try it 
with one of the posts and get back to you so you can test it... 
if that's okay with you.


Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Andre Pany via Digitalmars-d-learn

On Sunday, 18 August 2019 at 14:18:23 UTC, Ron Tarrant wrote:

On Sunday, 18 August 2019 at 09:28:30 UTC, Andre Pany wrote:

II noticed you use an indentation level of 8 spaces. Is this 
by purpose? As far as I know, 4 spaces is recommended.


I only use three in PS Pad, so the extra spaces are being 
inserted by either Perl, Jekyll, Liquid, or some part of the 
GitHub Pages site.


Is it possible it's an interpretation layered on by the web 
browser on your phone?
I don't know enough about how browsers work to determine 
whether or not this is a valid question.


Hm I am not sure, i just tried lynx (on raspberry pi) and here 
also the indentation level are 8 spaces.


Kind regards
Andre


Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Ron Tarrant via Digitalmars-d-learn

On Sunday, 18 August 2019 at 09:28:30 UTC, Andre Pany wrote:

II noticed you use an indentation level of 8 spaces. Is this by 
purpose? As far as I know, 4 spaces is recommended.


I only use three in PS Pad, so the extra spaces are being 
inserted by either Perl, Jekyll, Liquid, or some part of the 
GitHub Pages site.


Is it possible it's an interpretation layered on by the web 
browser on your phone?
I don't know enough about how browsers work to determine whether 
or not this is a valid question.


D for a safer Linux kernel

2019-08-18 Thread Laeeth Isharc via Digitalmars-d-learn

I noticed a Rust post so why not post.

https://www.reddit.com/r/linux_programming/comments/cs0ime/d_for_a_safer_linux_kernel

https://www.reddit.com/r/programming/comments/cs0iec/d_for_a_safer_linux_kernel


Re: Blog Post #0062: Cairo Load & Display Images

2019-08-18 Thread Andre Pany via Digitalmars-d-learn

On Saturday, 17 August 2019 at 23:40:10 UTC, Ron Tarrant wrote:

On Friday, 16 August 2019 at 12:58:23 UTC, Andre Pany wrote:

This causes some distruction on mobile phone as you have 
scroll horizontally although it would fit the screen if the 
source code would start at column 0.


That didn't take as long as I thought it would. I removed all 
excess indentation, so let me know if it's any better now.


It looks a lot better now. I noticed you use an indentation level 
of 8 spaces. Is this by purpose? As far as I know, 4 spaces is 
recommended.


Kind regards
Andre