On Tuesday, 18 July 2017 at 12:39:01 UTC, Stefan Koch wrote:
whhhahhh template bloat
Yes, and also very slow. :)
On Tuesday, 18 July 2017 at 08:46:50 UTC, Jack Applegame wrote:
On Monday, 17 July 2017 at 17:38:23 UTC, Nordlöw wrote:
I'm want to define a specialization of `append()` that takes
only static arrays as inputs and returns a static array being
the sum of the lengths of the inputs.
Have anybody
On Tuesday, 18 July 2017 at 08:07:45 UTC, Jacob Carlborg wrote:
append - add array or element to existing array
concat (concatenate) - add to arrays (or element) together to
create a new array
Seems like this is a concatenation. But please avoid shortening
the names. I vote you go with "conca
On Monday, 17 July 2017 at 17:38:23 UTC, Nordlöw wrote:
I'm want to define a specialization of `append()` that takes
only static arrays as inputs and returns a static array being
the sum of the lengths of the inputs.
Have anybody already implemented this?
If not, I'm specifically interested i
On 2017-07-17 22:11, Nordlöw wrote:
- under what name: append, concat or cat?
append - add array or element to existing array
concat (concatenate) - add to arrays (or element) together to create a
new array
Seems like this is a concatenation. But please avoid shortening the
names. I vote y
On Mon, Jul 17, 2017 at 10:32:14PM +, Nordlöw via Digitalmars-d-learn wrote:
> On Monday, 17 July 2017 at 20:01:41 UTC, H. S. Teoh wrote:
[...]
> > result[offset .. offset + a.length] = a[];
>
> This slice assignment doesn't support conversion between different
> element-ty
On Monday, 17 July 2017 at 20:28:12 UTC, Nordlöw wrote:
Made some adjustments with working unittest and put it up on
https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2467
Moved here
https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d#L2765
On Monday, 17 July 2017 at 20:01:41 UTC, H. S. Teoh wrote:
OK, here's an actual, compilable, runnable version:
import std.algorithm : sum;
import std.meta : allSatisfy, staticMap;
import std.range : only;
import std.traits : CommonType, isStaticArray;
ali
On Monday, 17 July 2017 at 20:53:36 UTC, H. S. Teoh wrote:
See the working implementation in my latest post on this
thread. That version supports CommonType, and works correctly
with empty tuples as well.
T
Thanks.
On Mon, Jul 17, 2017 at 08:28:12PM +, Nordlöw via Digitalmars-d-learn wrote:
[...]
> I had to special-case foreach body for `i == 0` since `sumOfLengths`
> couldn't instantiate with empty tuple `()`.
>
> Further, should `concat` support `CommonType`? That is, should
>
> int[2] x = [1, 2];
On Monday, 17 July 2017 at 20:10:31 UTC, H. S. Teoh wrote:
On Mon, Jul 17, 2017 at 08:11:03PM +, Nordlöw via
Digitalmars-d-learn wrote: [...]
Does this have a place in Phobos?
Never know till you try. :-D
If so,
- under what name: append, concat or cat?
I'd vote for concat.
- wher
On Mon, Jul 17, 2017 at 08:11:03PM +, Nordlöw via Digitalmars-d-learn wrote:
[...]
> Does this have a place in Phobos?
Never know till you try. :-D
> If so,
>
> - under what name: append, concat or cat?
I'd vote for concat.
> - where: std.algorithm or std.array?
std.array, IMO, since it
On Monday, 17 July 2017 at 19:11:26 UTC, H. S. Teoh wrote:
Hmm, since we already have sumOfLengths available at
compile-time, what about:
T[sumOfLengths!StaticArrays]
append(StaticArrays...)(StaticArrays arrays)
if (allSatisfy!(isStaticArray, StaticArrays))
{
OK, here's an actual, compilable, runnable version:
import std.algorithm : sum;
import std.meta : allSatisfy, staticMap;
import std.range : only;
import std.traits : CommonType, isStaticArray;
alias Elem(A : E[n], E, size_t n) = E;
enum Length(A) =
On Monday, 17 July 2017 at 18:54:31 UTC, Stefan Koch wrote:
we have special code in the compiler to optimize a ~ b ~ c.
Interesting, can you elaborate on what you mean with "optimize".
In that case, is there a reason why
int x[2];
int y[2];
int z[x.length + y.length] = x ~ y;
isn
On Monday, 17 July 2017 at 18:54:31 UTC, Stefan Koch wrote:
So all you need to do make it so
auto cat(T[]...)(T args)
{
T[] result;
mixin(() {
string mix = `result = `;
foreach(i;args.length)
{
mix ~= `args[` ~ itos(i) ~ `] ~`;
}
mix[$-1] = ';';
On Mon, Jul 17, 2017 at 12:01:48PM -0700, H. S. Teoh via Digitalmars-d-learn
wrote:
[...]
> template sumOfLengths(A...)
> if (A.length > 0)
> {
> static if (A.length == 1)
> enum sumOfLengths = A[0].length;
> else
>
On Mon, Jul 17, 2017 at 12:01:48PM -0700, H. S. Teoh via Digitalmars-d-learn
wrote:
[...]
> T[sumOfLengths!StaticArrays] append(StaticArrays...)(StaticArrays
> arrays)
> if (/* insert static array constraints here */)
> {
> typeof(return) result = void;
>
On Mon, Jul 17, 2017 at 05:38:23PM +, Nordlöw via Digitalmars-d-learn wrote:
> I'm want to define a specialization of `append()` that takes only
> static arrays as inputs and returns a static array being the sum of
> the lengths of the inputs.
>
> Have anybody already implemented this?
>
> If
On 07/17/2017 08:35 PM, Nordlöw wrote:
Thanks, but I'm talking about the variadic case where the number of
input arguments are unknown (>= 2) where the function header looks
something like
import std.traits : allSatisfy, isStaticArray;
auto append(R, Args...)(auto ref Args args)
if (args
On Monday, 17 July 2017 at 18:38:16 UTC, Nordlöw wrote:
On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote:
int[n + m] result = a ~ b;
Further, the expression `a ~ b` here will allocate and create a
copy on the GC-heap before writing `result`.
Maybe LDC optimizes away this now or i
On Monday, 17 July 2017 at 17:38:23 UTC, Nordlöw wrote:
I'm want to define a specialization of `append()` that takes
only static arrays as inputs and returns a static array being
the sum of the lengths of the inputs.
Have anybody already implemented this?
If not, I'm specifically interested i
On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote:
int[n + m] result = a ~ b;
Further, the expression `a ~ b` here will allocate and create a
copy on the GC-heap before writing `result`.
Maybe LDC optimizes away this now or in the future but DMD cannot.
Yeah I know, kind of dumb b
On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote:
Like so?
int[n + m] append(size_t n, size_t m)(int[n] a, int[m] b)
{
int[n + m] result = a ~ b;
return result;
}
Thanks, but I'm talking about the variadic case where the number
of input arguments are unknown (>= 2) where the fu
On 07/17/2017 07:38 PM, Nordlöw wrote:
I'm want to define a specialization of `append()` that takes only static
arrays as inputs and returns a static array being the sum of the lengths
of the inputs.
Have anybody already implemented this?
If not, I'm specifically interested in how to most con
25 matches
Mail list logo