Re: Filter a Range Based on a Passed In Variable

2018-01-20 Thread jsako via Digitalmars-d-learn
On Saturday, 20 January 2018 at 19:09:28 UTC, Adam D. Ruppe wrote: On Saturday, 20 January 2018 at 19:04:06 UTC, jsako wrote: I want to be able to filter a range based on a variable known at runtime. Something like this: [code] int id = getFilterID(); auto filteredRange = filter!(a => a.id

Re: Filter a Range Based on a Passed In Variable

2018-01-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 January 2018 at 19:04:06 UTC, jsako wrote: I want to be able to filter a range based on a variable known at runtime. Something like this: [code] int id = getFilterID(); auto filteredRange = filter!(a => a.id == id)(rangeToBeFiltered); [/code] This doesn't seem to be

Filter a Range Based on a Passed In Variable

2018-01-20 Thread jsako via Digitalmars-d-learn
I want to be able to filter a range based on a variable known at runtime. Something like this: [code] int id = getFilterID(); auto filteredRange = filter!(a => a.id == id)(rangeToBeFiltered); [/code] This doesn't seem to be possible, however as .filter only takes unary predicates. I tried:

Re: How to manage function's parameter storage class?

2018-01-20 Thread Sobaya via Digitalmars-d-learn
On Saturday, 20 January 2018 at 17:05:40 UTC, Simen Kjærås wrote: On Saturday, 20 January 2018 at 14:31:59 UTC, Sobaya wrote: How can I wrap function whose arguments contain both ref and normal like 'func' ? With normal 'Args', x is not increased because x is copied when passed to opDispatch.

Re: Cannot initialize associative array

2018-01-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 19, 2018 23:39:08 rumbu via Digitalmars-d-learn wrote: > Thank you Adam, just figured out myself the same solution, but I > didn't expect to have a static constructor in main.d. I thought > static constructors are meant to be used in imported modules. > Thanks again. There

Re: Using Postgres connection functions

2018-01-20 Thread Joe via Digitalmars-d-learn
On Saturday, 20 January 2018 at 04:54:47 UTC, Adam D. Ruppe wrote: Same as above. The general pattern is: C_Type[] name = new C_Type[](requested_size); // pass as `name.ptr`. This becomes a C_Type* Thanks, Adam. Perhaps something like this ought to make its way into the "D for C Programmers"

Re: How to manage function's parameter storage class?

2018-01-20 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 20 January 2018 at 14:31:59 UTC, Sobaya wrote: How can I wrap function whose arguments contain both ref and normal like 'func' ? With normal 'Args', x is not increased because x is copied when passed to opDispatch. If I write 'ref Args' in opDispatch's argument, it fails because

How to manage function's parameter storage class?

2018-01-20 Thread Sobaya via Digitalmars-d-learn
I'm using opDispatch for wrapping a function like below. ``` import std.stdio; void func(ref int x, int y) { x++; } struct B { // wraps 'func'. I want to implement this function. template opDispatch(string fn) { void opDispatch(Args...)(Args args) {

Re: Struct initialization syntax

2018-01-20 Thread Azi Hassan via Digitalmars-d-learn
On Thursday, 18 January 2018 at 03:50:15 UTC, arturg wrote: On Wednesday, 17 January 2018 at 17:37:07 UTC, H. S. Teoh wrote: On Wed, Jan 17, 2018 at 05:31:03PM +, Azi Hassan via Digitalmars-d-learn wrote: The D tour for structs uses a syntax similar to that of C++ in order to initialize a

Re: Relocatable objects and internal pointers

2018-01-20 Thread timotheecour via Digitalmars-d-learn
On Saturday, 30 January 2016 at 03:13:59 UTC, Matt Elkins wrote: std.typecons.Unique seems to require heap allocation, which makes it a far cry from std::unique_ptr. isn't unique_ptr typically for heap allocation? eg: