Re: How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 06:32:32 UTC, Rufus Smith wrote: Error: 'this' is only defined in non-static member functions, not __lambda2 Lambda's are delegates and delegates have a "this" type of pointer. I would like to get at it inside the lambda to check for some things. I'm doing some

Get relative offset portably.

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
I am doing some weird stuff. I duplicate functions and modify them in a portable way. One problem I have is that I cannot get data in a relative way to be able to access attached functional data. Here is an kinda of thought example, void base(int a, int b, int c) { ... } This function

Re: Passing a single tuple or multiple values

2016-07-19 Thread John via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 01:22:01 UTC, jmh530 wrote: import std.typecons : isTuple, tuple; import std.stdio : writeln; auto foo(T...)(T x) { T[0] y; foreach (i, e; x) { y += e; } return y; } auto bar(T)(T x) { static if

Re: Convert delegate or function type to other.

2016-07-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-07-18 21:19, Rufus Smith wrote: No, that converts an actual function. I need to create a new alias from the old one. You mean the actual type? John's answer will give you that. I'd also like to be able to create a delegate with a different context pointer. You can explicitly set

How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
Error: 'this' is only defined in non-static member functions, not __lambda2 Lambda's are delegates and delegates have a "this" type of pointer. I would like to get at it inside the lambda to check for some things. I'm doing some funky stuff. I'm not concerned about the scope or what this

Re: Convert delegate or function type to other.

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Monday, 18 July 2016 at 20:15:30 UTC, John wrote: On Monday, 18 July 2016 at 18:49:22 UTC, Rufus Smith wrote: Suppose I have the following: alias func = void function(int); Is there a way to convert it automatically to something the same type except of delegate: alias del = toDel(func) =

counting characters

2016-07-19 Thread celavek via Digitalmars-d-learn
Hi, I am trying to count characters in a string like: const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAGAGTGTCTGATAGCAGC"; counts['A'] = countchars!(dna_chain, 'A'); But I get a compilation error: template instance countchars!(dna_chain, "C") does not match

Re: returning constant references from class methods

2016-07-19 Thread ag0aep6g via Digitalmars-d-learn
On 07/19/2016 02:30 PM, celavek wrote: Hi, I'm trying the following code: class counter { public: final ulong[char] nucleotide_counts () const { return cached_counts; } private: ulong[char] cached_counts; } void main() { } I get the following error from the

Re: counting characters

2016-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/16 8:23 AM, celavek wrote: On Tuesday, 19 July 2016 at 09:57:27 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 09:42:40 UTC, celavek wrote: Works for me: size_t[char] counts; const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAGAGTGTCTGATAGCAGC";

Re: returning constant references from class methods

2016-07-19 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 12:30:49 UTC, celavek wrote: final ulong[char] nucleotide_counts () const { return cached_counts; } BTW you can find enumap useful https://forum.dlang.org/post/hloitwqnisvtgfoug...@forum.dlang.org if you want to have small associative arrays

Re: Passing a single tuple or multiple values

2016-07-19 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 07:23:52 UTC, John wrote: auto bar(T...)(T x) { static if (T.length == 1 && isTuple!(T[0])) return foo(x.expand); else return foo(x); } Hmm, this actually doesn't seem to be resolving my issue. I'm still getting the error about not being able to

Re: counting characters

2016-07-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 19, 2016 12:23:11 celavek via Digitalmars-d-learn wrote: > On Tuesday, 19 July 2016 at 09:57:27 UTC, Lodovico Giaretta wrote: > > On Tuesday, 19 July 2016 at 09:42:40 UTC, celavek wrote: > > > > Works for me: > > > > size_t[char] counts; > > const string dna_chain = > >

Re: counting characters

2016-07-19 Thread celavek via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 09:41:32 UTC, John wrote: On Tuesday, 19 July 2016 at 09:34:11 UTC, celavek wrote: Hi, I am trying to count characters in a string like: const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAGAGTGTCTGATAGCAGC"; counts['A'] =

Re: Passing a single tuple or multiple values

2016-07-19 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 07:23:52 UTC, John wrote: auto bar(T...)(T x) { static if (T.length == 1 && isTuple!(T[0])) return foo(x.expand); else return foo(x); } void main() { auto x = tuple(1, 2); auto y = bar(x); auto z = bar(x.expand);

Re: counting characters

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 12:23:11 UTC, celavek wrote: On Tuesday, 19 July 2016 at 09:57:27 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 09:42:40 UTC, celavek wrote: Works for me: size_t[char] counts; const string dna_chain =

Re: counting characters

2016-07-19 Thread celavek via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 09:57:27 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 09:42:40 UTC, celavek wrote: Works for me: size_t[char] counts; const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAGAGTGTCTGATAGCAGC"; counts['A'] =

returning constant references from class methods

2016-07-19 Thread celavek via Digitalmars-d-learn
Hi, I'm trying the following code: class counter { public: final ulong[char] nucleotide_counts () const { return cached_counts; } private: ulong[char] cached_counts; } void main() { } I get the following error from the compiler: Error: cannot implicitly convert

Re: counting characters

2016-07-19 Thread John via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 09:34:11 UTC, celavek wrote: Hi, I am trying to count characters in a string like: const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAGAGTGTCTGATAGCAGC"; counts['A'] = countchars!(dna_chain, 'A'); countchars(dna_chain, "A");

Re: counting characters

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 09:42:40 UTC, celavek wrote: On Tuesday, 19 July 2016 at 09:41:32 UTC, John wrote: On Tuesday, 19 July 2016 at 09:34:11 UTC, celavek wrote: Hi, I am trying to count characters in a string like: const string dna_chain =

Re: counting characters

2016-07-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 19, 2016 09:41:32 John via Digitalmars-d-learn wrote: > On Tuesday, 19 July 2016 at 09:34:11 UTC, celavek wrote: > > Hi, > > > > I am trying to count characters in a string like: > > > > const string dna_chain = > >

Re: counting characters

2016-07-19 Thread celavek via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 09:55:43 UTC, Jonathan M Davis wrote: On Tuesday, July 19, 2016 09:41:32 John via Digitalmars-d-learn wrote: auto result = count(dna_chain, 'A'); or if you know that the string is always going to just contain ASCII (as seems likely based on the example), then

strange bug: (not) calling module ctors; help with "master" needed

2016-07-19 Thread ketmar via Digitalmars-d-learn
i'm using git master (updated daily), and recently found very strange thing. when i'm linking my programs with libphobos2.a, module ctor from "std.internal.phobosinit" is not called, but when i'm linking with .so, everything is ok. it is easy to check: `EncodingScheme.create("utf-8")` will

Re: strange bug: (not) calling module ctors; help with "master" needed

2016-07-19 Thread ketmar via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:18:20 UTC, Steven Schveighoffer wrote: It's affecting phobos devs too, we are aware of the issue: https://issues.dlang.org/show_bug.cgi?id=16291 i see, thank you. my searching foo failed to find that issue. i guess i have to use digger to find the commit that

Re: Passing a single tuple or multiple values

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 13:33:41 UTC, jmh530 wrote: On Tuesday, 19 July 2016 at 07:23:52 UTC, John wrote: auto bar(T...)(T x) { static if (T.length == 1 && isTuple!(T[0])) return foo(x.expand); else return foo(x); } Hmm, this actually doesn't seem to be resolving my issue.

Re: counting characters

2016-07-19 Thread celavek via Digitalmars-d-learn
Thank you! That clarified a lot of things for me.

Re: returning constant references from class methods

2016-07-19 Thread celavek via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 12:33:53 UTC, ag0aep6g wrote: final const(ulong[char]) nucleotide_counts () const { return cached_counts; } OMG! I'm so blind. Never thought of trying the obvious way. Thank you

Re: How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 06:46:44 UTC, Mike Parker wrote: On Tuesday, 19 July 2016 at 06:32:32 UTC, Rufus Smith wrote: Error: 'this' is only defined in non-static member functions, not __lambda2 Lambda's are delegates and delegates have a "this" type of pointer. I would like to get at it

Re: strange bug: (not) calling module ctors; help with "master" needed

2016-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/16 11:08 AM, ketmar wrote: i'm using git master (updated daily), and recently found very strange thing. when i'm linking my programs with libphobos2.a, module ctor from "std.internal.phobosinit" is not called, but when i'm linking with .so, everything is ok. it is easy to check:

Re: LDC with ARM backend

2016-07-19 Thread Claude via Digitalmars-d-learn
On Friday, 15 July 2016 at 15:24:36 UTC, Kai Nacke wrote: There is a reason why we do not distribute a binary version of LDC with all LLVM targets enabled. LDC still uses the real format of the host. This is different on ARM (80bit on Linux/x86 vs. 64bit on Linux/ARM). Do not expect that

Re: Allowing "fall through" of attributes

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:55:02 UTC, Rufus Smith wrote: I have some functions that take other functions. I would like the attributes to be able to "fall" through so I get overload like behavior. I only care that I am passing a function, not if it is shared, extern(C), pure, @nogc, etc.

Re: How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/16 12:52 PM, Rufus Smith wrote: On Tuesday, 19 July 2016 at 15:58:49 UTC, Steven Schveighoffer wrote: On 7/19/16 11:25 AM, Rufus Smith wrote: [...] I think what Mike may be alluding to is that there is no name for the stack frame pointer you can use. There is no 'this' pointer that

Re: Allowing "fall through" of attributes

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 16:09:38 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 15:55:02 UTC, Rufus Smith wrote: I have some functions that take other functions. I would like the attributes to be able to "fall" through so I get overload like behavior. I only care that I am

Re: How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:58:49 UTC, Steven Schveighoffer wrote: On 7/19/16 11:25 AM, Rufus Smith wrote: [...] I think what Mike may be alluding to is that there is no name for the stack frame pointer you can use. There is no 'this' pointer that you can get at (even though it can be

Re: Passing a single tuple or multiple values

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:36:42 UTC, Lodovico Giaretta wrote: As you have to do `isTuple!(T[0])`, you also have to do `x[0].expand`. That's because T... works "as if" it was an array of types, and x, being of type T, it works "as if" it was an array of values. So you have to use an index

Re: strange bug: (not) calling module ctors; help with "master" needed

2016-07-19 Thread ketmar via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:18:20 UTC, Steven Schveighoffer wrote: Please add what you can to the report. ok, i found why it doesn't work with static libs. not sure what to do next, though... added the info to bugzilla.

Re: Allowing "fall through" of attributes

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 16:50:56 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:09:38 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 15:55:02 UTC, Rufus Smith wrote: I have some functions that take other functions. I would like the attributes to be able to "fall" through

Re: How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/16 11:25 AM, Rufus Smith wrote: On Tuesday, 19 July 2016 at 06:46:44 UTC, Mike Parker wrote: On Tuesday, 19 July 2016 at 06:32:32 UTC, Rufus Smith wrote: Error: 'this' is only defined in non-static member functions, not __lambda2 Lambda's are delegates and delegates have a "this" type

Allowing "fall through" of attributes

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
I have some functions that take other functions. I would like the attributes to be able to "fall" through so I get overload like behavior. I only care that I am passing a function, not if it is shared, extern(C), pure, @nogc, etc. void foo(R, A...)(R function(A) bar) { alias type =

Re: How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 16:58:12 UTC, Steven Schveighoffer wrote: On 7/19/16 12:52 PM, Rufus Smith wrote: On Tuesday, 19 July 2016 at 15:58:49 UTC, Steven Schveighoffer wrote: [...] Yes, but then this = null. I matters not for my use case. 'this' is not null in either case. There is no

Re: Allowing "fall through" of attributes

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 16:59:48 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 16:50:56 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:09:38 UTC, Lodovico Giaretta wrote: [...] But this doesn't create a function with all the attributes of the original? Just one that

Re: Passing a single tuple or multiple values

2016-07-19 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 15:40:20 UTC, Lodovico Giaretta wrote: You can find this out from the error, which says that you can't expand an object of type `(Tuple!(int, int))`. Note the surrounding parenthesis: they tell you that what you have is not a Tuple, but an AliasSeq whose only

Re: Allowing "fall through" of attributes

2016-07-19 Thread Lodovico Giaretta via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 17:05:55 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:59:48 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 16:50:56 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:09:38 UTC, Lodovico Giaretta wrote: [...] But this doesn't create a

Re: How to get the "this" ptr of a lambda inside the lambda?

2016-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/16 1:03 PM, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:58:12 UTC, Steven Schveighoffer wrote: On 7/19/16 12:52 PM, Rufus Smith wrote: On Tuesday, 19 July 2016 at 15:58:49 UTC, Steven Schveighoffer wrote: [...] Yes, but then this = null. I matters not for my use case. 'this'

Re: Allowing "fall through" of attributes

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 17:10:35 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 17:05:55 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:59:48 UTC, Lodovico Giaretta wrote: On Tuesday, 19 July 2016 at 16:50:56 UTC, Rufus Smith wrote: On Tuesday, 19 July 2016 at 16:09:38

How to search for an enum by values and why enum items aren't unique

2016-07-19 Thread stunaep via Digitalmars-d-learn
How can I search for an enum by its values? For example I have struct TestTraits { int value1; string value2; } enum Test : TestTraits { TEST = TestTraits(1, "test1"), TESTING = TestTraits(5, "test5") } and I have the int 5 and need to find TESTING with it. In

Why typeof(template) is void?

2016-07-19 Thread mogu via Digitalmars-d-learn
``` struct S(T) {} static assert(is (typeof(S) == void)); ``` Why S's type isn't something like `S: (T) -> S`?

Re: Template arguments produce unidentified identifier

2016-07-19 Thread Adam D. Ruppe via Digitalmars-d-learn
Take a read of this: http://stackoverflow.com/a/32621854/1457000 The short of it is don't mixin stringof. Instead, mixin the actual template itself. The functionLinkage might need to be string, but the types should remain literal. So try this: mixin("alias Func =

Re: Is there a way to "see" source code generated by templates after a compile?

2016-07-19 Thread WhatMeWorry via Digitalmars-d-learn
On Sunday, 17 July 2016 at 05:57:52 UTC, WhatMeWorry wrote: I don't suppose there's a way to "see" source code generated by templates after a compile but before execution? Or does the compiler generate it to a lower level on the fly; thus losing the source code? I'm assuming no because

Re: Dynamic code generation

2016-07-19 Thread ag0aep6g via Digitalmars-d-learn
On 07/20/2016 06:36 AM, Rufus Smith wrote: Does D offer any solutions to generate code dynamically? I don't think so. I would like to order based on optimal strategies. This requires effectively hard coding the execution path. A simple example, if (x == true) foo(); else bar();

Template arguments produce unidentified identifier

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
I have complex template that uses a mixin to solve some problems. The mixin produces the error. I thought template's were added in to the scope of the call? I guess the mixin is inserted before this happens. That isn't good ;/ Here is one place the error happens mixin("alias Func =

Re: Why typeof(template) is void?

2016-07-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 01:14:05 UTC, mogu wrote: Why S's type isn't something like `S: (T) -> S`? Because S isn't a type... think of a template as being like a function that returns a type. int foo(int) { return 0; } There, you wouldn't expect typeof(foo) to be int, no, typeof(foo)

Dynamic code generation

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
Does D offer any solutions to generate code dynamically? I would like to order based on optimal strategies. This requires effectively hard coding the execution path. A simple example, if (x == true) foo(); else bar(); can be recoded to be foo() or bar() while x is fixed, in my case x

Re: Template arguments produce unidentified identifier

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 01:48:31 UTC, Adam D. Ruppe wrote: Take a read of this: http://stackoverflow.com/a/32621854/1457000 The short of it is don't mixin stringof. Instead, mixin the actual template itself. The functionLinkage might need to be string, but the types should remain

Re: Template arguments produce unidentified identifier

2016-07-19 Thread Rufus Smith via Digitalmars-d-learn
If it's not clear, I have to import the proper identifiers but every use of the template would require the user to add their import. Obviously not the way to go.

Re: Why typeof(template) is void?

2016-07-19 Thread mogu via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 01:50:37 UTC, Adam D. Ruppe wrote: On Wednesday, 20 July 2016 at 01:14:05 UTC, mogu wrote: Why S's type isn't something like `S: (T) -> S`? Because S isn't a type... think of a template as being like a function that returns a type. int foo(int) { return 0; }

Re: How to search for an enum by values and why enum items aren't unique

2016-07-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, July 20, 2016 04:03:23 stunaep via Digitalmars-d-learn wrote: > How can I search for an enum by its values? For example I have > > >struct TestTraits { > > > > int value1; > > string value2; > > > >} > > > >enum Test : TestTraits { > > > > TEST = TestTraits(1, "test1"), > > TESTING =