View mode: basic / threaded / horizontal-split · Log in · Help
April 28, 2005
overlapping slices
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?
April 28, 2005
Re: overlapping slices
"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?

You can use C's memmove().
April 28, 2005
Re: overlapping slices
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?
>
>
>
April 28, 2005
Re: overlapping slices
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?
>>
>>
>> 
>
>
April 28, 2005
Re: overlapping slices
> 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.
April 29, 2005
Re: overlapping slices
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...
>> 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?
>
>You can use C's memmove().

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.

thanx
April 30, 2005
Re: overlapping slices
"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...
> >
> >
> >"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?
> >
> >You can use C's memmove().
>
> Do you mean casting array ref to a pointer and give it to memmove?

Yes.

> 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
Re: overlapping slices
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...
>> 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...
>> >> 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?
>> >
>> >You can use C's memmove().
>>
>> Do you mean casting array ref to a pointer and give it to memmove?
>
>Yes.
>
>> 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.
>
I bag a pardon, what's DMC?

thanx.
May 02, 2005
Re: overlapping slices
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...
>> 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...
>> >> 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?
>> >
>> >You can use C's memmove().
>>
>> Do you mean casting array ref to a pointer and give it to memmove?
>
>Yes.
>
>> 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.
>
I bag a pardon, what's DMC?

thanx.
May 02, 2005
Re: overlapping slices
On Mon, 2 May 2005 22:29:03 +0000 (UTC), B.G. wrote:

> 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...
>>> 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...
>>> >> 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?
>>> >
>>> >You can use C's memmove().
>>>
>>> Do you mean casting array ref to a pointer and give it to memmove?
>>
>>Yes.
>>
>>> 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.
>>
> I bag a pardon, what's DMC?
> 
> thanx.

DMC == Digital Mars C++ Compiler.

 http://www.digitalmars.com

-- 
Derek
Melbourne, Australia
3/05/2005 9:21:11 AM
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home