Re: How to check if an array is a manifest constant?

2011-04-04 Thread simendsjo
What use case do you have for wanting to know whether a variable is an enum or not? The same reason I'd like to check if it's const/immutable; if an algorithm requires a modifiable array. void sortInPlace(int[] array) { array.sort; } void main() { int[] a = [3,2,1];

Static array size limit

2011-04-02 Thread simendsjo
http://digitalmars.com/d/2.0/arrays.html says static arrays are limited to 16mb, but I can only allocate 1mb. My fault, or bug? enum size = (16 * 1024 * 1024) / int.sizeof; //int[size] a; // Error: index 4194304 overflow for static array enum size2 = (16 * 1000 * 1000) /

Re: Static array size limit

2011-04-02 Thread simendsjo
This is using dmd 2.052 on windows by the way.

Re: Static array size limit

2011-04-02 Thread simendsjo
I think you missed my /int.sizeof at the end. enum size = (16*1024*1024)/int.sizeof; int[size] a; // Error index overflow for static as expected int[size-1] b; // stack overflow int[250_001] c; // stack overflow int[250_000] d; // ok

Where does the template parameter E come from?

2011-03-28 Thread simendsjo
When running compose with two arguments, the implementation uses the template parameter E. I don't understand what's going on here as E isn't submitted to the template - what type is E? I've also seen this in unary/binaryFun using ElementType. template compose(fun...) { alias

Re: Where does the template parameter E come from?

2011-03-28 Thread simendsjo
On 28.03.2011 16:54, simendsjo wrote: When running compose with two arguments, the implementation uses the template parameter E. I don't understand what's going on here as E isn't submitted to the template - what type is E? I've also seen this in unary/binaryFun using ElementType. template

Re: Where does the template parameter E come from?

2011-03-28 Thread simendsjo
On 28.03.2011 17:07, David Nadlinger wrote: On 3/28/11 4:54 PM, simendsjo wrote: When running compose with two arguments, the implementation uses the template parameter E. I don't understand what's going on here as E isn't submitted to the template - what type is E? […] typeof({ E a; return

Error in Template Alias Parameter example in the documentation

2011-03-17 Thread simendsjo
This example comes from http://digitalmars.com/d/2.0/template.html int x; template Foo(alias X) { static int* p = X; } void test() { alias Foo!(x) bar; *bar.p = 3; // set x to 3 static int y; alias Foo!(y) abc; *abc.p = 3; // set y to 3 } Compiling this

TemplateParameterList in is expression

2011-03-16 Thread simendsjo
I'm having some problems understanding the (complex) is expression. // Example from the documentation static if (is(int[10] X : X[Y], int Y : 5)) { assert(0); // should not match, Y should be 10 } // but this doesn't match either.. Shouldn't it? static if (is(int[10] X : X[Y],

Expression tuples

2011-03-16 Thread simendsjo
http://www.digitalmars.com/d/2.0/tuple.html // this example fails Tuple!(3, 7, 'c') typecons.d(298): Error: static assert Attempted to instantiate Tuple with an invalid argument: 3 Even this fails: alias Tuple!(0) T; Is Tuple only meant to store types or named types?

Re: Mocking framework

2011-03-09 Thread simendsjo
I gave this some thought, and I'm probably just a bit braindamaged by C#. Consider you wish to unittest a class that fetches data from a database and sends an email. The common scenario here is to use IoC and mock the objects so you can check that FetchData was called and SendEmail is called

Re: Some weird crashes

2011-03-08 Thread simendsjo
On 08.03.2011 01:32, Andrej Mitrovic wrote: Sorry for not seeing this sooner. I think you might have set the wrong calling convention in the translated header file. See my answer on SO. I hope it works for you now. Thanks. Just to get the solution here too: * Use the vs2005 library (to get

Re: Wrapping C that uses compiler extensions

2011-03-05 Thread simendsjo
On 05.03.2011 08:58, Jérôme M. Berger wrote: simendsjo wrote: On 04.03.2011 22:42, Jérôme M. Berger wrote: int main(string[] args) { auto s1 =(); // MH MH auto s2 =(); // OK s2.c =ull; // OK return 0; } Is part of your message gone? Uh, I did not write

Re: Some weird crashes

2011-03-05 Thread simendsjo
On 28.02.2011 18:52, simendsjo wrote: I'm trying to wrap the newest mysql c connector, but I get some weird bugs. I don't know any assembly, so I don't even know if I've included enough info.. I hope this is a small enough test case so someone can understand the issue. I've used implib

Re: htod and system files

2011-03-05 Thread simendsjo
On 05.03.2011 20:04, Bekenn wrote: On 3/4/2011 3:31 PM, simendsjo wrote: The htod page, http://www.digitalmars.com/d/2.0/htod.html, says that system files will be included using the -hs option. htod mysql.h -hs Fatal error: unable to open input file 'sys/types.h' Does it try to find

C const

2011-03-04 Thread simendsjo
I'm not quite sure how to wrap c's const. This page, http://www.digitalmars.com/d/2.0/htomodule.html, says: D has const as a type modifier. void foo(const int *p, char *const q); becomes: void foo(const int* p, const char* q); But D's const is transitive - there are no const

Wrapping C that uses compiler extensions

2011-03-04 Thread simendsjo
This code confuses me... It's from the c mysql windows dll, libmysql.dll. size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, const char *fmt, ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5); #ifndef _my_attribute_h #define _my_attribute_h /*

Re: Wrapping C that uses compiler extensions

2011-03-04 Thread simendsjo
On 04.03.2011 22:42, Jérôme M. Berger wrote: int main(string[] args) { auto s1 =(); // MH MH auto s2 =(); // OK s2.c =ull; // OK return 0; } Is part of your message gone? You can safely ignore the “ATTRIBUTE_FORMAT_FPTR(printf, 4, 5)”. That I understood :)

Re: C const

2011-03-04 Thread simendsjo
On 04.03.2011 23:10, Jesse Phillips wrote: simendsjo Wrote: So all const modifiers should be dropped everywhere..? And should the const be dropped here? struct somestruct { const struct otherstruct; } All in all the real answer comes down to, is the data modified. Since C makes

Re: Some weird crashes

2011-03-03 Thread simendsjo
Thanks! I couldn't find it on the web page. coffimplib is missing to option to prepend _ to the types as implib does with /system. Any way around this (without changing all my code)?

Re: Some weird crashes

2011-03-03 Thread simendsjo
On 02.03.2011 18:24, Denis Koroskin wrote: On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo simen.end...@pandavre.com wrote: On 28.02.2011 20:24, Denis Koroskin wrote: On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo simen.end...@pandavre.com wrote: On 28.02.2011 18:52, simendsjo wrote

Re: Some weird crashes

2011-03-02 Thread simendsjo
On 02.03.2011 18:24, Denis Koroskin wrote: On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo simen.end...@pandavre.com wrote: On 28.02.2011 20:24, Denis Koroskin wrote: On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo simen.end...@pandavre.com wrote: On 28.02.2011 18:52, simendsjo wrote

Re: Some weird crashes

2011-03-01 Thread simendsjo
On 28.02.2011 20:24, Denis Koroskin wrote: On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo simen.end...@pandavre.com wrote: On 28.02.2011 18:52, simendsjo wrote: // ERROR auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); auto oldcn = cn; writeln(mysql_errno(cn

Some weird crashes

2011-02-28 Thread simendsjo
I'm trying to wrap the newest mysql c connector, but I get some weird bugs. I don't know any assembly, so I don't even know if I've included enough info.. I hope this is a small enough test case so someone can understand the issue. I've used implib on the included dll and rdmd and dmd 2.051 to

Re: Some weird crashes

2011-02-28 Thread simendsjo
On 28.02.2011 18:52, simendsjo wrote: // ERROR auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); auto oldcn = cn; writeln(mysql_errno(cn)); assert(cn == oldcn); // when the last assert is active, the above line changes cn and thus fails. auto err = mysql_errno(cn

Re: Some weird crashes

2011-02-28 Thread simendsjo
On 28.02.2011 20:24, Denis Koroskin wrote: I think you have a bug at line 42. On a serious note, it might have helped if you'd attached source code, or at least binaries. The file was too large to be attached. Here's a link to a public hosting service: http://share1t.com/4xgt2l. Everything

Re: Interfacing with c and platform dependent sizes

2011-02-27 Thread simendsjo
On 27.02.2011 11:43, Jacob Carlborg wrote: On 2011-02-26 17:58, simendsjo wrote: On 26.02.2011 17:06, Mike Wey wrote: On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple

Version very simple?

2011-02-27 Thread simendsjo
I'm having some problems grokking version. How would I translate this simple C macro? #if !defined(IDENT) || !defined(IDENT2) I've tried the following: version(!IDENT) identifier or integer expected, not ! !version(IDENT) Declaration expected, not '!' version(IDENT || IDENT2) found '||'

Re: Version very simple?

2011-02-27 Thread simendsjo
On 27.02.2011 16:18, David Nadlinger wrote: On 2/27/11 3:52 PM, simendsjo wrote: I'm having some problems grokking version. How would I translate this simple C macro? #if !defined(IDENT) || !defined(IDENT2) You are facing a quite common question, with the answer being

Re: Version very simple?

2011-02-27 Thread simendsjo
On 27.02.2011 17:27, Lars T. Kyllingstad wrote: On Sun, 27 Feb 2011 15:52:01 +0100, simendsjo wrote: I'm having some problems grokking version. How would I translate this simple C macro? #if !defined(IDENT) || !defined(IDENT2) I've tried the following: version(!IDENT) identifier

Re: Interfacing with c and platform dependent sizes

2011-02-26 Thread simendsjo
On 26.02.2011 17:06, Mike Wey wrote: On 02/26/2011 11:49 AM, Jacob Carlborg wrote: On 2011-02-26 01:28, simendsjo wrote: C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1) http://www.digitalmars.com/d/2.0/htomodule.html 2) http

Interfacing with c and platform dependent sizes

2011-02-25 Thread simendsjo
C is not my strong side, so I'm having some problems wrapping some code. I found a couple of sources on this: 1) http://www.digitalmars.com/d/2.0/htomodule.html 2) http://www.digitalmars.com/d/2.0/interfaceToC.html 1) C's long is the same as D's int. long long is long 2) C 32bit's long long is

Re: Multiple assignment

2011-02-25 Thread simendsjo
On 26.02.2011 01:56, bearophile wrote: Is this program showing a bug in multiple assignments (DMD 2.052)? void main() { int i; int[2] x; i, x[i] = 1; assert(x == [1, 0]); // OK int j; int[2] y; y[j], j = 1; assert(y == [0, 0]); // Not OK } At the end

Re: Interfacing with c and platform dependent sizes

2011-02-25 Thread simendsjo
On 26.02.2011 02:06, bearophile wrote: simendsjo: So.. A long in C is the same as the platform size? And long long doesn't exist in 64 bit? In D the size of int/uint is 32 bits and long/ulong is 64 bits. In C the size of int, unsigned int, long, long long int, unsigned long long int, etc

Phobos roadmap?

2011-02-16 Thread simendsjo
I've seen discussions on buffered ranges, std.parallelism, replacement of std.xml, std.process and std.stream and probably several other things I've already forgotten. DMD seems to have a quite updated roadmap in the wiki: http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel#Roadmap Does

Re: SO rotate question

2010-09-03 Thread simendsjo
Pelle wrote: On 09/02/2010 10:24 PM, bearophile wrote: simendsjo: Suggestions for D-ifying the code is welcome. Your unit tests are not good enough, they miss some important corner cases. This my first version in D2: import std.string: indexOf; /// return True if s1 is a rotated version

SO rotate question

2010-09-02 Thread simendsjo
http://stackoverflow.com/questions/2553522/interview-question-check-if-one-string-is-a-rotation-of-other-string I created a solution, but I don't want D to look bad, so I won't post it. It's a bit for loop heavy... At least it's shorter than the c example, but I don't know about speed or

Compiler bug? Functions as Array Properties doesn't work with nested functions

2010-08-15 Thread simendsjo
The spec doesn't mention anything about nested functions here. This works void foo(int[] a, int x) { }; void main() { int[] array; foo(array, 3); array.foo(3); } But this gives undefined identifier module t.foo void main() { void foo(int[] a, int x) { };

std.range design part of the language..?

2010-08-15 Thread simendsjo
From http://digitalmars.com/d/2.0/statement.html#ForeachStatement, Foreach over Structs and Classes with Ranges. I read this as the Range design is a part of the language now. Is this correct? And is the spec a bit out of date in the examples? It says foreach-/reverse translates to for(

Re: std.range design part of the language..?

2010-08-15 Thread simendsjo
On 15.08.2010 23:58, Jonathan M Davis wrote: On Sunday 15 August 2010 10:12:06 simendsjo wrote: From http://digitalmars.com/d/2.0/statement.html#ForeachStatement, Foreach over Structs and Classes with Ranges. I read this as the Range design is a part of the language now. Is this correct

rdmd only works with files in current directory on Windows?

2010-08-14 Thread simendsjo
c:\temp\src\test.d c:\temprdmd src\test The system cannot find the path specified. c:\temprdmd src/test std.file.FileException: (...)\.rdmd\rdmd-src/test.d-(...): The system cannot find the path specified. Using rdmd 20090902, dmd 2.048 and 64 bit win7

Duck typing and safety.

2010-08-13 Thread simendsjo
While reading std.range, I though that a ducktyping design without language/library support can be quite fragile. Consider the following example: import std.stdio; struct S { void shittyNameThatProbablyGetsRefactored() { }; } void process(T)(T s) { static if(

Re: Duck typing and safety.

2010-08-13 Thread simendsjo
On 13.08.2010 19:17, Steven Schveighoffer wrote: On Fri, 13 Aug 2010 13:01:47 -0400, simendsjo simen.end...@pandavre.com wrote: While reading std.range, I though that a ducktyping design without language/library support can be quite fragile. Consider the following example: import std.stdio

typeof and block statements

2010-08-12 Thread simendsjo
The spec doesn't mention anything about block statements in typeof declarations. //typeof({1}) a; // found } expecting ; //typeof({1}()) b; // same as a typeof(1) c; // int I'm asking because isInputRange from std.range the idom from the b test: template

Re: typeof and block statements

2010-08-12 Thread simendsjo
On 12.08.2010 15:30, Steven Schveighoffer wrote: On Thu, 12 Aug 2010 09:13:54 -0400, simendsjo simen.end...@pandavre.com wrote: The spec doesn't mention anything about block statements in typeof declarations. //typeof({1}) a; // found } expecting ; //typeof({1}()) b; // same as a typeof(1) c

Re: typeof and block statements

2010-08-12 Thread simendsjo
On 12.08.2010 16:19, Steven Schveighoffer wrote: On Thu, 12 Aug 2010 09:56:07 -0400, simendsjo simen.end...@pandavre.com wrote: On 12.08.2010 15:30, Steven Schveighoffer wrote: On Thu, 12 Aug 2010 09:13:54 -0400, simendsjo simen.end...@pandavre.com wrote: The spec doesn't mention anything

Re: typeof and block statements

2010-08-12 Thread simendsjo
On 12.08.2010 16:39, Steven Schveighoffer wrote: (...) Tested with dmd 2.048 on win7. pragma(msg, module:~typeof({return 1;}()).stringof); void main() { pragma(msg, main:~typeof({return 1;}()).stringof); //typeof({return 1;}()) a; // found 'a' when expecting ';' following statement } prints

Re: [OT] Is this more readable, or just way too verbose?

2010-08-10 Thread simendsjo
Lutger wrote: simendsjo wrote: (...) The CR and LF constants are a bit too much, probably because they don't really abstract over the literals which I can actually parse faster. The isCR and isLF are nice however. Taking it a step further: bool canSplit = inPattern(c,\r\n); if (canSplit

Re: AA invalidating pointers and references..?

2010-08-09 Thread simendsjo
bearophile wrote: simendsjo: I haven't worked much with AA's, but I find the key in aa returns a reference to the value to be handy. I think it's better than the following: int value; if( 1 in a ) value = a[1]; or a[1] in a try/catch or other implementations. Your examples have shown

[OT] Is this more readable, or just way too verbose?

2010-08-09 Thread simendsjo
I took splitlines from std.string, which is a simple, short method. S[] splitlines(S)(S s) { size_t istart; auto result = Appender!(S[])(); foreach (i; 0 .. s.length) { immutable c = s[i]; if (c == '\r' || c == '\n') { result.put(s[istart ..

std.string.chomp error

2010-08-09 Thread simendsjo
The documentation says /*** * Returns s[] sans trailing delimiter[], if any. * If delimiter[] is null, removes trailing CR, LF, or CRLF, if any. */ To adhere to the documentation, chomp must be changed from: C[] chomp(C, C1)(C[] s, in C1[] delimiter) {

Re: std.string.chomp error

2010-08-09 Thread simendsjo
On 09.08.2010 19:16, Lars T. Kyllingstad wrote: On Mon, 09 Aug 2010 18:58:36 +0200, simendsjo wrote: The documentation says /*** * Returns s[] sans trailing delimiter[], if any. * If delimiter[] is null, removes trailing CR, LF, or CRLF, if any

Justify text

2010-08-09 Thread simendsjo
Phobos assumes that you only want to fill with spaces when justifying text. I merged the functions with a user supplied character. Don't think it should be much slower.. Just the switch extra switch if the function is inlined.. (but don't take my word for it :) )? enum Alignment { Right,

Re: std.string.chomp error

2010-08-09 Thread simendsjo
On 09.08.2010 23:58, bearophile wrote: simendsjo: Ok; http://d.puremagic.com/issues/show_bug.cgi?id=4608 You seem to have missed my answer :-) Bye, bearophile No, but I don't know if it's the documentation or implementation that's correct.

Re: Justify text

2010-08-09 Thread simendsjo
On 09.08.2010 23:59, simendsjo wrote: return justify(s, Alignment.Right, width, ' '); Forgot zfill: string zfill(string s, int width) { return justify(s, Alignment.Right, width, '0'); }

Missing test in std.string.replace

2010-08-09 Thread simendsjo
Replacing with / null is missing. I first looked at the function and modified it. Quickly noticed that a few unit tests were missing: assert(replace(foo, foo, ) == ); assert(replace(foo, foo, null) == );

Re: Missing test in std.string.replace

2010-08-09 Thread simendsjo
On 10.08.2010 00:29, simendsjo wrote: Replacing with / null is missing. I first looked at the function and modified it. Quickly noticed that a few unit tests were missing: assert(replace(foo, foo, ) == ); assert(replace(foo, foo, null) == ); I refactored replace to understand what was going

Re: std.string.chomp error

2010-08-09 Thread simendsjo
On 09.08.2010 19:34, bearophile wrote: Lars T. Kyllingstad: Either that, or the documentation for it needs to be changed. Anyway, it would be great if you'd report this. A really basic unit testing is able to catch an error like this. This means Phobos needs more unit tests. Stuff that may

Cannot use local xxx as parameter to non-global template.

2010-08-09 Thread simendsjo
I'm new, so this is most certainly my fault I guess, but I cannot understand the error message... I wish to slice an array and store the slices in a tuple. auto partitionArray(T)(T[] array, int offset, int len) { auto pre = array[0 .. offset]; auto slice = array[offset ..

Re: std.string.chomp error

2010-08-09 Thread simendsjo
On 10.08.2010 02:09, Jonathan M Davis wrote: On Monday, August 09, 2010 16:59:07 bearophile wrote: simendsjo: Ahem.. :) Yes, I did miss your answer! How I got fooled by the preview pane and never noticed the scrollbar. No problem, it happens, don't worry. I cannot see how your other bug

[OT] What is more readable?

2010-08-09 Thread simendsjo
Continuing my what is more readable thread (just shut me up, but I don't always agree with i, j, k etc...): std.string.count: size_t count(string s, string sub) { size_t i; int j; int count = 0; for (i = 0; i s.length; i += j + sub.length) { j = indexOf(s[i ..

More constants in std.string?

2010-08-09 Thread simendsjo
\r and \n is used many times throughout std.string (and probably other modules like file). I assume defining constants were considered: const CR = '\r'; const LF = '\n'; So why isn't constants used instead?

std.string.translate using initializing twice?

2010-08-09 Thread simendsjo
translate does this: bool[256] deltab; // this would make all values of deltab false as bool.init == false, right? deltab[] = false; Isn't this just initializing all values of deltab to false twice..? And my Is this more readable? Original: string translate(string s, in string

Re: [OT] What is more readable?

2010-08-09 Thread simendsjo
On 10.08.2010 02:40, Jonathan M Davis wrote: On Monday, August 09, 2010 17:20:07 simendsjo wrote: Continuing my what is more readable thread (just shut me up, but I don't always agree with i, j, k etc...): Personally, I think that i is just fine in many cases where it's quite clear what

Re: More constants in std.string?

2010-08-09 Thread simendsjo
On 10.08.2010 02:46, Jonathan M Davis wrote: On Monday, August 09, 2010 17:24:47 simendsjo wrote: \r and \n is used many times throughout std.string (and probably other modules like file). I assume defining constants were considered: const CR = '\r'; const LF = '\n'; So why isn't constants

Re: std.string.chomp error

2010-08-09 Thread simendsjo
On 10.08.2010 03:08, bearophile wrote: Jonathan M Davis: Why, because it should be if(delimiter is null) or just if(!delimiter) if (delimiter.length == 0) Or if (!delimiter.length) Bye, bearophile Isn't that very different things? You cannot use .length if delimiter is null.

AA invalidating pointers and references..?

2010-08-08 Thread simendsjo
unittest { auto a = [1:2]; auto p = 1 in a; // can p be invalidated by rehashing? // That is pointing to a different item or a memory location used for other things? auto b = a.rehash; // The spec also says it orders in place, but returns the

Re: AA invalidating pointers and references..?

2010-08-08 Thread simendsjo
On 08.08.2010 17:51, bearophile wrote: simendsjo: auto a = [1:2]; auto p = 1 in a; // can p be invalidated by rehashing? Yes, I presume it can. p is meant for immediate consumption only. // The spec also says it orders in place, but returns the reorganized

Re: Array Operations and type inference

2010-08-08 Thread simendsjo
On 07.08.2010 14:10, simendsjo wrote: I'm new to D2, so please.. :) (...) Thanks for all answers. Seems array operations is a bit buggy, so I'll rather look more into them at a later date.

Re: Slicing to convert pointers to bound arrays

2010-08-08 Thread simendsjo
On 07.08.2010 16:48, bearophile wrote: simendsjo: When I do the same with a static array, I get 0. But this is just actually garbage, right? It might contain other data, and not always 0? Generally it contains garbage. In string literals there is one more item that's empty (zero). I don't

Re: Static arrays passed by value..?

2010-08-08 Thread simendsjo
On 08.08.2010 01:52, BCS wrote: What that is saying is that if the type of the function arg is a static array... not if the value passed to the function is a static array... Yes, it would help to read the spec a bit closer :)

What on earth is a ref function?

2010-08-08 Thread simendsjo
The spec is very short here, and the example doesn't give me much.. // I thought allows functinos to return by reference meant it could return local variables.. ref int* ptr() { auto p = new int; *p = 12; return p; // Error: escaping local variable } // So whats the

Where is function parameter storage classes documented?

2010-08-08 Thread simendsjo
There is very little documentation in the function documentation and none in declaration. Or am I just a little blind?

Array Operations and type inference

2010-08-07 Thread simendsjo
I'm new to D2, so please.. :) The spec on Array Operations, http://www.digitalmars.com/d/2./arrays.html says: A vector operation is indicated by the slice operator appearing as the lvalue of an =, +=, -=, *=, /=, %=, ^=, = or |= operator. The following tests works fine as I expected:

Slicing to convert pointers to bound arrays

2010-08-07 Thread simendsjo
I understand this is an unsafe operation, I just have a quick question. Here, b points outside a's memory, so I get garbage. { int[] a = [3,3,3]; auto p = a.ptr; auto b = p[0..3]; assert(b == [3,3,3]); b =

Is is the same as ptr == ptr for arrays?

2010-08-07 Thread simendsjo
Is the following equalent? int[] a; int[] b = a; assert(a is b); assert(a.ptr == b.ptr);

Re: Is is the same as ptr == ptr for arrays?

2010-08-07 Thread simendsjo
On 07.08.2010 18:04, Peter Alexander wrote: On 7/08/10 4:33 PM, simendsjo wrote: Is the following equalent? int[] a; int[] b = a; assert(a is b); assert(a.ptr == b.ptr); No. (a is b) implies (a.ptr == b.ptr) but (a.ptr == b.ptr) does not imply (a is b) For example: int[] a = [1, 2, 3

Static arrays passed by value..?

2010-08-07 Thread simendsjo
The spec for array says: Static arrays are value types. Unlike in C and D version 1, static arrays are passed to functions by value. Static arrays can also be returned by functions. I don't get the static arrays are passed to functions by value part. Here I am passing in a static and

Isn't __traits part of the language?

2010-08-06 Thread simendsjo
Rationale (http://digitalmars.com/d/2.0/rationale.html) says: Why not use operator names like __add__ and __div__ instead of opAdd, opDiv, etc.? __ keywords should indicate a proprietary language extension, not a basic part of the language. But traits is explained under the language spec,

Is it bad practice to alter dynamic arrays that have references to them?

2010-08-05 Thread simendsjo
Just tell me if this is frowned upon... The reason I posted on SO is because I think it can help making people aware of D. http://stackoverflow.com/questions/3416657/is-it-bad-practice-to-alter-dynamic-arrays-that-have-references-to-them Let me know if it's not accepted to crosspost like this.

Re: Is it bad practice to alter dynamic arrays that have references to them?

2010-08-05 Thread simendsjo
On 05.08.2010 19:35, Steven Schveighoffer wrote: On Thu, 05 Aug 2010 13:10:44 -0400, simendsjo simen.end...@pandavre.com wrote: (...) One helpful function to note is the capacity function: http://digitalmars.com/d/2.0/phobos/object.html#capacity This gives you the capacity of the array

Re: Is it bad practice to alter dynamic arrays that have references to them?

2010-08-05 Thread simendsjo
On 05.08.2010 20:50, Steven Schveighoffer wrote: On Thu, 05 Aug 2010 14:41:12 -0400, simendsjo simen.end...@pandavre.com wrote: On 05.08.2010 19:35, Steven Schveighoffer wrote: On Thu, 05 Aug 2010 13:10:44 -0400, simendsjo simen.end...@pandavre.com wrote: (...) (...) Ah, that's really

<    1   2   3   4   5   6