digitalmars.D - overlapping slices
- B.G. (4/4) Apr 28 2005 a[3 .. 20] = a[4 .. 21]; is prohibited,
- Walter (5/9) Apr 28 2005 compiler,
- B.G. (6/16) Apr 29 2005 Do you mean casting array ref to a pointer and give it to memmove?
- Walter (7/25) Apr 29 2005 it
- B. (3/29) May 02 2005 I bag a pardon, what's DMC?
- B.G. (3/29) May 02 2005 I bag a pardon, what's DMC?
- Derek Parnell (7/43) May 02 2005 DMC == Digital Mars C++ Compiler.
- B.G. (14/57) May 02 2005 Oops! Sorry, Walter ;-))))
- Andrew Fedoniouk (252/259) Apr 28 2005 Instead of
- B.G. (30/292) Apr 28 2005 The question was actually indeed about Vector-like templates, :)
- Andrew Fedoniouk (10/42) Apr 28 2005 The same mechanism as with e,g, two declarations
- David L. Davis (451/457) Jul 31 2005 ..
- Holger (5/468) Jul 31 2005 Seems very useful indeed. Thanks for bringing this to public
a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done by compiler, but the above situation is frequent enought, so is there any way to do it other than a loop?
Apr 28 2005
"B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done bycompiler,but the above situation is frequent enought, so is there any way to do itotherthan a loop?You can use C's memmove().
Apr 28 2005
In article <d4r5it$19b5$1 digitaldaemon.com>, Walter says..."B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...Do you mean casting array ref to a pointer and give it to memmove? Is it safe to move object references this way? There are some posts about moveable memory in future gc implementations, etc, that's actually the reason for my concerns with this issue. thanxa[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done bycompiler,but the above situation is frequent enought, so is there any way to do itotherthan a loop?You can use C's memmove().
Apr 29 2005
"B.G." <B.G._member pathlink.com> wrote in message news:d4tb6a$pj0$1 digitaldaemon.com...In article <d4r5it$19b5$1 digitaldaemon.com>, Walter says...it"B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done bycompiler,but the above situation is frequent enought, so is there any way to doYes.otherDo you mean casting array ref to a pointer and give it to memmove?than a loop?You can use C's memmove().Is it safe to move object references this way? There are some posts about moveable memory in future gc implementations,etc,that's actually the reason for my concerns with this issue.It's safe if the implementation of memmove() will move pointer sized chunks at a time. DMC's will, but there's no guarantee others will.
Apr 29 2005
In article <d4ukpk$20s2$1 digitaldaemon.com>, Walter says..."B.G." <B.G._member pathlink.com> wrote in message news:d4tb6a$pj0$1 digitaldaemon.com...I bag a pardon, what's DMC? thanx.In article <d4r5it$19b5$1 digitaldaemon.com>, Walter says...it"B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done bycompiler,but the above situation is frequent enought, so is there any way to doYes.otherDo you mean casting array ref to a pointer and give it to memmove?than a loop?You can use C's memmove().Is it safe to move object references this way? There are some posts about moveable memory in future gc implementations,etc,that's actually the reason for my concerns with this issue.It's safe if the implementation of memmove() will move pointer sized chunks at a time. DMC's will, but there's no guarantee others will.
May 02 2005
In article <d4ukpk$20s2$1 digitaldaemon.com>, Walter says..."B.G." <B.G._member pathlink.com> wrote in message news:d4tb6a$pj0$1 digitaldaemon.com...I bag a pardon, what's DMC? thanx.In article <d4r5it$19b5$1 digitaldaemon.com>, Walter says...it"B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done bycompiler,but the above situation is frequent enought, so is there any way to doYes.otherDo you mean casting array ref to a pointer and give it to memmove?than a loop?You can use C's memmove().Is it safe to move object references this way? There are some posts about moveable memory in future gc implementations,etc,that's actually the reason for my concerns with this issue.It's safe if the implementation of memmove() will move pointer sized chunks at a time. DMC's will, but there's no guarantee others will.
May 02 2005
On Mon, 2 May 2005 22:29:03 +0000 (UTC), B.G. wrote:In article <d4ukpk$20s2$1 digitaldaemon.com>, Walter says...DMC == Digital Mars C++ Compiler. http://www.digitalmars.com -- Derek Melbourne, Australia 3/05/2005 9:21:11 AM"B.G." <B.G._member pathlink.com> wrote in message news:d4tb6a$pj0$1 digitaldaemon.com...I bag a pardon, what's DMC? thanx.In article <d4r5it$19b5$1 digitaldaemon.com>, Walter says...it"B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done bycompiler,but the above situation is frequent enought, so is there any way to doYes.otherDo you mean casting array ref to a pointer and give it to memmove?than a loop?You can use C's memmove().Is it safe to move object references this way? There are some posts about moveable memory in future gc implementations,etc,that's actually the reason for my concerns with this issue.It's safe if the implementation of memmove() will move pointer sized chunks at a time. DMC's will, but there's no guarantee others will.
May 02 2005
In article <1hqz8n1ubnxtt$.xm7d74d5jvd5$.dlg 40tude.net>, Derek Parnell says...On Mon, 2 May 2005 22:29:03 +0000 (UTC), B.G. wrote:Oops! Sorry, Walter ;-)))) The forum's most stupid question since ages, probably. Well, digitalmars means only D to me... Seriously - OK, so memmove is not entirely 'nice' solution... I just thought, it would be NOT BAD, to have a single approved cross-platform function for that purpose, with correct implementation everywhere. IMHO it would be more natural to have it in the language core (it's in fact just a special case of slicing, at least from the programmer's point of view), I just don't have an idea how to plug it into the language in an elegant way. Maybe as a further array property? something like arr.overlap(srcIndex, destIndex, length) or whatever...In article <d4ukpk$20s2$1 digitaldaemon.com>, Walter says...DMC == Digital Mars C++ Compiler. http://www.digitalmars.com"B.G." <B.G._member pathlink.com> wrote in message news:d4tb6a$pj0$1 digitaldaemon.com...I bag a pardon, what's DMC? thanx.In article <d4r5it$19b5$1 digitaldaemon.com>, Walter says...it"B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done bycompiler,but the above situation is frequent enought, so is there any way to doYes.otherDo you mean casting array ref to a pointer and give it to memmove?than a loop?You can use C's memmove().Is it safe to move object references this way? There are some posts about moveable memory in future gc implementations,etc,that's actually the reason for my concerns with this issue.It's safe if the implementation of memmove() will move pointer sized chunks at a time. DMC's will, but there's no guarantee others will.-- Derek Melbourne, Australia 3/05/2005 9:21:11 AM
May 02 2005
Instead of a[3 .. 20] = a[4 .. 21]; a[3] = something; you may use just a.ins( 3, something ); if you will include following somewhere: //| //| std D array extenders, these should be intrinsic ops for arrays in ideal D //| template xarrayT(T) { // append array by one element void push(inout T[] elements, T v) { int l = elements.length; elements.length = l + 1; elements[l] = v; } // del last element and return it T pop(inout T[] elements) { int l = elements.length - 1; assert(l >= 0); T t = elements[l]; elements.length = l; return t; } // insert element into array void ins(inout T[] elements, uint at, T v) { uint l = elements.length; if(at >= l) { elements ~= v; return; } // for some reasons this does not compile: // elements = elements[0..at] ~ v ~ elements[at..elements.length]; // so we use C way: elements.length = l + 1; memmove(&elements[at+1],&elements[at],(l-at)*T.sizeof); elements[at] = v; } // insert array into array void insr(inout T[] elements, uint at, T[] va ) { uint l = elements.length; if(at >= l) { elements ~= va; return; } elements.length = l + va.length; memmove(&elements[at + va.length],&elements[at],(l-at)*T.sizeof); elements[at..at+va.length] = va; } // del element and return it T cut(inout T[] elements, uint at) { uint l = elements.length - 1; if(at >= l) return pop(elements); T t = elements[at]; memmove(&elements[at],&elements[at+1],(l-at)*T.sizeof); elements.length = l; return t; } // del range and return its content T[] cutr(inout T[] elements, uint at, uint end) { assert(at <= end); if(at == end) return null; T[] t = elements[at..end].dup; uint l = elements.length - (end - at); if(at < l) { elements.length = at; return t; } memmove(&elements[at],&elements[end],(l-at)*T.sizeof); elements.length = l; return t; } // just del range void del(inout T[] elements, int at, int end) { assert(at <= end); if(at == end) return; uint l = elements.length - (end - at); if(at >= l) { elements.length = at; return; } memmove(&elements[at],&elements[end],(l-at)*T.sizeof); elements.length = l; } // find index of the element in array, -1 if not found int index(in T[] elements,T t) { int i = elements.length - 1; for(; i >= 0; --i) if( elements[i] === t ) break; return i; } } alias xarrayT!(byte).push push; alias xarrayT!(ubyte).push push; alias xarrayT!(short).push push; alias xarrayT!(ushort).push push; alias xarrayT!(int).push push; alias xarrayT!(uint).push push; alias xarrayT!(long).push push; alias xarrayT!(ulong).push push; alias xarrayT!(float).push push; alias xarrayT!(double).push push; alias xarrayT!(real).push push; alias xarrayT!(ifloat).push push; alias xarrayT!(idouble).push push; alias xarrayT!(ireal).push push; alias xarrayT!(cfloat).push push; alias xarrayT!(cdouble).push push; alias xarrayT!(creal).push push; alias xarrayT!(char).push push; alias xarrayT!(wchar).push push; alias xarrayT!(dchar).push push; alias xarrayT!(byte).pop pop; alias xarrayT!(ubyte).pop pop; alias xarrayT!(short).pop pop; alias xarrayT!(ushort).pop pop; alias xarrayT!(int).pop pop; alias xarrayT!(uint).pop pop; alias xarrayT!(long).pop pop; alias xarrayT!(ulong).pop pop; alias xarrayT!(float).pop pop; alias xarrayT!(double).pop pop; alias xarrayT!(real).pop pop; alias xarrayT!(ifloat).pop pop; alias xarrayT!(idouble).pop pop; alias xarrayT!(ireal).pop pop; alias xarrayT!(cfloat).pop pop; alias xarrayT!(cdouble).pop pop; alias xarrayT!(creal).pop pop; alias xarrayT!(char).pop pop; alias xarrayT!(wchar).pop pop; alias xarrayT!(dchar).pop pop; alias xarrayT!(byte).ins ins; alias xarrayT!(ubyte).ins ins; alias xarrayT!(short).ins ins; alias xarrayT!(ushort).ins ins; alias xarrayT!(int).ins ins; alias xarrayT!(uint).ins ins; alias xarrayT!(long).ins ins; alias xarrayT!(ulong).ins ins; alias xarrayT!(float).ins ins; alias xarrayT!(double).ins ins; alias xarrayT!(real).ins ins; alias xarrayT!(ifloat).ins ins; alias xarrayT!(idouble).ins ins; alias xarrayT!(ireal).ins ins; alias xarrayT!(cfloat).ins ins; alias xarrayT!(cdouble).ins ins; alias xarrayT!(creal).ins ins; alias xarrayT!(char).ins ins; alias xarrayT!(wchar).ins ins; alias xarrayT!(dchar).ins ins; alias xarrayT!(byte).insr insr; alias xarrayT!(ubyte).insr insr; alias xarrayT!(short).insr insr; alias xarrayT!(ushort).insr insr; alias xarrayT!(int).insr insr; alias xarrayT!(uint).insr insr; alias xarrayT!(long).insr insr; alias xarrayT!(ulong).insr insr; alias xarrayT!(float).insr insr; alias xarrayT!(double).insr insr; alias xarrayT!(real).insr insr; alias xarrayT!(ifloat).insr insr; alias xarrayT!(idouble).insr insr; alias xarrayT!(ireal).insr insr; alias xarrayT!(cfloat).insr insr; alias xarrayT!(cdouble).insr insr; alias xarrayT!(creal).insr insr; alias xarrayT!(char).insr insr; alias xarrayT!(wchar).insr insr; alias xarrayT!(dchar).insr insr; alias xarrayT!(byte).cut cut; alias xarrayT!(ubyte).cut cut; alias xarrayT!(short).cut cut; alias xarrayT!(ushort).cut cut; alias xarrayT!(int).cut cut; alias xarrayT!(uint).cut cut; alias xarrayT!(long).cut cut; alias xarrayT!(ulong).cut cut; alias xarrayT!(float).cut cut; alias xarrayT!(double).cut cut; alias xarrayT!(real).cut cut; alias xarrayT!(ifloat).cut cut; alias xarrayT!(idouble).cut cut; alias xarrayT!(ireal).cut cut; alias xarrayT!(cfloat).cut cut; alias xarrayT!(cdouble).cut cut; alias xarrayT!(creal).cut cut; alias xarrayT!(char).cut cut; alias xarrayT!(wchar).cut cut; alias xarrayT!(dchar).cut cut; alias xarrayT!(byte).cutr cutr; alias xarrayT!(ubyte).cutr cutr; alias xarrayT!(short).cutr cutr; alias xarrayT!(ushort).cutr cutr; alias xarrayT!(int).cutr cutr; alias xarrayT!(uint).cutr cutr; alias xarrayT!(long).cutr cutr; alias xarrayT!(ulong).cutr cutr; alias xarrayT!(float).cutr cutr; alias xarrayT!(double).cutr cutr; alias xarrayT!(real).cutr cutr; alias xarrayT!(ifloat).cutr cutr; alias xarrayT!(idouble).cutr cutr; alias xarrayT!(ireal).cutr cutr; alias xarrayT!(cfloat).cutr cutr; alias xarrayT!(cdouble).cutr cutr; alias xarrayT!(creal).cutr cutr; alias xarrayT!(char).cutr cutr; alias xarrayT!(wchar).cutr cutr; alias xarrayT!(dchar).cutr cutr; alias xarrayT!(byte).del del; alias xarrayT!(ubyte).del del; alias xarrayT!(short).del del; alias xarrayT!(ushort).del del; alias xarrayT!(int).del del; alias xarrayT!(uint).del del; alias xarrayT!(long).del del; alias xarrayT!(ulong).del del; alias xarrayT!(float).del del; alias xarrayT!(double).del del; alias xarrayT!(real).del del; alias xarrayT!(ifloat).del del; alias xarrayT!(idouble).del del; alias xarrayT!(ireal).del del; alias xarrayT!(cfloat).del del; alias xarrayT!(cdouble).del del; alias xarrayT!(creal).del del; alias xarrayT!(char).del del; alias xarrayT!(wchar).del del; alias xarrayT!(dchar).del del; alias xarrayT!(byte).index index; alias xarrayT!(ubyte).index index; alias xarrayT!(short).index index; alias xarrayT!(ushort).index index; alias xarrayT!(int).index index; alias xarrayT!(uint).index index; alias xarrayT!(long).index index; alias xarrayT!(ulong).index index; alias xarrayT!(float).index index; alias xarrayT!(double).index index; alias xarrayT!(real).index index; alias xarrayT!(ifloat).index index; alias xarrayT!(idouble).index index; alias xarrayT!(ireal).index index; alias xarrayT!(cfloat).index index; alias xarrayT!(cdouble).index index; alias xarrayT!(creal).index index; alias xarrayT!(char).index index; alias xarrayT!(wchar).index index; alias xarrayT!(dchar).index index; "B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done by compiler, but the above situation is frequent enought, so is there any way to do it other than a loop?
Apr 28 2005
In article <d4r6r5$1ane$1 digitaldaemon.com>, Andrew Fedoniouk says...Instead of a[3 .. 20] = a[4 .. 21]; a[3] = something; you may use just a.ins( 3, something ); if you will include following somewhere:The question was actually indeed about Vector-like templates, :) I was trying to write my own. is this a part of some library like dool, mango, etc? BTW, please correct me If I'm wrong without the aliases at the very bottom, I can't use char[] x x.ins(...) Is that the reason why they are there? If I'm applying those templates to a class, do I have to define aliases for that particular class for the arr.func() syntax to work with the class? Hmmmm, funny, now I don't understand how aliasing works, I didn't know you can say alias xarrayT!(char).index index; alias xarrayT!(wchar).index index; How can two and more different things be mapped to one identifier??? That would mean, for a D compiler aliases are not as simple as identifier mapping. Further, if it's not that simple anyway, wouldn't it be more logical to have a compiler to decide in place which template function to use? Something else... already several times I've encountered the situation when there is some code or someone is speaking about features of D, not present at http://www.digitalmars.com/d/. This makes me think that this language description is out of date, Is there a place where ALL language features including most recent or experimental stuff are documented or at least referenced? For instance I couldn't find anything about - opApply, - $ instead of length for slice syntax, - maybe I'm blind, but the array syntax we speak about is not there too, (a really _great_ feature IMHO)//| //| std D array extenders, these should be intrinsic ops for arrays in ideal D //| template xarrayT(T) { // append array by one element void push(inout T[] elements, T v) { int l = elements.length; elements.length = l + 1; elements[l] = v; } // del last element and return it T pop(inout T[] elements) { int l = elements.length - 1; assert(l >= 0); T t = elements[l]; elements.length = l; return t; } // insert element into array void ins(inout T[] elements, uint at, T v) { uint l = elements.length; if(at >= l) { elements ~= v; return; } // for some reasons this does not compile: // elements = elements[0..at] ~ v ~ elements[at..elements.length]; // so we use C way: elements.length = l + 1; memmove(&elements[at+1],&elements[at],(l-at)*T.sizeof); elements[at] = v; } // insert array into array void insr(inout T[] elements, uint at, T[] va ) { uint l = elements.length; if(at >= l) { elements ~= va; return; } elements.length = l + va.length; memmove(&elements[at + va.length],&elements[at],(l-at)*T.sizeof); elements[at..at+va.length] = va; } // del element and return it T cut(inout T[] elements, uint at) { uint l = elements.length - 1; if(at >= l) return pop(elements); T t = elements[at]; memmove(&elements[at],&elements[at+1],(l-at)*T.sizeof); elements.length = l; return t; } // del range and return its content T[] cutr(inout T[] elements, uint at, uint end) { assert(at <= end); if(at == end) return null; T[] t = elements[at..end].dup; uint l = elements.length - (end - at); if(at < l) { elements.length = at; return t; } memmove(&elements[at],&elements[end],(l-at)*T.sizeof); elements.length = l; return t; } // just del range void del(inout T[] elements, int at, int end) { assert(at <= end); if(at == end) return; uint l = elements.length - (end - at); if(at >= l) { elements.length = at; return; } memmove(&elements[at],&elements[end],(l-at)*T.sizeof); elements.length = l; } // find index of the element in array, -1 if not found int index(in T[] elements,T t) { int i = elements.length - 1; for(; i >= 0; --i) if( elements[i] === t ) break; return i; } } alias xarrayT!(byte).push push; alias xarrayT!(ubyte).push push; alias xarrayT!(short).push push; alias xarrayT!(ushort).push push; alias xarrayT!(int).push push; alias xarrayT!(uint).push push; alias xarrayT!(long).push push; alias xarrayT!(ulong).push push; alias xarrayT!(float).push push; alias xarrayT!(double).push push; alias xarrayT!(real).push push; alias xarrayT!(ifloat).push push; alias xarrayT!(idouble).push push; alias xarrayT!(ireal).push push; alias xarrayT!(cfloat).push push; alias xarrayT!(cdouble).push push; alias xarrayT!(creal).push push; alias xarrayT!(char).push push; alias xarrayT!(wchar).push push; alias xarrayT!(dchar).push push; alias xarrayT!(byte).pop pop; alias xarrayT!(ubyte).pop pop; alias xarrayT!(short).pop pop; alias xarrayT!(ushort).pop pop; alias xarrayT!(int).pop pop; alias xarrayT!(uint).pop pop; alias xarrayT!(long).pop pop; alias xarrayT!(ulong).pop pop; alias xarrayT!(float).pop pop; alias xarrayT!(double).pop pop; alias xarrayT!(real).pop pop; alias xarrayT!(ifloat).pop pop; alias xarrayT!(idouble).pop pop; alias xarrayT!(ireal).pop pop; alias xarrayT!(cfloat).pop pop; alias xarrayT!(cdouble).pop pop; alias xarrayT!(creal).pop pop; alias xarrayT!(char).pop pop; alias xarrayT!(wchar).pop pop; alias xarrayT!(dchar).pop pop; alias xarrayT!(byte).ins ins; alias xarrayT!(ubyte).ins ins; alias xarrayT!(short).ins ins; alias xarrayT!(ushort).ins ins; alias xarrayT!(int).ins ins; alias xarrayT!(uint).ins ins; alias xarrayT!(long).ins ins; alias xarrayT!(ulong).ins ins; alias xarrayT!(float).ins ins; alias xarrayT!(double).ins ins; alias xarrayT!(real).ins ins; alias xarrayT!(ifloat).ins ins; alias xarrayT!(idouble).ins ins; alias xarrayT!(ireal).ins ins; alias xarrayT!(cfloat).ins ins; alias xarrayT!(cdouble).ins ins; alias xarrayT!(creal).ins ins; alias xarrayT!(char).ins ins; alias xarrayT!(wchar).ins ins; alias xarrayT!(dchar).ins ins; alias xarrayT!(byte).insr insr; alias xarrayT!(ubyte).insr insr; alias xarrayT!(short).insr insr; alias xarrayT!(ushort).insr insr; alias xarrayT!(int).insr insr; alias xarrayT!(uint).insr insr; alias xarrayT!(long).insr insr; alias xarrayT!(ulong).insr insr; alias xarrayT!(float).insr insr; alias xarrayT!(double).insr insr; alias xarrayT!(real).insr insr; alias xarrayT!(ifloat).insr insr; alias xarrayT!(idouble).insr insr; alias xarrayT!(ireal).insr insr; alias xarrayT!(cfloat).insr insr; alias xarrayT!(cdouble).insr insr; alias xarrayT!(creal).insr insr; alias xarrayT!(char).insr insr; alias xarrayT!(wchar).insr insr; alias xarrayT!(dchar).insr insr; alias xarrayT!(byte).cut cut; alias xarrayT!(ubyte).cut cut; alias xarrayT!(short).cut cut; alias xarrayT!(ushort).cut cut; alias xarrayT!(int).cut cut; alias xarrayT!(uint).cut cut; alias xarrayT!(long).cut cut; alias xarrayT!(ulong).cut cut; alias xarrayT!(float).cut cut; alias xarrayT!(double).cut cut; alias xarrayT!(real).cut cut; alias xarrayT!(ifloat).cut cut; alias xarrayT!(idouble).cut cut; alias xarrayT!(ireal).cut cut; alias xarrayT!(cfloat).cut cut; alias xarrayT!(cdouble).cut cut; alias xarrayT!(creal).cut cut; alias xarrayT!(char).cut cut; alias xarrayT!(wchar).cut cut; alias xarrayT!(dchar).cut cut; alias xarrayT!(byte).cutr cutr; alias xarrayT!(ubyte).cutr cutr; alias xarrayT!(short).cutr cutr; alias xarrayT!(ushort).cutr cutr; alias xarrayT!(int).cutr cutr; alias xarrayT!(uint).cutr cutr; alias xarrayT!(long).cutr cutr; alias xarrayT!(ulong).cutr cutr; alias xarrayT!(float).cutr cutr; alias xarrayT!(double).cutr cutr; alias xarrayT!(real).cutr cutr; alias xarrayT!(ifloat).cutr cutr; alias xarrayT!(idouble).cutr cutr; alias xarrayT!(ireal).cutr cutr; alias xarrayT!(cfloat).cutr cutr; alias xarrayT!(cdouble).cutr cutr; alias xarrayT!(creal).cutr cutr; alias xarrayT!(char).cutr cutr; alias xarrayT!(wchar).cutr cutr; alias xarrayT!(dchar).cutr cutr; alias xarrayT!(byte).del del; alias xarrayT!(ubyte).del del; alias xarrayT!(short).del del; alias xarrayT!(ushort).del del; alias xarrayT!(int).del del; alias xarrayT!(uint).del del; alias xarrayT!(long).del del; alias xarrayT!(ulong).del del; alias xarrayT!(float).del del; alias xarrayT!(double).del del; alias xarrayT!(real).del del; alias xarrayT!(ifloat).del del; alias xarrayT!(idouble).del del; alias xarrayT!(ireal).del del; alias xarrayT!(cfloat).del del; alias xarrayT!(cdouble).del del; alias xarrayT!(creal).del del; alias xarrayT!(char).del del; alias xarrayT!(wchar).del del; alias xarrayT!(dchar).del del; alias xarrayT!(byte).index index; alias xarrayT!(ubyte).index index; alias xarrayT!(short).index index; alias xarrayT!(ushort).index index; alias xarrayT!(int).index index; alias xarrayT!(uint).index index; alias xarrayT!(long).index index; alias xarrayT!(ulong).index index; alias xarrayT!(float).index index; alias xarrayT!(double).index index; alias xarrayT!(real).index index; alias xarrayT!(ifloat).index index; alias xarrayT!(idouble).index index; alias xarrayT!(ireal).index index; alias xarrayT!(cfloat).index index; alias xarrayT!(cdouble).index index; alias xarrayT!(creal).index index; alias xarrayT!(char).index index; alias xarrayT!(wchar).index index; alias xarrayT!(dchar).index index; "B.G." <B.G._member pathlink.com> wrote in message news:d4r4pq$186g$1 digitaldaemon.com...a[3 .. 20] = a[4 .. 21]; is prohibited, Slicing is a great idea leaving much space for optimizations done by compiler, but the above situation is frequent enought, so is there any way to do it other than a loop?
Apr 28 2005
I was trying to write my own. is this a part of some library like dool, mango, etc?It is part of Harmonia library which is not published yet.BTW, please correct me If I'm wrong without the aliases at the very bottom, I can't use char[] x x.ins(...) Is that the reason why they are there?Yes. You are right.If I'm applying those templates to a class, do I have to define aliases for that particular class for the arr.func() syntax to work with the class? Hmmmm, funny, now I don't understand how aliasing works, I didn't know you can say alias xarrayT!(char).index index; alias xarrayT!(wchar).index index; How can two and more different things be mapped to one identifier???The same mechanism as with e,g, two declarations index(char c) and index(int i) if I understood Walter correctly.That would mean, for a D compiler aliases are not as simple as identifier mapping. Further, if it's not that simple anyway, wouldn't it be more logical to have a compiler to decide in place which template function to use? Something else... already several times I've encountered the situation when there is some code or someone is speaking about features of D, not present at http://www.digitalmars.com/d/. This makes me think that this language description is out of date, Is there a place where ALL language features including most recent or experimental stuff are documented or at least referenced? For instance I couldn't find anything about - opApply, - $ instead of length for slice syntax, - maybe I'm blind, but the array syntax we speak about is not there too, (a really _great_ feature IMHO)$ is experimental alias for 'length'. Seems like excitement about it already vanished. Sic transit gloria mundi. opApply defined here: http://www.digitalmars.com/d/statement.html#foreach Yep. sort of thesaurus (index) in documentation will be extremely nice.
Apr 28 2005
In article <d4r6r5$1ane$1 digitaldaemon.com>, Andrew Fedoniouk says...Instead of a[3 .. 20] = a[4 .. 21]; a[3] = something; you may use just a.ins( 3, something ); if you will include following somewhere:..Andrew, thanks for being kind enough to share your xarrayt.d code back in April (of which, I've just now gotten around to checking it out)...hope you don't mind, but I thought I'd post a minor bug fixed / addtional unittest to the code. I'm pretty sure others will find this code you've written as being very useful in their own projects! Output: ------- C:\dmd>dmd xarrayt.d -debug=xarrayt -unittest C:\dmd\bin\..\..\dm\bin\link.exe xarrayt,,,user32+kernel32/noi; C:\dmd>xarrayt xarryt.unittest started. String (char[]) Array Test. push() s="To Kill a Mocking Bird!" pop() s="" (Looped thru to remove all the characters) ins() s="To SKill a Mocking Bird!" del() s="To Kill a Mocking Bird!" del() and insr() s="To Raise a Mocking Bird!" del() and insr() s="To Kiss a Mocking Bird!" cutr() and '~=' s="To Kiss a puppy Dog!" sub="Mocking Bird!" index() 'K' found at position 3 cut() 'K' s="To iss a puppy Dog!" Numerical (long[]) Array Test. la[]=10,20,21,25,30,40,45,50 push() la[]=10,20,21,25,30,40,45,50,60,70 pop() la[]=10,20,21,25,30,40,45,50,60 ins() la[]=10,15,20,21,25,30,40,45,50,60 del() la[]=10,15,20,25,30,40,45,50,60 cutr() la[]=10,30,40,45,50,60 la's cut to la2[]=15,20,25 index() value 45 found at position 3 cut() la[]=10,30,40,50,60 la's cut to la2[]=45 xarrayt.unittest finished! C:\dmd> Thanks again for sharing it, David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Jul 31 2005
Seems very useful indeed. Thanks for bringing this to public attention (again). Cheers, Holger In article <dcj82c$jn0$1 digitaldaemon.com>, David L. Davis says...In article <d4r6r5$1ane$1 digitaldaemon.com>, Andrew Fedoniouk says...Instead of a[3 .. 20] = a[4 .. 21]; a[3] = something; you may use just a.ins( 3, something ); if you will include following somewhere:..Andrew, thanks for being kind enough to share your xarrayt.d code back in April (of which, I've just now gotten around to checking it out)...hope you don't mind, but I thought I'd post a minor bug fixed / addtional unittest to the code. I'm pretty sure others will find this code you've written as being very useful in their own projects! Output: ------- C:\dmd>dmd xarrayt.d -debug=xarrayt -unittest C:\dmd\bin\..\..\dm\bin\link.exe xarrayt,,,user32+kernel32/noi; C:\dmd>xarrayt xarryt.unittest started. String (char[]) Array Test. push() s="To Kill a Mocking Bird!" pop() s="" (Looped thru to remove all the characters) ins() s="To SKill a Mocking Bird!" del() s="To Kill a Mocking Bird!" del() and insr() s="To Raise a Mocking Bird!" del() and insr() s="To Kiss a Mocking Bird!" cutr() and '~=' s="To Kiss a puppy Dog!" sub="Mocking Bird!" index() 'K' found at position 3 cut() 'K' s="To iss a puppy Dog!" Numerical (long[]) Array Test. la[]=10,20,21,25,30,40,45,50 push() la[]=10,20,21,25,30,40,45,50,60,70 pop() la[]=10,20,21,25,30,40,45,50,60 ins() la[]=10,15,20,21,25,30,40,45,50,60 del() la[]=10,15,20,25,30,40,45,50,60 cutr() la[]=10,30,40,45,50,60 la's cut to la2[]=15,20,25 index() value 45 found at position 3 cut() la[]=10,30,40,50,60 la's cut to la2[]=45 xarrayt.unittest finished! C:\dmd> Thanks again for sharing it, David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Jul 31 2005