Templates args
Lodovico Giaretta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 14 12:48:20 PDT 2016
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 Function(T value)
>> {
>> ...
>> }
>> const T DerivateFunction(const T value)
>> {
>> ...
>> }
>> }
>>
>> 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] _neurons_arr;
>> else
>> T[] _neurons_arr;
>>
>> private:
>> alias Function = F.Function;
>> }
>>
>> unittest
>> {
>> Neurons_layer!(float,5,Sigmoid!float) nf;
>> }
>>
>>
>> The question is - How to make in pretty way this line:
>> Neurons_layer!(float,5,Sigmoid!float) nf;
>
> to something like - Neurons_layer!(float,5,Sigmoid) nf;
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.
More information about the Digitalmars-d-learn
mailing list