On Sunday, 30 September 2012 at 17:07:19 UTC, monarch_dodra wrote:
On Sunday, 30 September 2012 at 01:29:24 UTC, Ivan Agafonov
wrote:
// Tell me about this sutation, may be it is a bug?
[SNIP]
// all of this fails!!!
assert (a.length == a.length); // This is really shocking
On Saturday, 10 March 2012 at 03:32:44 UTC, Caligo wrote:
struct B { }
struct C { }
struct D { }
struct A {
ref A foo(B item) {
/* do something special. */
return this;
}
ref A foo(T)(T item) if(is(T == C) || is(T == D)) {
/* nothing sp
On Mon, 14 Nov 2011 15:13:20 +0200, Steven Schveighoffer
wrote:
There is definitely some debatable practice here for wherever enum is
used on an array.
Consider that:
enum a = "hello";
foo(a);
Does not allocate heap memory, even though "hello" is a reference type.
However:
enum a = ['
seriously want an error here???
}
You are missing the point, nobody asked that. You are assigning it to
auto, a runtime variable.
Which was asked was about modifying a constant, sort(a) means sort a
in-place. So you cant do:
immutable a;
sort(a);
But with current design you can do:
enum a
of a effectively copies the value of a to wherever its
used.
So,
enum a = [3, 1, 2];
sort(a);
is _identical_ to
sort([3, 1, 2]);
That means that if you use a in any code, it's copied in that code such
that
you could end up allocating a lot of memory that you didn't intend to
odule variable.
immutable a = [3, 1, 2];
Otherwise, you're allocating a new array every time you use the enum.
So, use
a manifest constant when you want to avoid having it take up any memory
but
don't care about whatever allocations may occur when it's used (primitive
types
On Fri, 23 Sep 2011 23:44:41 +0300, Jonathan M Davis
wrote:
It uses the const version if the struct or class is const. And in
neither case
in your program is it const. It's mutable in both, so the mutable
overload is
the one that gets called in both places. Why would the const ve
On Fri, 23 Sep 2011 23:44:52 +0300, Steven Schveighoffer
wrote:
steves@steve-laptop:~/testd$ cat testconst.cpp
#include
using namespace std;
struct S {
S& fun() {
cout << "fun" << endl;
return *this;
}
S fun() const {
cout << "fun const" << endl;
On Fri, 23 Sep 2011 23:27:02 +0300, Jonathan M Davis
wrote:
On Friday, September 23, 2011 23:19:15 so wrote:
Hello everyone.
I asked this a few times with no response.
Could anyone explain me what is the rational behind this?
Why it won't distinguish mutable overload from immutable as
Hello everyone.
I asked this a few times with no response.
Could anyone explain me what is the rational behind this?
Why it won't distinguish mutable overload from immutable as in C++?
test2.d
Description: Binary data
(I think that "enum" and "static enum" are the same thing.)
"static enum" makes no sense, shouldn't it be an error?
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
.
On Sun, 28 Mar 2010 19:09:18 +0400, #ponce wrote:
so Wrote:
Basically what i am asking is hmmm, ability to write generic constants?
:)
Thanks!
Hi,
When writing generic FP code i always use real literals and cast to T,
or int. I suggest doing this.
Like:
T exp3(T)(T x)
{
if
1 +0400, biozic wrote:
Le 28/03/10 10:57, so a écrit :
Well, i am having hard time explaining, it is not a surprise that you
don't understand.
To make things clearer, lets forget floats for a seconds and change your
code to standard unsigned types.
import std.stdio: writeln;
struct Vector(T)
You didn't change anything there, just back to original code, now just
enabled implicit cast again!
Please read my next replies, everything should be clear now. :)
Thanks!
On Sun, 28 Mar 2010 14:32:21 +0400, bearophile
wrote:
so:
Well, i am having hard time explaining, it is
Everything comes to this...
Why "3" is an int?
Why "0.3 is a double?
I guess these constraints was there before generic coding comes out, and
we are just stuck with it!
If these sound so naive, sorry about it, I don't know compiler/language
history.
Thanks!
On Sun,
Basically what i am asking is hmmm, ability to write generic constants? :)
Thanks!
On Sun, 28 Mar 2010 12:29:17 +0400, bearophile
wrote:
so:
With one exception yes, i want all 3 test pass with your fix to implicit
cast.
You know, we are trying to write generic code.
I don't under
Well, i am having hard time explaining, it is not a surprise that you
don't understand.
To make things clearer, lets forget floats for a seconds and change your
code to standard unsigned types.
import std.stdio: writeln;
struct Vector(T) {
this(T m) { mm = m; }
Vector opBinary(strin
With one exception yes, i want all 3 test pass with your fix to implicit
cast.
You know, we are trying to write generic code.
Thanks!
On Sat, 27 Mar 2010 22:21:46 +0200, bearophile
wrote:
Are you trying to do this?
import std.stdio: writeln;
struct Vector(T) {
this(T m) { mm = m; }
takes a variable of type T,
but it accepted 0.3 on all 3 tests, implicitly casted double to T. In C++
world this brings tons of trouble, especially performance problems,
but here i am not sure what DMD does that there :)
Thanks.
On Sat, 27 Mar 2010 16:44:32 +0200, bearophile
wrote:
s
On Sat, 27 Mar 2010 15:54:19 +0200, Bill Baxter wrote:
Note that 'real' is a built in type in D. It's an 80-bit float on x86
procs and 64-bit elsewhere.
So .5L is like cast(real).5. Not the solution you were looking for.
--bb
That "r for real!" was joke.
What i m
On Sat, 27 Mar 2010 12:20:38 +0200, so wrote:
I haven't seen a single C++ library able to do this properly. (I would
just copy it!)
This is one of the reasons why something like
std::numeric_limits::function() exists.
Which makes a generic and *clean* numeric code in C++ nonexistent.
On Sat, 27 Mar 2010 15:28:22 +0200, bearophile
wrote:
so:
One thing i can think of now is adding another float literal, maybe 'r',
for "real"!,
See here, Unfortunately it's called "L" not "r":
http://www.digitalmars.com/d/2.0/lex.html
free to cast this to any floating point suitable.
Some kind of template, i don't know!
So when i have something like this :
scalar m = 0.99r;
when scalar is f32 :
scalar m = 0.99f;
when scalar is f64 :
scalar m = 0.99;
...
On Sat, 27 Mar 2010 13:32:24 +0200, Robert Clipsham
wrote:
On 27/03/10 10:20, so wrote:
In C++!
I have a type defined in the core library like..
typedef float scalar;
//typedef double scalar; // <-- whole framework is now double precision
alias float scalar;
//alias double sca
On Sat, 27 Mar 2010 13:52:28 +0200, bearophile
wrote:
so:
Since D is superb, i like to know how you do it in D.
If you got a better idea in C++, i would like to hear that too!
You know there are float literal too, in C++/D, like: 5.5f
I don't think D can help you more than C++ here
In C++!
I have a type defined in the core library like..
typedef float scalar;
//typedef double scalar; // <-- whole framework is now double precision
Next i instantiate vectors, matrices etc... from templates.
typedef vector_t vector;
typedef matrix_t matrix;
Until now everything cool, here pa
Hello!
For me, the best language/compiler tester is a generic, high performance
vector/matrix library.
D so far the best tool i have seen for both, and with the addition of
opDispatch... awesome!
As a newbie, this is my take on basic vector swizzle.
I can't think like a "D code
27 matches
Mail list logo