Re: Interfacing with C++ std::shared_ptr and std::unique_ptr

2020-06-09 Thread evilrat via Digitalmars-d-learn

On Wednesday, 10 June 2020 at 06:43:24 UTC, Andre Pany wrote:


Also, the C++ classes make use of templates. Is it still 
possible to call these

classes from D?


It should be, I did something similar and it worked. But it was 
quite some time ago so I don't remember exact situation and any 
details.


However you still be out of luck if the types you are trying to 
use is present in header only, since there is simply nothing to 
link with, so now you have to port whole template to D, or make 
dummy wrapper in C++ that forces the compiler to emit those 
symbols.


Same with ctor/dtors, if you have a class that is only used in 
some executable and not present in any of a .lib/.a form you're 
stuck. This is especially annoying with destructors because it 
renders the whole thing unusable without helper libraries that 
does new/delete in order to get the damn symbols emitted in 
object files to be able to link.


Interfacing with C++ std::shared_ptr and std::unique_ptr

2020-06-09 Thread Andre Pany via Digitalmars-d-learn

Hi,

I would like to interface with the library 
https://github.com/NTNU-IHB/FMI4cpp

and have following class definitions in the header file:

``` c++
namespace fmi4cpp {

template
class fmu_base {

public:

const std::string guid() const {
return get_model_description()->guid;
}

const std::string model_name() const {
return get_model_description()->model_name;
}

virtual std::shared_ptr 
get_model_description() const = 0;


};

template
class fmu_provider : public virtual 
fmu_base {


public:

virtual bool supports_cs() const = 0;

virtual bool supports_me() const = 0;

virtual std::unique_ptr  as_cs_fmu() const = 0;

virtual std::unique_ptr  as_me_fmu() const = 0;

};
```

While unique_ptr is already available in drunime library 
core.stdcpp.memory,
shared_ptr is missing. Does someone already have translated 
shared_ptr?


Also, the C++ classes make use of templates. Is it still possible 
to call these

classes from D?

Kind regards
Andre


Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Seb via Digitalmars-d-learn

On Wednesday, 10 June 2020 at 01:35:32 UTC, Q. Schroll wrote:

On Wednesday, 10 June 2020 at 00:53:30 UTC, Seb wrote:
It's a bit more complicated though as you need to avoid subtle 
breakage with ranges that return tuples that are auto-expanded 
like e.g. `foreach (k,v; myDict)`.


Okay, I can accept that. It's a poor decision, but well, it is 
what it is.


Anyhow, I would be highly in favor of DMD doing this. It's one 
of those many things that I have on my list for D3 or a D fork.


Is there any "official" or at least public list for D3 
suggestions?

Many people here talk about it recently...


No, there's nothing "official" not public lists yet.
However, there are two good related wiki pages:

https://wiki.dlang.org/Language_issues
https://wiki.dlang.org/Language_design_discussions



Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Q. Schroll via Digitalmars-d-learn

On Wednesday, 10 June 2020 at 00:53:30 UTC, Seb wrote:
It's a bit more complicated though as you need to avoid subtle 
breakage with ranges that return tuples that are auto-expanded 
like e.g. `foreach (k,v; myDict)`.


Okay, I can accept that. It's a poor decision, but well, it is 
what it is.


Anyhow, I would be highly in favor of DMD doing this. It's one 
of those many things that I have on my list for D3 or a D fork.


Is there any "official" or at least public list for D3 
suggestions?

Many people here talk about it recently...


Re: Alpine support for D

2020-06-09 Thread aberba via Digitalmars-d-learn

On Wednesday, 10 June 2020 at 01:06:30 UTC, aberba wrote:

On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote:
I notice that in the new release for Alpine Linux it mentions 
support for D.


I was curious what was meant by this and thought someone here 
would know. Just high level, like druntime was ported or 
packages added to the repo?


Tradionally you'd run D on something like Ubuntu, etc but 
Alpine is lightweight which is a good thing when building 
docker containers. Alpine uses a different C runtime musl?? 
among other things whilst D uses use libc. So I believe we now 
have bindings musl too to get D to work on Alpine.


https://en.m.wikipedia.org/wiki/Musl


Re: Alpine support for D

2020-06-09 Thread aberba via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote:
I notice that in the new release for Alpine Linux it mentions 
support for D.


I was curious what was meant by this and thought someone here 
would know. Just high level, like druntime was ported or 
packages added to the repo?


Tradionally you'd run D on something like Ubuntu, etc but Alpine 
is lightweight which is a good thing when building docker 
containers. Alpine uses a different C runtime musl?? among other 
things whilst D uses use libc. So I believe we now have bindings 
musl too to get D to work on Alpine.


Re: 32 bit phobos

2020-06-09 Thread Seb via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 17:58:56 UTC, welkam wrote:
I tried to compile a 32 bit executable but my system does not 
have 32 bit phobos. How do I get 32 bit phobos? I am using 
Manjaro.


dmd -m32 source/test2.d
/usr/bin/ld: skipping incompatible 
/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/../../../libphobos2.a 
when searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/libphobos2.a when 
searching for -lphobos2

/usr/bin/ld: cannot find -lphobos2
collect2: error: ld returned 1 exit status
Error: linker exited with status 1


Download a DMD archive (.tar.xz) from 
https://dlang.org/download.html or use the official install 
script.

DMD archives contain both 32 and 64-bit binaries.


Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Seb via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote:
Is there any particular reason why std.range : enumerate is a 
thing and


foreach (i, e; range) { ... }

doesn't work from the get-go? I wouldn't have such an issue 
with it if static foreach would work with enumerate just fine. 
As far as I can tell,


foreach (e; range) { ... }

is being lowered to

for (auto _range = range; !_range.empty; _range.popFront)
{
auto e = _range.front;
...
}

So why cant DMD rewrite

foreach (i, e; range) { ... }

to

for (auto _range = range, index = size_t(0); !_range.empty; 
_range.popFront, ++index)

{
size_t i = index;
auto e = _range.front;
...
}

Doesn't seem like a big deal, does it? I'm asking because I 
suspect there's an odd reason I have no idea and I whish to be 
educated.


It's a bit more complicated though as you need to avoid subtle 
breakage with ranges that return tuples that are auto-expanded 
like e.g. `foreach (k,v; myDict)`.
So IIRC the main reason why D's foreach magic isn't doing this is 
that it was argued that this problem is not significant enough to 
be worth fixing as there's enumerate and "there's bigger fish to 
fry".


Anyhow, I would be highly in favor of DMD doing this. It's one of 
those many things that I have on my list for D3 or a D fork.


Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Stefan Koch via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote:
Is there any particular reason why std.range : enumerate is a 
thing and


[...]


I don't think there is any particular reason. Other than that 
might shadow an opApply.

And C++ iterators didn't have it.


Re: Why is there no range iteration with index by the language?

2020-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 09, 2020 at 05:03:55PM -0700, H. S. Teoh via Digitalmars-d-learn 
wrote:
> On Tue, Jun 09, 2020 at 11:53:16PM +, Q. Schroll via Digitalmars-d-learn 
> wrote:
> > Is there any particular reason why std.range : enumerate is a thing
> > and
> > 
> > foreach (i, e; range) { ... }
> > 
> > doesn't work from the get-go?
> [...]
> 
> std.range.indexed is your friend. ;-)
[...]

Aaah, that function doesn't do what I thought it did.  Sorry!! :-(

What you want is std.range.enumerate.  But you already knew that.


T

-- 
EMACS = Extremely Massive And Cumbersome System


Re: Why is there no range iteration with index by the language?

2020-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 09, 2020 at 11:53:16PM +, Q. Schroll via Digitalmars-d-learn 
wrote:
> Is there any particular reason why std.range : enumerate is a thing
> and
> 
> foreach (i, e; range) { ... }
> 
> doesn't work from the get-go?
[...]

std.range.indexed is your friend. ;-)


T

-- 
Let's eat some disquits while we format the biskettes.


Why is there no range iteration with index by the language?

2020-06-09 Thread Q. Schroll via Digitalmars-d-learn
Is there any particular reason why std.range : enumerate is a 
thing and


foreach (i, e; range) { ... }

doesn't work from the get-go? I wouldn't have such an issue with 
it if static foreach would work with enumerate just fine. As far 
as I can tell,


foreach (e; range) { ... }

is being lowered to

for (auto _range = range; !_range.empty; _range.popFront)
{
auto e = _range.front;
...
}

So why cant DMD rewrite

foreach (i, e; range) { ... }

to

for (auto _range = range, index = size_t(0); !_range.empty; 
_range.popFront, ++index)

{
size_t i = index;
auto e = _range.front;
...
}

Doesn't seem like a big deal, does it? I'm asking because I 
suspect there's an odd reason I have no idea and I whish to be 
educated.


Re: Metaprogramming with D

2020-06-09 Thread tastyminerals via Digitalmars-d-learn

On Monday, 8 June 2020 at 14:41:55 UTC, Jan Hönig wrote:

On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote:


  dmd -mixin= ...


thanks for the tip!




  writeln(q{
  void foo() {
  }
});


What is the name of this `q` thing?
How do i find it? Are there any recent tutorials on it?


Ali's online book consolidates a lot of D language knowledge like 
this. I forgot about token string literals myself but then 
remembered it was in his book.


Re: Metaprogramming with D

2020-06-09 Thread ag0aep6g via Digitalmars-d-learn

On 09.06.20 20:16, Ali Çehreli wrote:
I am biased but I like my :) index of the book, where all such syntax 
items appear:


   https://ddili.org/ders/d.en/ix.html


Oh yeah. It's how I got the link. You might want to fix some of the 
URLs, though. Characters like '{' or '[' need to be percent-encoded.


Re: Metaprogramming with D

2020-06-09 Thread Ali Çehreli via Digitalmars-d-learn

On 6/8/20 7:50 AM, ag0aep6g wrote:


https://ddili.org/ders/d.en/literals.html#ix_literals.q%7B%7D


Thank you.

I am biased but I like my :) index of the book, where all such syntax 
items appear:


  https://ddili.org/ders/d.en/ix.html

Ali


Re: filter custom version id from __traits code

2020-06-09 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 18:08:01 UTC, Stanislav Blinov wrote:

On Tuesday, 9 June 2020 at 17:40:10 UTC, Basile B. wrote:


Any idea ?


As I replied in the issue report:


Instead of

static if (!is(mixin(member) == module) && 
!(is(mixin(member


use

static if (is(typeof(mixin(member


Yes thanks again for the help.


Re: filter custom version id from __traits code

2020-06-09 Thread Stanislav Blinov via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 17:40:10 UTC, Basile B. wrote:


Any idea ?


As I replied in the issue report:


Instead of

static if (!is(mixin(member) == module) && !(is(mixin(member

use

static if (is(typeof(mixin(member


32 bit phobos

2020-06-09 Thread welkam via Digitalmars-d-learn
I tried to compile a 32 bit executable but my system does not 
have 32 bit phobos. How do I get 32 bit phobos? I am using 
Manjaro.


dmd -m32 source/test2.d
/usr/bin/ld: skipping incompatible 
/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/../../../libphobos2.a 
when searching for -lphobos2
/usr/bin/ld: skipping incompatible /usr/lib/libphobos2.a when 
searching for -lphobos2

/usr/bin/ld: cannot find -lphobos2
collect2: error: ld returned 1 exit status
Error: linker exited with status 1




filter custom version id from __traits code

2020-06-09 Thread Basile B. via Digitalmars-d-learn
I don't see how to filter a custom version identifier from this 
traits code:


---
module test;

import std.traits   : isCallable;
version(all) version = my_version;

private bool onlyFuncs()
{
bool result = true;
foreach (member; __traits(allMembers, mixin(__MODULE__)))
{
static if (!is(mixin(member) == module) && 
!(is(mixin(member
static if (__traits(getOverloads, mixin(__MODULE__), 
member, true).length == 0)

{
pragma(msg, "`", member, "` ", "is not a type or a 
function");

result = false;
break;
}
}
return result;
}
static assert(onlyFuncs(), "this script must hide globals as 
local static variable in a getter");


void main(){}
---


: Error: undefined identifier my_version in module test
onlineapp.d(12): Error: module test.my_version cannot be 
resolved

onlineapp.d(21):called from here: onlyFuncs()
onlineapp.d(21):while evaluating: static


Any idea ?


Re: Alpine support for D

2020-06-09 Thread MoonlightSentinel via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote:
I notice that in the new release for Alpine Linux it mentions 
support for D.


Announcement: 
https://forum.dlang.org/thread/raue6j$1vp4$2...@digitalmars.com


Alpine support for D

2020-06-09 Thread Jesse Phillips via Digitalmars-d-learn
I notice that in the new release for Alpine Linux it mentions 
support for D.


I was curious what was meant by this and thought someone here 
would know. Just high level, like druntime was ported or packages 
added to the repo?