On Friday, 1 March 2013 at 16:38:39 UTC, Era Scarecrow wrote:
On Friday, 1 March 2013 at 14:32:12 UTC, Andrea Fontana wrote:
struct MyStruct(WEIGHTS)
{
string ...
string ...
alias WEIGHTS weights;
}
enum FirstWeights : double
{
}
enum SecondWeights : double
{
double foo = 0.3,
d
On Friday, 1 March 2013 at 14:32:12 UTC, Andrea Fontana wrote:
struct MyStruct(WEIGHTS)
{
string ...
string ...
alias WEIGHTS weights;
}
enum FirstWeights : double
{
}
enum SecondWeights : double
{
double foo = 0.3,
double bar = 0.4
}
so:
auto s1 = MyStruct!FirstWeights ...
Andrea Fontana:
but:
enum s1 = MyStruct(firstWeights, 10, 8);
enum s2 = MyStruct(firstWeights, 9, 10);
writeln(likeness(s1, s2));
still gives error: and s1 and s2 are known at compile time,
aren't them?
Right. But they are known at compile-time only outside likeness().
Your solution
On Friday, 1 March 2013 at 16:03:58 UTC, bearophile wrote:
Andrea Fontana:
BTW, compiler can't guess s1 and s2 weights, should it?
if inside likeness() i write:
enum test = first.weights.foo * second.weights.foo;
it said that can't read first and second value at compile time.
firstWeights
Andrea Fontana:
BTW, compiler can't guess s1 and s2 weights, should it?
if inside likeness() i write:
enum test = first.weights.foo * second.weights.foo;
it said that can't read first and second value at compile time.
firstWeights and secondWeights are compile-time constants, but
the argum
On Friday, 1 March 2013 at 15:08:21 UTC, bearophile wrote:
void main() {
immutable s1 = MyStruct(firstWeights, 10, 8);
immutable s2 = MyStruct(firstWeights, 9, 10);
immutable s3 = MyStruct(secondWeights, 9, 10);
import std.stdio;
writeln(likeness(s1, s2))
void main() {
immutable s1 = MyStruct(firstWeights, 10, 8);
immutable s2 = MyStruct(firstWeights, 9, 10);
immutable s3 = MyStruct(secondWeights, 9, 10);
import std.stdio;
writeln(likeness(s1, s2));
Sorry for the mix of tabs and spaces. The crappy editor
Andrea Fontana:
How to put s1,s2,3... in a range/array or something
similar/iterable? Probably there's no way (inside variant?)...
One solution is to not use templates:
immutable struct Weights {
double foo, bar;
}
enum Weights firstWeights = { foo: 0.3, bar: 0.4 },
sec
On Friday, 1 March 2013 at 14:39:53 UTC, bearophile wrote:
Andrea Fontana:
double likeness(T,T1)(ref in T1, ref in T2)
==>
double likeness(T1, T2)(in ref T1, in ref T2)
Bye,
bearophile
Sure not the only error. I was writing "pseudo code". Real code
it's quite complex.
Try this one (is
On Friday, 1 March 2013 at 14:27:40 UTC, Andrea Fontana wrote:
I'm trying to do something like this. I don't know whether or
not it's a good idea, i'm open to solutions and suggestions
struct MyStruct(WEIGHTS)
{
string ...
string ...
alias WEIGHTS weights;
}
double likeness(T,T1)(ref
10 matches
Mail list logo