a lambda with arguments has type void?

2016-06-07 Thread cy via Digitalmars-d-learn
This program errors out, when I try to pass lambdas that take arguments. How am I getting the syntax wrong here? Is there some reason you can't do this? import std.stdio; void foo(Callable)(Callable bar) { bar(); } void foo2(Callable)(Callable bar, int baz) { bar(baz); } void main() {

Re: Constraining template with function signature

2016-06-09 Thread cy via Digitalmars-d-learn
The other way is better, but since you asked... On Wednesday, 8 June 2016 at 01:42:55 UTC, Carl Vogel wrote: Now, I can use something like isCallable std.traits to make sure the predicate is a Callable, and there are various function traits in the module that I could combine with `is` clauses

shared Mutex?

2016-06-09 Thread cy via Digitalmars-d-learn
I was thinking of using threads in a D program (ignores unearthly wailing) and I need 1 thread for each unique string resource (database connection info). So I did this: shared BackgroundDB[string] back; I don't see any way to make less data shared there. If it weren't shared, it would be

Re: Pointer problems, changing for no reasons

2016-06-09 Thread cy via Digitalmars-d-learn
I can't help but notice that loadModel is not a static member function, yet you don't seem to call it with a Model object in your "get" function. Also have a look at std.typecons.RefCounted if you want reference counted data..

Re: Parse File at compile time, but not embedded

2016-06-09 Thread cy via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 22:09:58 UTC, Alex Parrill wrote: Accessing a SQL server at compile time seems like a huge abuse of CTFE (and I'm pretty sure it's impossible at the moment). Why do I need to install and set up a MySQL database in order to build your software? Presumably you

Re: shared Mutex?

2016-06-09 Thread cy via Digitalmars-d-learn
On Thursday, 9 June 2016 at 20:53:38 UTC, tcak wrote: (cast()mx).lock(); I was told casting away shared when there are still references to it is a bad idea. Like, the Mutex object might get corrupted if the garbage collector tries to move it while another thread is using it. So

Re: a lambda with arguments has type void?

2016-06-08 Thread cy via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 22:17:03 UTC, ag0aep6g wrote: You don't specify the types of the parameters of the function literals, so you effectively have templates there. As such the literals have no types, and can't be passed as arguments. Yeah, I see that now. The compiler does have all the

const types can't be specialized non-const, if arrays?

2016-06-16 Thread cy via Digitalmars-d-learn
I don't get it. Do I have to write a separate template for arrays specifically or something? NonConst foo(Constant: const NonConst, NonConst)(Constant bar) { pragma(msg,"NonConst is ",NonConst); pragma(msg,"Constant is ",Constant); NonConst foo = bar; return foo;

Re: How to get access to Voldemort / private thingies

2016-06-17 Thread cy via Digitalmars-d-learn
On Friday, 17 June 2016 at 19:49:18 UTC, Johan Engelen wrote: Hi all, Is there another way to get access to Voldemort class methods, or private class members, other than using Voldemort data is pretty well protected though. Because unlike protection attributes, modularizing stuff in

Re: How to get access to Voldemort / private thingies

2016-06-17 Thread cy via Digitalmars-d-learn
On Friday, 17 June 2016 at 20:12:53 UTC, cy wrote: writeln("see ",wow," for any equipment you need."); Oh, and as you can see it's important to automate that, so you don't make any mistakes while copying.

Re: vibe.d - asynchronously wait() for process to exit

2016-06-18 Thread cy via Digitalmars-d-learn
On Friday, 17 June 2016 at 13:53:15 UTC, Vladimir Panteleev wrote: Geod24 on IRC suggested signalfd + createFileDescriptorEvent. I think this would work, but isn't it possible to wrap the fd returned by signalfd into a Vibe.d stream and read it directly? I'm just not sure how. Well, vibe.d

How to group similar member functions from different classes?

2016-06-18 Thread cy via Digitalmars-d-learn
When I define functions like: class A { abstract void format(...) {...} } class B : A { void format(...) {...} } class C : A { void format(...) {...} } and so on, often these different member functions all share a lot in common. Maybe they are the only ones that require formatting

Re: How to get access to Voldemort / private thingies

2016-06-18 Thread cy via Digitalmars-d-learn
On Saturday, 18 June 2016 at 08:41:30 UTC, Johan Engelen wrote: Without going in too much detail, the problem is that I am not linking to opaque .o files. The problem is the compiler has to assume you *might* be linking to opaque .o files, so it can't provide any introspection capabilities.

Re: How to group similar member functions from different classes?

2016-06-18 Thread cy via Digitalmars-d-learn
On Saturday, 18 June 2016 at 07:03:25 UTC, cy wrote: So how would you do it? Defining A.foo, B.foo, etc in one place, and A.bar, B.bar, etc in another? The only thing I've been able to figure is a horrible hack, where your member functions are something like // off in define_foos.d

Re: print function

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 12:35:14 UTC, Artur Skawina wrote: D's std lib implementations are sometimes really awful, but in this case it's not actually that bad: print("hi","there"); -> fwrite("hi", 1, 2, 0x7ff68d0cb640) = 2 fwrite(" ", 1, 1,

What's going to replace std.stream?

2016-02-05 Thread cy via Digitalmars-d-learn
Let's say I have a socket, and a file, and I want to send the contents of that file to the socket. What's the best way to do that? Yes I'm aware that in Linux, you can use a combination of a pipe and splice(2) to keep all buffers kernel side for that, but I was thinking more generally. The

Re: Template to create a type and instantiate it

2016-02-05 Thread cy via Digitalmars-d-learn
On Saturday, 6 February 2016 at 06:39:27 UTC, Marco Leise wrote: using the template multiple times with the same arguments will always give you the first instance. Hmm, consider that the argument was a particular line of code though, and that's not likely to repeat. I didn't test what would

Re: Things that keep D from evolving?

2016-02-06 Thread cy via Digitalmars-d-learn
On Saturday, 6 February 2016 at 10:29:32 UTC, Ola Fosheim Grøstad wrote: This prevents fast GC: Pointers. Would it be possible to write a fast garbage collector that just didn't track any pointers? Just offer a head's up that if you use "this collector" and pointers on collectable data,

Re: What's going to replace std.stream?

2016-02-06 Thread cy via Digitalmars-d-learn
On Saturday, 6 February 2016 at 08:24:59 UTC, Jakob Ovrum wrote: foreach(chunk; File("path/to/file").byChunk(16 * 1024)) Ohh, cool so the streaming...ish logic is in std.stdio now. I thought that module was only for text output.

Why can't compile time expressions do ___?

2016-02-06 Thread cy via Digitalmars-d-learn
I'm not clear on why you aren't allowed to allocate memory with compile time execution, or why access to the filesystem is restricted. (Unless you pass -J/ I think?)

Re: Detecting exception unwinding

2016-02-06 Thread cy via Digitalmars-d-learn
On Saturday, 6 February 2016 at 14:25:21 UTC, Ola Fosheim Grøstad wrote: See, even Python supports this. :-) And D supports the "with" statement in python, in the form of "scope()" statements. The D way is slightly less misleading too, as with somethingThatFails() as e: print(e) doesn't

How to warn of unused imports?

2016-02-08 Thread cy via Digitalmars-d-learn
When I factor out code from my modules, it really, really often leaves import statements that just sit there doing nothing, making it look like my program is more complex than it is. How do I get warned for leaving those, and a list of which ones I can safely remove?

Re: Bug or intended?

2016-02-08 Thread cy via Digitalmars-d-learn
On Saturday, 6 February 2016 at 14:15:04 UTC, rsw0x wrote: I was playing around with alias templates and came across this, I reduced it to: --- struct A(alias C c){ auto foo(){ return c.i; } } struct B{ C c; A!c a; } struct C{ int i; } --- It gives me a "need 'this' for 'i'

Re: Custom hash table key is const, how to call dtors?

2016-02-06 Thread cy via Digitalmars-d-learn
On Saturday, 6 February 2016 at 03:57:16 UTC, Marco Leise wrote: No, but they could have dtors because they contain malloc'd data. E.g. string literals that don't live on the GC heap. Character arrays allocated with glibc malloc are immutable? News to me...

in a template argument, specify which object member to access?

2016-02-08 Thread cy via Digitalmars-d-learn
object.member lets me access the member of the object, but what if I want to access those members in a generic way, but in a different arrangement depending on context? Like if I wanted to first follow a tree down, and second priority would be going left to right, but then I wanted to first go

Re: How to warn of unused imports?

2016-02-08 Thread cy via Digitalmars-d-learn
On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote: Otherwise, it sounds like a decent enhancement request for DMD. I know other compilers who do this warning. It definitely does sound like a decent enhancement request. I didn't know it wasn't implemented yet, but it should be

Re: Detecting exception unwinding

2016-02-04 Thread cy via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 11:09:00 UTC, Ola Fosheim Grøstad wrote: Is there some reliable way to detect that a destructor is called because of exception unwinding? I basically want to change behaviour within a destructor based on whether the destructor is called as a result of a

Template to create a type and instantiate it

2016-02-04 Thread cy via Digitalmars-d-learn
I'm guessing I have to use a "mixin" mixin for this, but... there's no way to do something like this is there? template TFoo(T) { struct T { int a; int b; } T obj; } TFoo!Derp; Derp bar; Neither templates, nor mixin templates seem capable of this. Easy enough to use mixin, with

Re: print function

2016-02-04 Thread cy via Digitalmars-d-learn
On Thursday, 4 February 2016 at 15:32:48 UTC, Artur Skawina wrote: void print(A...)(A a) { foreach (N, ref e; a) write(e, N==A.length-1?"\n":" "); } will be unrolled at compile time Mind if I elaborate on this a bit? If that is unrolled, I understand it will unroll

How to allocate arrays of objects?

2016-02-10 Thread cy via Digitalmars-d-learn
The following program segfaults for me, compiling it with dmdv2.070 as well as the latest git. I must be doing it wrong. There's a way to specify class construction, or emplace, or something. But I can't find it! How do I deal with arrays of objects? class A { int stuff; } void

Re: How to allocate arrays of objects?

2016-02-10 Thread cy via Digitalmars-d-learn
On Thursday, 11 February 2016 at 04:07:18 UTC, cy wrote: A[] as = new A[2]; assert(as.length==2); as[0].stuff = 42; Oh, I get it. `as` is an array of 2 pointers to A objects, both pointers set to null. So I need to say like: as[0..$] = new A(); before accessing

Re: in a template argument, specify which object member to access?

2016-02-08 Thread cy via Digitalmars-d-learn
This is what I have so far. Using mixin(rawstring~templatearg) for every time I access the member is kind of cludgy though. struct A { string up; string down; string left; string right; } template goPlaces(string D1, string D2, string D3) { string

Re: in a template argument, specify which object member to access?

2016-02-08 Thread cy via Digitalmars-d-learn
On Monday, 8 February 2016 at 22:38:45 UTC, Mengu wrote: i believe you can use __traits(getMember) there. Great! Should have refreshed before sending that reply... I wonder if mixin("a."~member) is better or worse than __traits(getMember,a,member)...

Re: Custom hash table key is const, how to call dtors?

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 22:18:50 UTC, Marco Leise wrote: But when you remove items from the table you need to call a const/immutable dtor that needs to be written for everything that can be a hash table key. You need to write destructors for hash keys? How would you use string literals

Re: What is a short, fast way of testing whether x in [a, b]?

2016-02-07 Thread cy via Digitalmars-d-learn
On Monday, 8 February 2016 at 03:09:53 UTC, Enjoys Math wrote: was wondering if there's a D native way of doing it. That is the D native way of doing it, but you could clean up a lot of the boilerplate with some more templates. Also, || tests for exclusion, as in whether something is NOT in

Re: Template to create a type and instantiate it

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 07:44:29 UTC, Rikki Cattermole wrote: That code is completely wrong anyway. Well, obviously it's wrong. If I don't know correct code that will do what I want, then I can't tell you what I want using correct code. But you could do: alias Derp = TFoo; Derp

Re: Detecting exception unwinding

2016-02-05 Thread cy via Digitalmars-d-learn
On Friday, 5 February 2016 at 08:16:05 UTC, Ola Fosheim Grøstad wrote: If you can test for "uncaught_exceptions" you can implement the equivalent of scope(failure/success) etc within destructors. Sorry, years of python programming have made me shy of destructors. It just looks a little less

Re: How to be more careful about null pointers?

2016-03-28 Thread cy via Digitalmars-d-learn
On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote: I invoked db.find_chapter.bindAll(8,4), when db was a null pointer. No, no, no it's worse than that. What I did was (db.)find_chapter = (db.)backend.prepare("...") when backend was null, and got no error. find_chapter was garbage of course,

How to be more careful about null pointers?

2016-03-28 Thread cy via Digitalmars-d-learn
I finally found the null pointer. It took a week. I was assigning "db = db" when I should have been assigning "this.db = db". Terrible, I know. But... I invoked db.find_chapter.bindAll(8,4), when db was a null pointer. There was no null pointer error. No exception raised for dereferencing a

How to escape control characters?

2016-03-30 Thread cy via Digitalmars-d-learn
This might be a dumb question. How do I format a string so that all the newlines print as \n and all the tabs as \t and such?

Re: How to escape control characters?

2016-03-30 Thread cy via Digitalmars-d-learn
Oh, cool. On Thursday, 31 March 2016 at 03:29:19 UTC, H. S. Teoh wrote: Or implement manual substitution with a pipeline: string myString = ...; string escapedStr = myString .chunks(1) .map!(c => (c == "\n") ? "\\n" : (c

Re: How to escape control characters?

2016-03-30 Thread cy via Digitalmars-d-learn
On Thursday, 31 March 2016 at 03:23:52 UTC, Seb wrote: http://dlang.org/spec/lex.html#WysiwygString r"ab\n" or `ab\n` Yes I know. But I mean like, string a = r"ab\n"; writeln(escape(a)); // => ab\n

Re: setting stringImportPaths in dub.json

2016-03-20 Thread cy via Digitalmars-d-learn
I also tried symlinking ../sharedViews into views/shared and importing "shared/common.stuff" but that didn't work either.

Re: Linux blocked on file read on exit, need select

2016-03-20 Thread cy via Digitalmars-d-learn
I don't know, but you could always just use fcntl if you already can assume you're on Linux. extern (C) int fcntl(int, int, int); C keeps the constants under lock and key of course, so you have to specify them manually. But you could write a C program to print them out, or generate D code I

setting stringImportPaths in dub.json

2016-03-20 Thread cy via Digitalmars-d-learn
"stringImportPaths": ["../sharedViews/"] nope... "buildSettings": { "stringImportPaths": ["../sharedViews/"] } nope... "package": { "name": "myownfreakingpackage", "buildSettings": { "stringImportPaths": ["../sharedViews/"] } } nope...

Re: setting stringImportPaths in dub.json

2016-03-20 Thread cy via Digitalmars-d-learn
On Monday, 21 March 2016 at 04:58:37 UTC, cy wrote: I also tried symlinking ../sharedViews into views/shared and importing "shared/common.stuff" but that didn't work either. Oh. I was editing dub.selections.json. Never mind, I'm just an idiot.

Re: Using ffmpeg in command line with D

2016-03-22 Thread cy via Digitalmars-d-learn
On Monday, 21 March 2016 at 17:26:09 UTC, Karabuta wrote: Will this work Yes. and is it the right approach used by video convertor front-ends? Well, yes, provisionally. When you invoke "ffmpeg" via spawnProcess, that isolates ffmpeg as its own process, obviously. From a security and

Re: byChunk odd behavior?

2016-03-22 Thread cy via Digitalmars-d-learn
On Tuesday, 22 March 2016 at 07:17:41 UTC, Hanh wrote: input.take(3).array; foreach (char c; input) { Never use an input range twice. So, here's how to use it twice: If it's a "forward range" you can use save() to get a copy to use later (but all the std.stdio.* ranges don't

If I understand const right...

2016-03-23 Thread cy via Digitalmars-d-learn
a = a + 1 a is const, a + 1 is const, yet a can't be assigned to a + 1. And I think the reason is like... const(int) a = 23; while(something()) { a = a + 1; } in the first iteration, a is set to 23, and the value of "a + 1" is 24, but where is the computer gonna store that 24? It can't

inout and templates don't mix...

2016-03-23 Thread cy via Digitalmars-d-learn
halp There's a module that tries to define complex operations on both const and non-const structs, since it's the same operation for both. So every function that invokes those operations is copy-pasted twice, just with "const" added. Switching to inout to eliminate that huge amount of code

Re: If I understand const right...

2016-03-23 Thread cy via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote: Just to be 100% clear: you're adding to the pointer here, No, that's what I meant to do. b = new int(*b + 1); Here "b" is pointing to mutable heap allocated data, which got cast to constant. with b = b + 1, it's still constant

How do you append to a dynamic array using move semantics?

2016-03-23 Thread cy via Digitalmars-d-learn
struct Thing { @disable this(this); } ... items ~= move(item); // Error: struct Thing is not copyable because it is annotated with @disable ++items.length move(items[$-1],item); // Error: struct Thing is not copyable because it is annotated with @disable appender(items).put(move(item));

Re: How do you append to a dynamic array using move semantics?

2016-03-23 Thread cy via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 23:44:55 UTC, ag0aep6g wrote: You got the order of arguments wrong here. Source goes first, Oh, derp. Thanks. Right then... it works as expected.

Re: How to be more careful about null pointers?

2016-03-29 Thread cy via Digitalmars-d-learn
On Monday, 28 March 2016 at 21:24:48 UTC, Adam D. Ruppe wrote: If it didn't give the error, either you swallowed it or you didn't actually dereference null. Okay, so it's not actually supposed to happen. Hopefully it's something I did wrong... What is the db library you are using? Did you

Re: How to be more careful about null pointers?

2016-03-29 Thread cy via Digitalmars-d-learn
On Tuesday, 29 March 2016 at 06:21:49 UTC, Ali Çehreli wrote: parent.prep.bind is translated to the following by the compiler: "Call bind() for the object at address... let's calculate... Wherever parent is, we should add the offset of prep inside that object." Okay, that's helpful

Is NullableRef checked at compile time?

2016-05-23 Thread cy via Digitalmars-d-learn
I was squinting at the std.typecons.NullableRef code and it _looks_ like isNull is only checked at runtime (and not checked at all in release mode!) but D has surprised me before in its ability to pre-calculate stuff during compilation. I was thinking of using something like this:

Re: Speed up `dub`.

2016-05-23 Thread cy via Digitalmars-d-learn
On Thursday, 19 May 2016 at 17:50:44 UTC, ciechowoj wrote: dub build --nodeps I tried it, doesn't seem to do anything, maybe something is broken. Perhaps you didn't complete "dub build" without --nodeps beforehand? You have to do that once, and it's still as annoyingly inefficient as

Re: Newbie to D, first impressions and feedback on the 5 (and more) first minutes.

2016-05-24 Thread cy via Digitalmars-d-learn
https://p0nce.github.io/d-idioms/ I wanted to mention as well, if you like idioms. That guy has some good ideas. On Tuesday, 24 May 2016 at 17:36:45 UTC, Ali Çehreli wrote: Yes, a link from that page points to a book that *can* be bought but it's available online as well: It's worth buying,

Re: Newbie to D, first impressions and feedback on the 5 (and more) first minutes.

2016-05-24 Thread cy via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 15:27:45 UTC, llaine wrote: I'm running Fedora 23 on a daily basis and the installation was OK. Not as easy as on mac but still. Yeah, rpm based distributions like Fedora/Redhat/etc have historically been a real pain when it comes to installing stuff. Depending on

guard condition for a callable thingy, with THESE arguments

2016-05-14 Thread cy via Digitalmars-d-learn
I take callbacks on occasion, and I don't really care if they're a delegate, or a function, or a callable object, and I can assert that in a template: void foo(Callable)(Callable callback) if(isSomeFunction!Callable || isCallable!Callable) { ... } That works, but it doesn't show you what

Re: Speed up `dub`.

2016-05-14 Thread cy via Digitalmars-d-learn
On Monday, 7 March 2016 at 09:18:37 UTC, ciechowoj wrote: I'm using `dub` to build project. And every time I run `dub` it seems to check if dependencies are up to date, which takes some time. Is there a way to switch of that checking? Or any other way to speed up building process? It really

Re: guard condition for a callable thingy, with THESE arguments

2016-05-15 Thread cy via Digitalmars-d-learn
On Sunday, 15 May 2016 at 02:12:38 UTC, Ann W. Griffith wrote: use "Parameters" in the constraint or make a template that you can reeuse. This is what I've got going so far. Using static asserts to have clearer errors when an incorrect callback is supplied. I'm not... sure storage class is

Small C wrapper in your DUB package?

2016-05-08 Thread cy via Digitalmars-d-learn
I'm tiring of making extern (C) signatures for a million library calls and counting out the offset of members of C structures, to produce analagous D structures. Couldn't I just make a .c file that had my own specialized, opaque, D friendly interface? I don't really know how to do that.

Re: Small C wrapper in your DUB package?

2016-05-08 Thread cy via Digitalmars-d-learn
Well, just messing with it myself, the solution seems to be to make a .a library, link with /lib/libc.a since unlike .o, .a breaks shared linkage, and then refer to it in libs as "$PACKAGE_DIR/libmywrapper.a" ... "preBuildCommands": ["make -C $PACKAGE_DIR"], "libs":

std.range pipelike interface, inverting OutputStreams?

2016-08-12 Thread cy via Digitalmars-d-learn
I was trying to use std.regex, and it takes an output stream to pump the result to, which is great, but I wanted to perform TWO replacements, one with the output of the previous, with data that might be a tricky size to cache redundantly. So, ideally when you do something like regexp

Re: std.range pipelike interface, inverting OutputStreams?

2016-08-12 Thread cy via Digitalmars-d-learn
Here's how to do it using context switches. There ought to be a way to manually pass specific state around to keep that from happening, but probably not since there's no interface to pause something writing to an OutputRange. auto pipe(T, alias oh)() { import std.concurrency:

Re: Passing Structs to function like in C

2016-08-12 Thread cy via Digitalmars-d-learn
On Friday, 12 August 2016 at 15:21:22 UTC, D.Rex wrote: I was wondering how this is achieved in D, or if D has an alternative implementation of this. It isn't, because C interfaces that require you to pass in structures are inherently bad design, and usually both unstable and extremely C

Re: How to group similar member functions from different classes?

2016-07-15 Thread cy via Digitalmars-d-learn
On Monday, 20 June 2016 at 16:39:54 UTC, Marc Schütz wrote: Untested: Seems to only work if A and B are both defined in the same file as Foos (defeating the purpose). Putting A and B in a.d and b.d respectively gives me these errors: a.d(2): Error: undefined identifier 'Foos' a.d(2):

extern (C++) including bodies of member functions?

2016-07-15 Thread cy via Digitalmars-d-learn
I would never (ever) do this myself, but trying to understand dmd, the code is absolutely packed with things like this: extern(C++) class Package : ScopeDSymbol { ... override const(char)* kind() const { return "package"; } ... override final inout(Package) isPackage() inout {

build a subpackage in dub?

2016-07-16 Thread cy via Digitalmars-d-learn
Say I have a package called "main" and a sub-package in a "complicatedexample" directory, and my dub.json in "main" looks sort of like: "subPackages": [ "./complicatedexample/" ], Let's say I do *not* have ":complicatedexample" in my dependencies for "main", but "complicatedexample" itself

Re: extern (C++) including bodies of member functions?

2016-07-15 Thread cy via Digitalmars-d-learn
On Friday, 15 July 2016 at 19:20:52 UTC, Jacob Carlborg wrote: Yes. Just as it's possible to call C function from D, it's possible to implement functions in D that can be called from C. This compatibility applies C++ and Objective-C as well. So, it applies to member functions too (for C++)?

UFCS with implicit "this" ?

2016-08-08 Thread cy via Digitalmars-d-learn
I really like UFCS, which is to say, defining functions outside the class/struct to operate on it, but you can still say object.function(...) and it'll get rewritten into function(object,...). Only sticky point is the convenience of "this". Like I can go struct A { bool a;

Re: UFCS with implicit "this" ?

2016-08-09 Thread cy via Digitalmars-d-learn
On Tuesday, 9 August 2016 at 05:33:09 UTC, Jonathan M Davis wrote: Personally, I think that you should just make it a member function if it's not a generic function, but to each their own, Well, I use generics for when I have like, optional functionality that isn't inherent to the class

Re: When does take modify the underlying iterator?

2016-08-16 Thread cy via Digitalmars-d-learn
On Tuesday, 16 August 2016 at 21:13:38 UTC, Steven Schveighoffer wrote: static if(isForwardRange!(typeof(iter))) But this may not work for any input range, since any time you copy the range, you are copying internal state that may cache an element or more. Yes, that was the problem with

When does take modify the underlying iterator?

2016-08-16 Thread cy via Digitalmars-d-learn
InputRanges that are not ForwardRanges seem to lack a possibly crucial operation. I want to start with an arbitrary range, take 1 from it, then process the rest. But there doesn't seem to be any way to do that, because there's no way to tell whether "take" will advance the range, or whether it

How to avoid ctRegex (solved)

2016-08-21 Thread cy via Digitalmars-d-learn
At seconds PER (character range) pattern, ctRegex slows down compilation like crazy, but it's not obvious how to avoid using it, since Regex(Char) is kind of weird for a type. So, here's what I do. I think this is right. in the module scope, you start with: auto pattern = ctRegex!"foobar";

Re: How to avoid ctRegex (solved)

2016-08-27 Thread cy via Digitalmars-d-learn
On Wednesday, 24 August 2016 at 05:29:57 UTC, ag0aep6g wrote: The plain regex function doesn't have such a requirement. It also works with a pattern that's generated at run time, e.g. from user input. But you can use it with a compile time constant, too. And it works in CTFE then, but it does

Re: How to avoid ctRegex (solved)

2016-08-22 Thread cy via Digitalmars-d-learn
On Sunday, 21 August 2016 at 21:18:11 UTC, ag0aep6g wrote: I may be missing the point here, but just putting `auto pattern = regex("foobar");` at module level works for me. Really? I thought global variables could only be initialized with static stuff available during compile time, and you

Re: How to avoid ctRegex (solved)

2016-08-23 Thread cy via Digitalmars-d-learn
On Tuesday, 23 August 2016 at 04:51:19 UTC, ag0aep6g wrote: That's true, and apparently `regex("foobar")` can be evaluated at compile time. Then what's ctRegex in there for at all...?

Re: Is there a d analog of strncmp?

2016-08-23 Thread cy via Digitalmars-d-learn
import std.algorithm.searching: startsWith, commonPrefix; if(s1.startsWith(s2)) {...} string prefix = commonPrefix(s1,s2);

C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread cy via Digitalmars-d-learn
So a lovely C library does its own opaque allocation, and provides access to the malloc'd memory, and that memory's length. Instead of copying the results into garbage collected memory (which would probably be smart) I was thinking about creating a structure like: struct WrappedString {

Re: C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread cy via Digitalmars-d-learn
On Saturday, 11 March 2017 at 23:43:54 UTC, Nicholas Wilson wrote: A string *is* a pointer length pair, an immutable(char)[]. Yes, but surely there's some silly requirement, like that the pointer must only ever point to garbage collected memory, or something? ubyte[] arr; // or byte/char

Invoking the compiler during runtime

2020-08-05 Thread cy via Digitalmars-d-learn
D's compile-time-execution is fantastic, but there are some times when I'd like to examine the generated code, or produce code that needs to pass through earlier phases before CTFE, or do AST stuff. Sometimes I simply don't want to generate the code with every compilation, so saving the

Re: Invoking the compiler during runtime

2020-08-05 Thread cy via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 06:02:58 UTC, cy wrote: Some way to import the compiler itself, instead of calling it in a subprocess? Well, I did find this: https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ But it's pretty advanced... probably just invoking dmd

GDC and DMD incompatability, can both be used?

2020-07-10 Thread cy via Digitalmars-d-learn
hunt/source/hunt/serialization/JsonSerializer.d:125:20: error: basic type expected, not foreach 125 | static foreach (string member; FieldNameTuple!T) { I'm having a little trouble using the hunt library with gdc. Does gdc not support static foreach at all? Is there some way to

Re: GDC and DMD incompatability, can both be used?

2020-07-10 Thread cy via Digitalmars-d-learn
And OK yes I see gdc definitely does not support static foreach, but instead there's some sort of D compiler written in D compiled by GDC? That's just dmd, isn't it? https://github.com/D-Programming-GDC/GDC/pull/550 He calls it "DDMD."

Re: How to divide by space keeping words with spaces inside quotes?

2021-08-08 Thread cy via Digitalmars-d-learn
On Sunday, 8 August 2021 at 23:04:32 UTC, Marcone wrote: How to divide by space keeping words with spaces inside quotes? Well the designers of ASCII were morons who decided that open quote and close quote would be the same damn letter, so it's a little trickier. Basically what you have to do