On Saturday, 16 February 2019 at 05:06:55 UTC, mnar53 wrote:
Absolutely a newbie to D. This code mimics c, but unfortunately
does not work:
import std.typecons;
import std.math;
alias double function(double) UNARY;
UNARY[] FCNS = [sin, cos, tan];
double[][] MAP (int idx, double[][] args)
Thanks for the detailed answers!
Yes, I accept that immutable guarantees should be implemented
only during @safe that doesn't call into @trusted.
On Friday, 15 February 2019 at 18:59:36 UTC, H. S. Teoh wrote:
At the very least, such [union] code should be automatically
@system.
Sensible.
Absolutely a newbie to D. This code mimics c, but unfortunately
does not work:
import std.typecons;
import std.math;
alias double function(double) UNARY;
UNARY[] FCNS = [sin, cos, tan];
double[][] MAP (int idx, double[][] args) nothrow {
UNARY f = FCNS[idx];
foreach(i; 0 ..
On Fri, Feb 15, 2019 at 03:50:33AM -0700, Jonathan M Davis via
Digitalmars-d-learn wrote:
> On Friday, February 15, 2019 3:06:34 AM MST Kagamin via Digitalmars-d-learn
> wrote:
> > Union is just a pretty cast, type system guarantees don't hold for
> > it.
>
> Well, technically, what's supposed
On Friday, 15 February 2019 at 17:18:28 UTC, H. S. Teoh wrote:
Why? because that's the only case where you can reinterpret the
.sizeof*.length bytes as an array of a different type. There
is no conversion, the cast works as a reinterpretation. It's
by design.
But my problem is that it
On Friday, 15 February 2019 at 17:28:45 UTC, H. S. Teoh wrote:
On Fri, Feb 15, 2019 at 05:40:39PM +0100, ag0aep6g via
Digitalmars-d-learn wrote:
Your fun_to_dlg fails when the function has parameters.
Yes. Delegates are basically syntactic sugar for a function
pointer with an implicit first
On Fri, Feb 15, 2019 at 05:40:39PM +0100, ag0aep6g via Digitalmars-d-learn
wrote:
> On 15.02.19 15:20, Bastiaan Veelo wrote:
> > Exploiting this, it is possible to explicitly convert a function
> > pointer into a delegate [2]:
> > ```
> > Ret delegate(Args args) fun_to_dlg(Ret, Args...)(Ret
On Friday, 15 February 2019 at 16:40:39 UTC, ag0aep6g wrote:
Your fun_to_dlg fails when the function has parameters.
Hah ok. std.functional.toDelegate() does work in its place though.
As far as I see, it would be possible make the conversion would
work by changing how a delegate's context is
On Fri, Feb 15, 2019 at 04:17:12PM +, Dennis via Digitalmars-d-learn wrote:
> I assumed that casting an int[] to a ubyte[] would keep all bytes and
> quadruple the length of the original array. But when the array is a
> literal, it keeps the same length but truncates every int element to a
>
On 15.02.19 15:20, Bastiaan Veelo wrote:
Exploiting this, it is possible to explicitly convert a function pointer
into a delegate [2]:
```
Ret delegate(Args args) fun_to_dlg(Ret, Args...)(Ret function(Args args)
fun)
{
Ret delegate(Args) dlg;
dlg.funcptr = fun;
return dlg;
}
I assumed that casting an int[] to a ubyte[] would keep all bytes
and quadruple the length of the original array. But when the
array is a literal, it keeps the same length but truncates every
int element to a ubyte:
```
import std.stdio;
void main()
{
// enum:
enum litA =
On Friday, 15 February 2019 at 14:30:45 UTC, Alex wrote:
There is
https://dlang.org/library/std/functional/to_delegate.html
Ah, there it is :-) Thanks.
A templated function also works.
```
int genfun(F)(F dg) {return dg();}
int top_level() {return -1;}
void main()
{
int nested()
On Friday, 15 February 2019 at 14:20:44 UTC, Bastiaan Veelo wrote:
Given a function taking a delegate, for example
```
int fun(int delegate() dg) {return dg();}
```
Sometimes we need to call `fun` with a pointer to a nested
function and other times with a pointer to a top level
function. As
Given a function taking a delegate, for example
```
int fun(int delegate() dg) {return dg();}
```
Sometimes we need to call `fun` with a pointer to a nested
function and other times with a pointer to a top level function.
As function pointers do not implicitly convert to delegates, this
does
On Wednesday, 13 February 2019 at 05:13:12 UTC, sarn wrote:
On Tuesday, 12 February 2019 at 20:03:09 UTC, Jonathan M Davis
wrote:
So, I'd say that it's safe to say that dmd
The whole thing just seems like a weird requirement that
really shouldn't be there,
Like I said in the first reply,
On Friday, February 15, 2019 3:06:34 AM MST Kagamin via Digitalmars-d-learn
wrote:
> Union is just a pretty cast, type system guarantees don't hold
> for it.
Well, technically, what's supposed to be the case is that when you cast, the
type system guarantees still hold but it's up to the
Union is just a pretty cast, type system guarantees don't hold
for it.
On Thursday, February 14, 2019 11:59:31 PM MST Stefan Koch via Digitalmars-
d-learn wrote:
> On Thursday, 14 February 2019 at 23:55:18 UTC, SimonN wrote:
> > std.typecons.Rebindable!(immutable A) is implemented as:
> > private union {
> >
> > immutable(A) original;
> > A
18 matches
Mail list logo