Re: How do you do a typeid(obj) to get the most derived class that it is, or string?
On 02/01/2016 10:20 PM, Enjoys Math wrote: class A { } class B : A { } class C : B { } auto b = new B(); typeid(b) == "B" ? Thanks. class A { } class B : A { } class C : B { } void main() { auto b = new B(); assert(typeid(b) == typeid(B)); // Or, if you have the type without an object (e.g. in templated code) assert(typeid(typeof(b)) == typeid(B)); } Ali
How do you do a typeid(obj) to get the most derived class that it is, or string?
class A { } class B : A { } class C : B { } auto b = new B(); typeid(b) == "B" ? Thanks.
Re: Determine type of property
On Tuesday, 2 February 2016 at 03:36:25 UTC, Steven Schveighoffer wrote: S has 3 different properties, x, y, z: struct S { int x; int y() { return 1;} } int z(S s) { return 1;} pragma(msg, typeof(S.init.x).stringof); // int pragma(msg, typeof(S.init.y).stringof); // int() pragma(msg, typeof(S.init.z).stringof); // int Is there a trait I can call/use to consistently get "int" from all 3? -Steve import std.traits, std.stdio; alias PropertyType(T, string property) = ReturnType!(function(T x) { return mixin("x." ~ property); }); struct S { int x; int y() { return 1;} } int z(S s) { return 1;} void main() { writeln(PropertyType!(S, "x").stringof); writeln(PropertyType!(S, "y").stringof); writeln(PropertyType!(S, "z").stringof); } (DPaste: http://dpaste.dzfl.pl/0b03bc8ea11f)
Re: how do I tell if something is lvalue?
On Monday, 1 February 2016 at 22:32:26 UTC, Steven Schveighoffer wrote: What I wanted essentially was a template constraint that says "this type has a member named foo, and t.foo is an lvalue" -Steve Like this? template hasLValProperty(T, string property) { enum hasLValProperty = __traits(compiles, function(ref T x) { void requireLVal(V)(ref V y) { } requireLVal(mixin("x." ~ property)); }); } struct Foo { int a; } struct Bar { int b() { return 0; } } struct Baz { ref int c() { static int _c; return _c; } } void test(T, string property)() { import std.stdio; write(T.stringof, ".", property, " is "); if(!hasLValProperty!(T, property)) write("NOT "); writeln("an lvalue"); } void main() { import std.stdio; test!(Foo, "a")(); test!(Foo, "b")(); test!(Bar, "a")(); test!(Bar, "b")(); test!(Baz, "c")(); } (DPaste: http://dpaste.dzfl.pl/5877cc17ffd2)
Re: D with DerelictASSIMP3 question
On Tuesday, 2 February 2016 at 03:22:16 UTC, Maeriden wrote: Try aiGetMaterialTextureCount. I'm guessing derelict uses the C API as much as it can. It uses the C API exclusively.
Determine type of property
S has 3 different properties, x, y, z: struct S { int x; int y() { return 1;} } int z(S s) { return 1;} pragma(msg, typeof(S.init.x).stringof); // int pragma(msg, typeof(S.init.y).stringof); // int() pragma(msg, typeof(S.init.z).stringof); // int Is there a trait I can call/use to consistently get "int" from all 3? -Steve
Re: D with DerelictASSIMP3 question
On Tuesday, 2 February 2016 at 02:57:14 UTC, WhatMeWorry wrote: I'm porting a C++/opengl/AssImp tutorial over to D/DerelictOpenGL/DerelictAssImp but have hit a brick wall. [...] Try aiGetMaterialTextureCount. I'm guessing derelict uses the C API as much as it can.
D with DerelictASSIMP3 question
I'm porting a C++/opengl/AssImp tutorial over to D/DerelictOpenGL/DerelictAssImp but have hit a brick wall. It's a fairly large project but a tiny fragment suffices: if(mesh.mMaterialIndex >= 0) { const aiMaterial* material = scene.mMaterials[mesh.mMaterialIndex]; // uint texCount = material.GetTextureCount(aiTextureType_SPECULAR); Everything compiles fine. But when I uncomment the call to GetTextureCount(), the Visual Studio D compiler comes back with: ModelClass.d(165): Error: no property 'GetTextureCount' for type 'const(aiMaterial*)' I looked at AssImp documentation at http://assimp.sourceforge.net/lib_html/structai_material.html And it shows unsigned intGetTextureCount (aiTextureType type) const Get the number of textures for a particular texture type. So it seems like such a simple error, but I've been stuck for days. Any suggestions?
Re: How do you get system time in specified precision?
On 2/1/16 8:17 PM, Enjoys Math wrote: That is in metric system units? Ie milli-, micro-, hectanano-, nano-seconds? Those are available from SysTime.fracSecs. Is that what you are looking for? If not, please be more specific. time has a lot of different meanings. -Steve
How do you get system time in specified precision?
That is in metric system units? Ie milli-, micro-, hectanano-, nano-seconds? The documentation doesn't show this well and many things are deprecated. Please show me how! Thank you.
Re: Region allocator strage error
On Monday, 1 February 2016 at 12:05:53 UTC, ref2401 wrote: On Sunday, 31 January 2016 at 14:48:34 UTC, ref2401 wrote: I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure At least tell me can anyone replicate it? https://issues.dlang.org/show_bug.cgi?id=15637 (Sorry for the *triple* post).
Re: how do I tell if something is lvalue?
On 2/1/16 5:20 PM, tsbockman wrote: On Sunday, 31 January 2016 at 22:11:45 UTC, Steven Schveighoffer wrote: Thanks! I was surprised this is not straightforward. -Steve For function return values, at least, you can do this: import std.traits, std.stdio; int foo() { return 0; } ref int bar() { static int x = 0; return x; } enum isRetByRef(alias func) = (functionAttributes!func & FunctionAttribute.ref_) != 0; void main() { writeln("foo: ", isRetByRef!foo); writeln("bar: ", isRetByRef!bar); } (DPaste: http://dpaste.dzfl.pl/2aa8d3553a12) Thanks. In my case, I need to treat fields and properties that return by ref the same way. What I wanted essentially was a template constraint that says "this type has a member named foo, and t.foo is an lvalue" -Steve
Re: how do I tell if something is lvalue?
On Sunday, 31 January 2016 at 22:11:45 UTC, Steven Schveighoffer wrote: Thanks! I was surprised this is not straightforward. -Steve For function return values, at least, you can do this: import std.traits, std.stdio; int foo() { return 0; } ref int bar() { static int x = 0; return x; } enum isRetByRef(alias func) = (functionAttributes!func & FunctionAttribute.ref_) != 0; void main() { writeln("foo: ", isRetByRef!foo); writeln("bar: ", isRetByRef!bar); } (DPaste: http://dpaste.dzfl.pl/2aa8d3553a12)
Re: how do I tell if something is lvalue?
On Monday, 1 February 2016 at 20:53:35 UTC, Artur Skawina wrote: On 02/01/16 21:42, Artur Skawina wrote: On 02/01/16 20:47, Meta via Digitalmars-d-learn wrote: That looks much nicer. It still needs work to properly handle functions with non-empty argument lists. Then it gets a bit long for a one-liner ;) enum isLvalue(A...) = is(typeof((ref _){}(A[0](A[1..$] || is(typeof((ref _){}(A[0]))); And it's of course wrong in case there is a zero-args ref-returning overload present. So... enum isLvalue(A...) = A.length>1?is(typeof((ref _){}(A[0](A[1..$]:is(typeof((ref _){}(A[0]))); artur Hmm, I think it can be simplified by replacing `A[0](A[1..$])` with `A(Parameters!A.init)`. Then the whole thing becomes: enum isLvalue(alias A) = is(typeof((ref _) {} (A(Parameters!A.init; *However*, we then run into this problem: int n; ref int returnN(int, float, bool) { return n; } ref int returnN() { return n; } static assert(isLvalue!returnN); If I remember correctly this will just check the first returnN declaration.
Re: Region allocator strage error
On Monday, 1 February 2016 at 19:55:26 UTC, mark_mcs wrote: On Monday, 1 February 2016 at 12:05:53 UTC, ref2401 wrote: On Sunday, 31 January 2016 at 14:48:34 UTC, ref2401 wrote: I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure At least tell me can anyone replicate it? Reproduced on Windows 7 Pro x64 and Windows 10 Pro x64, DMD 2.070 and 2.069.2. I don't have any 32-bit machines to test. I'll try and debug later. This should fail on 64-bit Linux builds. import std.experimental.allocator; import std.experimental.allocator.building_blocks; void main(string[] args) { ubyte[1024] memory; auto alloc = Region!NullAllocator(memory); auto result = alloc.allocate(20); alloc.expand(result, 20); }
Re: How would you implement this in D? (signals & slots)
On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote: module signals_and_slots; import std.algorithm: remove; [...] D's signals & slots: https://dlang.org/phobos/std_signals.html
How would you implement this in D? (signals & slots)
module signals_and_slots; import std.algorithm: remove; struct Slots(DelegateType, ArgTypes...) { this() { } // How would you implement this? void call(ArgTypes args) { foreach (dg; delegates) dg(args); } void connect(DelegateType slot) { foreach (dg; delegates) { if (dg == slot) return; } delegates ~= slot; } void disconnect(DelegateType slot) { for (uint k=0; k < delegates.length; k++) { if (delegates[k] == slot) delegates = delegates.remove(k); } } private: DelegateType[] delegates; } = How do you implement this template called like: void onColorChange(in Color) { // do something with color } auto slots = Slots!(void delegate(in Color), Color); slots.connect(&onColorChange); auto color = Color(0.0, 1.0, 1.0, 1.0); slots.call(color); ? Thank you!
Re: how do I tell if something is lvalue?
On 02/01/16 21:42, Artur Skawina wrote: > On 02/01/16 20:47, Meta via Digitalmars-d-learn wrote: >> That looks much nicer. It still needs work to properly handle functions with >> non-empty argument lists. > > Then it gets a bit long for a one-liner ;) > >enum isLvalue(A...) = is(typeof((ref _){}(A[0](A[1..$] || > is(typeof((ref _){}(A[0]))); And it's of course wrong in case there is a zero-args ref-returning overload present. So... enum isLvalue(A...) = A.length>1?is(typeof((ref _){}(A[0](A[1..$]:is(typeof((ref _){}(A[0]))); artur
Re: how do I tell if something is lvalue?
On 02/01/16 20:47, Meta via Digitalmars-d-learn wrote: > On Monday, 1 February 2016 at 18:28:05 UTC, Artur Skawina wrote: >> On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: >>> Thanks! I was surprised this is not straightforward. >> >>enum isLvalue(alias A) = is(typeof((ref _){}(A))); > > That looks much nicer. It still needs work to properly handle functions with > non-empty argument lists. Then it gets a bit long for a one-liner ;) enum isLvalue(A...) = is(typeof((ref _){}(A[0](A[1..$] || is(typeof((ref _){}(A[0]))); > Also, can alias parameters take runtime variables? I can't remember. Yes. > > struct S > { > int w(int n) { return 1; } ref int wl(int n) { return x; } > } > > static assert(isLvalue!(S.w)); static assert(!isLvalue!(S.w, 1)); static assert(isLvalue!(S.wl, 1)); artur
Containers with non copyable types
For example it is no problem in C++ to have std::vector> vuf; But how can this be expressed in D? For example Array!(Unique!int) ua; doesn't compile because it requires this(this) which is obviously disabled for "Unique".
Re: chain(const(array of class)) fails
Sorry for late reply -- but I got around to test a couple more cases! On Monday, 1 February 2016 at 00:19:44 UTC, Nicholas Wilson wrote: Unqaul means remove any const or immutable torn the type Okay, that sounds like our 'const' shouldn't matter. 'const' is the outermost qualifier, and stripping that leaves us with B[] and C[], which were chainable earlier. StaticMap is like a compile time map What this error message says is that there is one candidate function that matches what you are attempting to do. and that chain takes a variadic argument and each of those arguments must 1) when unqualified be an input range (Basically you can foreach over it) Yep, const(B[]) and const(C[]) can be foreached. My workaround has been to replace chain() with several foreaches. 2) that the common type of the element type of the unqualified variadic argument types is not void (in this case not arrays of void) Have you tried changing The declaration of a and b to const(A[])? Surprisingly, this compiles and gives the desired output: const(B[]) b = [ new B(), new B() ]; const(A[]) c = [ new C(), new C() ]; // A instead of C chain(b, c).each!(a => a.val.writeln); With two arguments, const(array) has worked iff at least one range is of the base type. Only if none were of the base type, I got the error. Apparently, the template is smart enough to infer the common base type without 'const', but needs to be fed the basetype in case of 'const'. My gut feeling is that I should report this as a bug against phobos... Also have you tried with other reference type (e.g. assoc arrays pointers)? immutable(B[int]) b; immutable(C[int]) c; chain(b.byValue, c.byValue).each!(a => a.val.writeln); Error is the same as for the classes: template std.range.chain cannot deduce function from argument types !()(Result, Result), candidates are: /* snip */ To get this error, again, if at least one range is 'immutable(A[int]).byValue', i.e., using the base class A, the template instantiates with no problems. -- Simon
Re: how do I tell if something is lvalue?
On 2/1/16 2:47 PM, Meta wrote: On Monday, 1 February 2016 at 18:28:05 UTC, Artur Skawina wrote: On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: Thanks! I was surprised this is not straightforward. enum isLvalue(alias A) = is(typeof((ref _){}(A))); artur That looks much nicer. It still needs work to properly handle functions with non-empty argument lists. Also, can alias parameters take runtime variables? I can't remember. struct S { int w(int n) { return 1; } } static assert(isLvalue!(S.w)); Nice for the general case, but in my case, I don't need to worry about parameters. Thanks! -Steve
Re: Region allocator strage error
On Monday, 1 February 2016 at 12:05:53 UTC, ref2401 wrote: On Sunday, 31 January 2016 at 14:48:34 UTC, ref2401 wrote: I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure At least tell me can anyone replicate it? Reproduced on Windows 7 Pro x64 and Windows 10 Pro x64, DMD 2.070 and 2.069.2. I don't have any 32-bit machines to test. I'll try and debug later.
Re: how do I tell if something is lvalue?
On Monday, 1 February 2016 at 18:28:05 UTC, Artur Skawina wrote: On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: Thanks! I was surprised this is not straightforward. enum isLvalue(alias A) = is(typeof((ref _){}(A))); artur That looks much nicer. It still needs work to properly handle functions with non-empty argument lists. Also, can alias parameters take runtime variables? I can't remember. struct S { int w(int n) { return 1; } } static assert(isLvalue!(S.w));
Re: Octree implementation?
On Monday, 1 February 2016 at 02:56:06 UTC, Tofu Ninja wrote: Just out of curiosity, does anyone have an octree implementation for D laying around? Just looking to save some time. https://github.com/Ingrater/thBase/blob/master/src/thBase/container/octree.d Its a loose octree implementation. That means the cells overlap a bit to accomondate for the problem of objects that are on the border between to cells. I don't know though if you can rip out the implementation without some modifications. Kind Regards Benjamin Thaut
Re: how do I tell if something is lvalue?
On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: > Thanks! I was surprised this is not straightforward. enum isLvalue(alias A) = is(typeof((ref _){}(A))); artur
Re: how do I tell if something is lvalue?
On 1/31/16 5:12 PM, Meta wrote: On Sunday, 31 January 2016 at 22:11:45 UTC, Steven Schveighoffer wrote: On 1/31/16 4:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There's probably a simpler way but this is the first thing I could come up with that works. Thanks! I was surprised this is not straightforward. It seems to me like it would be a useful addition to __traits. Yeah, the compiler probably has this handy. https://issues.dlang.org/show_bug.cgi?id=15634 -Steve
Re: Region allocator strage error
On Monday, 1 February 2016 at 12:05:53 UTC, ref2401 wrote: On Sunday, 31 January 2016 at 14:48:34 UTC, ref2401 wrote: I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure At least tell me can anyone replicate it? Missing imports for c&p: import std.experimental.allocator; import std.experimental.allocator.building_blocks; I can't reproduce it on Linux x86_64, neither with latest DMD from git, nor DMD 2.070.0. It's the following assert, maybe it helps finding the cause: https://github.com/D-Programming-Language/phobos/blob/master/std/experimental/allocator/building_blocks/region.d#L235
Re: How to set array length for multidimensional static arrays
On Monday, February 01, 2016 13:22:23 Daniel Kozak via Digitalmars-d-learn wrote: > V Mon, 01 Feb 2016 12:19:10 + > Namal via Digitalmars-d-learn > napsáno: > > > On Monday, 1 February 2016 at 12:12:00 UTC, Jonathan M Davis > > wrote: > > > On Monday, February 01, 2016 11:15:40 Namal via > > > Digitalmars-d-learn wrote: > > >> Sorry guys that I didn't express myself well. I also mixed > > >> some stuff up. What I wanted to ask is this, in c++ this is > > >> valid > > >> > > >> int x = 3; > > >> int y = 10; > > >> int arr [x][y]; > > >> > > >> x,y are known at the compile time and arr is a static array. I > > >> can't do that in D so what is the best way to declare an array > > >> of that size? > > > > > > If x and y are known at compile time, then you can declare a > > > static array using them for dimensions. e.g. > > > > > > enum x = 3; > > > enum y = 10; > > > int[y][x] arr; > > > > > > But x and y must be something that it is evaluated by the > > > compiler at compile time - e.g. an enum or a static variable. A > > > local variable that just so happens to be directly initialized > > > (like in your example) won't work. > > > > > > If x and y are _not_ known at compile time, then you can't use > > > the to declare a static array. You'll have to use a dynamic > > > array. e.g. > > > > > > auto arr = new int[][](x, y); > > > > > > - Jonathan M Davis > > > > Thanks alot, I didn't know that way with new. > > you can use this too: > auto arr = new int[y][x]; True, but that's not the same thing. It creates a dynamic array of static arrays instead of a static array of dynamic arrays. e.g. auto a = new int[][](5, 10); auto b = new int[5][10]; auto c = new int[5][](10); writeln(typeof(a).stringof); writeln(typeof(b).stringof); writeln(typeof(c).stringof); prints int[][] int[5][] int[5][] And in the cases where the inner element is a static array, its length has to be known compile time, whereas the lengths of the dynamic arrays don't. On a side note, I really wish that putting the size inside of the brackets was illegal for dynamic arrays to make what's going on clearer, but instead, the outer layer can go either in the brackets or in the parens, whereas where the other layers go changes them between dynamic arrays and static arrays. - Jonathan M Davis
Re: How to set array length for multidimensional static arrays
V Mon, 01 Feb 2016 12:19:10 + Namal via Digitalmars-d-learn napsáno: > On Monday, 1 February 2016 at 12:12:00 UTC, Jonathan M Davis > wrote: > > On Monday, February 01, 2016 11:15:40 Namal via > > Digitalmars-d-learn wrote: > >> Sorry guys that I didn't express myself well. I also mixed > >> some stuff up. What I wanted to ask is this, in c++ this is > >> valid > >> > >> int x = 3; > >> int y = 10; > >> int arr [x][y]; > >> > >> x,y are known at the compile time and arr is a static array. I > >> can't do that in D so what is the best way to declare an array > >> of that size? > > > > If x and y are known at compile time, then you can declare a > > static array using them for dimensions. e.g. > > > > enum x = 3; > > enum y = 10; > > int[y][x] arr; > > > > But x and y must be something that it is evaluated by the > > compiler at compile time - e.g. an enum or a static variable. A > > local variable that just so happens to be directly initialized > > (like in your example) won't work. > > > > If x and y are _not_ known at compile time, then you can't use > > the to declare a static array. You'll have to use a dynamic > > array. e.g. > > > > auto arr = new int[][](x, y); > > > > - Jonathan M Davis > > Thanks alot, I didn't know that way with new. you can use this too: auto arr = new int[y][x];
Re: How to set array length for multidimensional static arrays
On Monday, 1 February 2016 at 12:12:00 UTC, Jonathan M Davis wrote: On Monday, February 01, 2016 11:15:40 Namal via Digitalmars-d-learn wrote: Sorry guys that I didn't express myself well. I also mixed some stuff up. What I wanted to ask is this, in c++ this is valid int x = 3; int y = 10; int arr [x][y]; x,y are known at the compile time and arr is a static array. I can't do that in D so what is the best way to declare an array of that size? If x and y are known at compile time, then you can declare a static array using them for dimensions. e.g. enum x = 3; enum y = 10; int[y][x] arr; But x and y must be something that it is evaluated by the compiler at compile time - e.g. an enum or a static variable. A local variable that just so happens to be directly initialized (like in your example) won't work. If x and y are _not_ known at compile time, then you can't use the to declare a static array. You'll have to use a dynamic array. e.g. auto arr = new int[][](x, y); - Jonathan M Davis Thanks alot, I didn't know that way with new.
Re: How to set array length for multidimensional static arrays
On Monday, February 01, 2016 11:15:40 Namal via Digitalmars-d-learn wrote: > Sorry guys that I didn't express myself well. I also mixed some > stuff up. What I wanted to ask is this, in c++ this is valid > > int x = 3; > int y = 10; > int arr [x][y]; > > x,y are known at the compile time and arr is a static array. I > can't do that in D so what is the best way to declare an array of > that size? If x and y are known at compile time, then you can declare a static array using them for dimensions. e.g. enum x = 3; enum y = 10; int[y][x] arr; But x and y must be something that it is evaluated by the compiler at compile time - e.g. an enum or a static variable. A local variable that just so happens to be directly initialized (like in your example) won't work. If x and y are _not_ known at compile time, then you can't use the to declare a static array. You'll have to use a dynamic array. e.g. auto arr = new int[][](x, y); - Jonathan M Davis
Re: Region allocator strage error
On Sunday, 31 January 2016 at 14:48:34 UTC, ref2401 wrote: I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure At least tell me can anyone replicate it?
Re: How to set array length for multidimensional static arrays
V Mon, 01 Feb 2016 11:15:40 + Namal via Digitalmars-d-learn napsáno: > Sorry guys that I didn't express myself well. I also mixed some > stuff up. What I wanted to ask is this, in c++ this is valid > > int x = 3; > int y = 10; > int arr [x][y]; > > x,y are known at the compile time and arr is a static array. I > can't do that in D so what is the best way to declare an array of > that size? You can do that: immutable x = 3; immutable y = 10; int[y][x] arr;
Re: How to set array length for multidimensional static arrays
Sorry guys that I didn't express myself well. I also mixed some stuff up. What I wanted to ask is this, in c++ this is valid int x = 3; int y = 10; int arr [x][y]; x,y are known at the compile time and arr is a static array. I can't do that in D so what is the best way to declare an array of that size?
Re: How to set array length for multidimensional static arrays
On Monday, February 01, 2016 07:42:56 Namal via Digitalmars-d-learn wrote: > On Monday, 1 February 2016 at 07:41:33 UTC, Namal wrote: > > I understand that I cannot pass a variable to the static array > > like in C++, and have to use dynamic arrays. But how can I set > > the length for them without using a loop? > > I mean std::vector in C++, not array. I'm not sure what you're trying to do exactly. static arrays cannot be resized. They're a fixed size that's known at compile time. And they're nothing like std::vector at all. e.g. int[42] arr; That array has 42 elements and will always have 42 elements. And you can't do something like int[x] arr; unless x is known at compile time (e.g. it's an enum). Now, if you want something like std::vector, what you're probably looking for is either dynamic arrays or std.container.Array. And dynamic arrays can be allocated pretty much just like you'd do an array in C++ or Java. e.g. auto arr = new int[](42); Or you can set its length directly. e.g. arr.length = 42; If the new length is shorter than the current length, then it would be identical to slicing the array and reassigning it to the original. e.g. arr = arr[0 .. 42]; And if the new length is longer, then each of the new elements is set to the init value of the of the element type. Or you can append elements with ~=, which would be like using push_back. e.g. arr ~= 12; And if you want to reserve a particular capacity for the dynamic array like you might do with std::vector, then just use reserve. e.g. arr.reserve(42); If you haven't yet, you really should read this article: http://dlang.org/d-array-article.html It really should help you understand dynamic arrays in D. However, be warned that its terminology is a bit off. It uses the term dynamic array for the GC-managed block of memory that a typical dynamic array refers to (per the language spec, T[] is a dynamic array regardless of what kind of memory it refers to, and a GC-managed block of memory has no official term). Similarly, it uses the term slice for T[] rather than dynamic array, and while a non-null dynamic array is a slice of memory of some kind, the term slice is used for a lot more in D than just arrays. Still, while its terminology is a bit wrong, the article is very good and really a must read for anyone who wants to understand dynamic arrays in D. - Jonathan M Davis
Re: C Macro deeper meaning?
On Sunday, 31 January 2016 at 02:58:28 UTC, Andrew Edwards wrote: void notUsed(T)(T v) { return cast(void)0; }; since it always returns cast(void)0 regardless of the input. But it cannot be that simple, so what am I missing? Now notUsed has an unused parameter v.