Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3720

Re: Understanding ValArray slices

From jacob navia <jacob@spamsink.net>
Newsgroups comp.lang.c++
Subject Re: Understanding ValArray slices
Date 2011-04-14 22:50 +0200
Organization lccwin
Message-ID <io7mmh$22l$1@speranza.aioe.org> (permalink)
References (1 earlier) <90mk5cFeeiU8@mid.individual.net> <io57nd$b6s$1@speranza.aioe.org> <0cfb9f27-e357-4df0-8524-c6f5da967d44@k3g2000prl.googlegroups.com> <io6qf5$ncl$1@speranza.aioe.org> <01b3d7b2-ba1c-439b-8524-babd0fcdb598@x37g2000prb.googlegroups.com>

Show all headers | View raw


Le 14/04/11 18:53, gwowen a écrit :
> On Apr 14, 1:48 pm, jacob navia<ja...@spamsink.net>  wrote:
>> Le 14/04/11 10:59, gwowen a crit :
>
>> MultiplyWithSlice(ValArray *array, size_t start, size_t size, size_t
>> increment, ValArray *multiplicand)
>>
>> would multiply using the described slice. The multiplicand should have
>> exactly "size" elements (i.e. as much elements as the slice describes)
>
> I'm not sure, I'm afraid.  Would this be an "in place" multiplication,
> or would MultiplyWithSlice() return a new object/pointer to a new
> object?

All the functions of the library are in place functions for the left
argument

Multiply(left,right) means left += right

This allows to build an "accumulator" kind of software in RPN
that is easy to generate and use. You can then express complicated 
formulas in that notation without allocating intermediate results.

>
> There's a good example on how to use valarray slices on the MSDN
> http://msdn.microsoft.com/en-us/library/5hky5878%28v=vs.80%29.aspx
> Essentially, the only (standardised) use of a slice object is an
> argument to valarray::operator[] which returns a valarray object whose
> size is that of the slice, containing selected elements of the initial
> valarray - without modifiying the initial array.  Think of it like the
> std::string::substr() function, but selecting evenly letters  rather
> than a substring.

I am not sure it is necessary to have a slice object. If I add 3
arguments to the slice functions it would be the same...

Another (maybe beter) possibility is that ALL functions take
a "slice" argument that defults to
{0,length(ValArray),1} i.e. 0,1,2... length(ValArray)

A function SetSlice(ValArray,start,length,increment) would set a
slice into the array to other values than the default ones, making
that ALL functions would work on the slice automatically.

To take out the slice you would call ReSetSlice(ValArray);

This has the advantage of having less functions and reusing
maybe the same code to work on a slice ithout any
modifications.

>
> std::string str = "abcdefghijklmnopqrstu";
> std::string fragment = str.subtst(1,8); // fragment = "bcdefghi"
>
> // if strings were sliceable
> std::string::slice slc(0,8,2);  //
> fragment = str[slc]; // fragment = "acegikmo"

Yes, I see.

Thanks for your input.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-13 23:44 +0200
  Re: Understanding ValArray slices Ian Collins <ian-news@hotmail.com> - 2011-04-14 09:50 +1200
    Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 00:22 +0200
      Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-14 01:59 -0700
        Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 14:48 +0200
          Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-14 09:53 -0700
            Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 22:50 +0200
              Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 22:51 +0200
              Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-14 22:47 -0700
                Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-15 22:19 +0200
                Re: Understanding ValArray slices Ian Collins <ian-news@hotmail.com> - 2011-04-16 08:21 +1200
                Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-15 14:13 -0700
                Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-15 23:24 +0200
                Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-15 23:05 -0700
                Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-16 12:00 +0200
                Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-15 14:23 -0700

csiph-web