Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 July 2016 at 04:38:03 UTC, Basile B. wrote: two obvious: - recursive template. - staticIota in a foreach. (aliasSeqOf!(iota(1, T.length)) even better: template sameType(T...) { import std.meta; static if (!T.length) enum sameType = false; else enum

Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 July 2016 at 04:31:08 UTC, Devin Hill wrote: Thanks, that way of doing it does work. I guess that means there's no easy way to make sure all T are the same type without a template constraint? Yes, immediatly, now, I think that a contraint has to be used. But you have several

Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Devin Hill via Digitalmars-d-learn
On Friday, 15 July 2016 at 04:08:19 UTC, Basile B. wrote: With D style variadics it works, you can build the array from the list and have a static array: = void foo(T...)(T t) { T[0][T.length] tt = [t]; // T[0] is the type writeln(tt); // [1,2,3] static

Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 July 2016 at 03:43:49 UTC, Devin Hill wrote: Hi everyone, I have a struct template which takes an integer n, and then has a constructor taking that many arguments of type long, which looks like: struct Struct(int n) { this(long[n] nums...) { /* stuff */ } } This works and

Are templates with variadic value parameters possible?

2016-07-14 Thread Devin Hill via Digitalmars-d-learn
Hi everyone, I have a struct template which takes an integer n, and then has a constructor taking that many arguments of type long, which looks like: struct Struct(int n) { this(long[n] nums...) { /* stuff */ } } This works and lets me change n for each instantiation, but I wanted to

Re: persistence, serialization, history (run-to-run) in small self-contained program

2016-07-14 Thread dan via Digitalmars-d-learn
On Thursday, 14 July 2016 at 08:28:56 UTC, Jacob Carlborg wrote: On 2016-07-14 07:18, dan wrote: I'm writing a small program (compiled with gdc on xubuntu 16.04). I would like it to remember a little data (a few kilobytes maybe). . My main concern is minimizing program complexity.

Type constructor with new size

2016-07-14 Thread Eppason via Digitalmars-d-learn
How can I create a new type NT from type T that such that NT is compatible with T when reduced to the size of T, but has size n? Another way to see it is that I would like to construct a type at compile time that has the same layout as another type but padded exactly by n - T.sizeof bytes. It

Re: Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn
On Thursday, 14 July 2016 at 19:48:38 UTC, ag0aep6g wrote: Make F an alias parameter: struct Neurons_layer(T = float, size_t neurons_num = 0, alias F = Sigmoid) if(isFloatingPoint!T && is(typeof(F!T.Function))) { ... private: alias Function = F!T.Function; } unittest {

Re: Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn
On Thursday, 14 July 2016 at 19:48:20 UTC, Lodovico Giaretta wrote: You don't need Sigmoid!float at all. This will work: Neurons_layer!(float, 5) nf; as you provided a default value for the third argument. Yes, default init is present, but double, real types are desirable

Re: Templates args

2016-07-14 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 14 July 2016 at 19:28:23 UTC, Andrey wrote: On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote: [...] struct Sigmoid(T) { [...] } struct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) { [...]

Re: Templates args

2016-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/16 3:28 PM, Andrey wrote: On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote: struct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) { private: static if(neurons_num > 0) T[neurons_num]

Re: Templates args

2016-07-14 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 14 July 2016 at 19:28:23 UTC, Andrey wrote: On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote: Hi guys! Help a newbie please. Playing with D and trying to understand some features. Here is my try to carry out my code from C++ project to D struct Sigmoid(T) { const T

Re: Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn
On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote: Hi guys! Help a newbie please. Playing with D and trying to understand some features. Here is my try to carry out my code from C++ project to D struct Sigmoid(T) { const T Function(T value) { ... } const T

Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn
Hi guys! Help a newbie please. Playing with D and trying to understand some features. Here is my try to carry out my code from C++ project to D struct Sigmoid(T) { const T Function(T value) { ... } const T DerivateFunction(const T value) { ... } } struct Neurons_layer(T =

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/16 5:56 AM, Miguel L wrote: On Thursday, 14 July 2016 at 09:12:50 UTC, Jonathan M Davis wrote: So, whether you should be using Appender or assumeSafeAppend or neither depends entirely on what you're doing. However, in general, simply appending to dynamic arrays does not result in many

Re: Some asm help for the 'thiscall' calling convention?

2016-07-14 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 22:30:51 UTC, Adam Sansier wrote: Um, no, I revived it so that people searching for answers wouldn't be led astray by idiots who pretend to know everything. My word is not COM specification of course, there's the official documentation and tons of books about

Re: Is logical subsetting of an array possible ?

2016-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/16 7:03 AM, Sahil wrote: On Thursday, 14 July 2016 at 10:51:33 UTC, Nicholas Wilson wrote: On Thursday, 14 July 2016 at 10:43:12 UTC, Sahil wrote: This is with reference to documentation about use of array in D (https://dlang.org/spec/arrays.html#array-setting). easily. The function

Re: I can has @nogc and throw Exceptions?

2016-07-14 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 22:42:36 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 21:27:16 UTC, Lodovico Giaretta wrote: At the end, all memory comes from one of these: GC heap, malloc, mmap, sbrk. All other allocators build on top of these (or on top of user supplied buffers,

Re: Reserve on dynamic arrays

2016-07-14 Thread cym13 via Digitalmars-d-learn
On Thursday, 14 July 2016 at 09:29:10 UTC, Jonathan M Davis wrote: On Thursday, July 14, 2016 07:20:46 cym13 via Digitalmars-d-learn wrote: [...] Whatever the profiler is telling you, it's clearly not actually telling you whether an allocation took place, and that's easy to test. For

Re: Confused about referencing in D

2016-07-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 14 July 2016 at 06:23:15 UTC, Gorge Jingale wrote: I think that the assignment in the first case is not assigning the reference returned by auto ref GetValue(). `ref` in D is shallow, it only applies to the thing it is specifically on and is lost across assignments. Once you

Problems with -fPIC, libraries and exceptions (in linux?)

2016-07-14 Thread Arafel via Digitalmars-d-learn
Hi! I've stumbled across the following problem: when I raise an exception from a (statically linked) library that was compiled with -fPIC, I get a segmentation fault. Example: -- libfoo/dub.json { "name" : "foo", "description" : "Exception raising lib", "dflags" : [

Re: Is logical subsetting of an array possible ?

2016-07-14 Thread Sahil via Digitalmars-d-learn
On Thursday, 14 July 2016 at 11:01:20 UTC, Nicholas Wilson wrote: On Thursday, 14 July 2016 at 10:51:33 UTC, Nicholas Wilson wrote: I should explain this a bit more if you are totally new to D. although filter looks like a method for an array type it is not it is a function. in D function

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 14, 2016 09:56:02 Miguel L via Digitalmars-d-learn wrote: > Thank you Jonathan, that really cleared up a lot of things, I > read the article. But I still have this doubt: is > assumeSafeAppend() changing a property of the array as "this > array is never going to be referenced by

Re: Is logical subsetting of an array possible ?

2016-07-14 Thread Sahil via Digitalmars-d-learn
On Thursday, 14 July 2016 at 10:51:33 UTC, Nicholas Wilson wrote: On Thursday, 14 July 2016 at 10:43:12 UTC, Sahil wrote: This is with reference to documentation about use of array in D (https://dlang.org/spec/arrays.html#array-setting). easily. The function you are looking for is called

Re: Is logical subsetting of an array possible ?

2016-07-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 14 July 2016 at 10:51:33 UTC, Nicholas Wilson wrote: On Thursday, 14 July 2016 at 10:43:12 UTC, Sahil wrote: (I am totally new to D) easily. The function you are looking for is called 'filter' import std.algorithm; import std.array; int[] a = [ 4,5,8,1,3,2,9,10]; auto b =

Re: Is logical subsetting of an array possible ?

2016-07-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 14 July 2016 at 10:43:12 UTC, Sahil wrote: This is with reference to documentation about use of array in D (https://dlang.org/spec/arrays.html#array-setting). In languages tailor-made for data mining, like R, a subset of an array (not necessarily contiguous values) can be

Is logical subsetting of an array possible ?

2016-07-14 Thread Sahil via Digitalmars-d-learn
This is with reference to documentation about use of array in D (https://dlang.org/spec/arrays.html#array-setting). In languages tailor-made for data mining, like R, a subset of an array (not necessarily contiguous values) can be extracted as shown below: vec //a vector or array in R

Re: C++ interface vs D and com

2016-07-14 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 21:27:29 UTC, Adam Sansier wrote: Yes! your right, If you were only around to tell me that in the first place! ;) Now we know. Again, as I said before, the problem is informational. We know it only after you posted links to threads with relevant info. You knew

Re: cant run unittests

2016-07-14 Thread dom via Digitalmars-d-learn
On Thursday, 14 July 2016 at 00:33:50 UTC, ethgeh wrote: On Wednesday, 13 July 2016 at 19:41:53 UTC, dom wrote: how can i run my unittests for a dynamic library? some weird conflict is reported between main functions, my project doesnt contain any main function. [...] try to put this

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Miguel L via Digitalmars-d-learn
On Thursday, 14 July 2016 at 09:12:50 UTC, Jonathan M Davis wrote: So, whether you should be using Appender or assumeSafeAppend or neither depends entirely on what you're doing. However, in general, simply appending to dynamic arrays does not result in many reallocations (just like it doesn't

Re: Confused about referencing in D

2016-07-14 Thread kink via Digitalmars-d-learn
On Thursday, 14 July 2016 at 06:23:15 UTC, Gorge Jingale wrote: I think that the assignment in the first case is not assigning the reference returned by auto ref GetValue(). Yep. There's no such thing as C++ `auto& val = GetValue()` in D. You'd have to use a pointer instead: `auto pVal = ()`.

Re: Reserve on dynamic arrays

2016-07-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 14, 2016 07:20:46 cym13 via Digitalmars-d-learn wrote: > As one can see there seem to be absolutely no difference in > allocations wether we reserve or not. I've ran more experiences, > reserving way less or more than I appened to no avail: > allocations seem to just ignore it. >

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 14, 2016 07:07:52 Miguel L via Digitalmars-d-learn wrote: > Ok, i have read about Appender and assumeSafeAppend(), but i am > still a bit confused. > What i have understood is: dynamic arrays are (almost) always > reallocating when appending to them except assumeSafeAppend() is >

Re: persistence, serialization, history (run-to-run) in small self-contained program

2016-07-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-07-14 07:18, dan wrote: I'm writing a small program (compiled with gdc on xubuntu 16.04). I would like it to remember a little data (a few kilobytes maybe). It looks like d comes with standard support for both sqlite3 and json --- is there any particular reason to prefer one over the

Reserve on dynamic arrays

2016-07-14 Thread cym13 via Digitalmars-d-learn
Does changing the capacity of dynamic arrays actually do anything with respect to memory allocation? I have the following data with DMD 2.071.1 // With dmd -profile=gc void main() { import std.stdio; int[] arr = [1, 1, 1]; arr.reserve(512); foreach (i ; 0..10) arr ~=

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 17:19:09 UTC, Steven Schveighoffer wrote: On 7/13/16 8:41 AM, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 12:37:26 UTC, Miguel L wrote: I tried Appender, but for some reason garbage collector still seems to be running every few iterations. I will try

Re: Confused about referencing in D

2016-07-14 Thread rikki cattermole via Digitalmars-d-learn
On 14/07/2016 6:23 PM, Gorge Jingale wrote: I'm pretty confused why the following code doesn't work as expected. GetValue is a struct. auto value = GetValue(); memcpy(, , Val.sizeof); But if I plug in value direct to memset it works!! memcpy((), , Val.sizeof); GetValue returns memory

Confused about referencing in D

2016-07-14 Thread Gorge Jingale via Digitalmars-d-learn
I'm pretty confused why the following code doesn't work as expected. GetValue is a struct. auto value = GetValue(); memcpy(, , Val.sizeof); But if I plug in value direct to memset it works!! memcpy((), , Val.sizeof); GetValue returns memory to stick a value in and the memcpy is