Re: Can't call splitter with range struct

2021-03-16 Thread David Skluzacek via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 07:43:18 UTC, drug wrote:
That means that you GZippedRange should provide opSlice 
operator and should be a narrow string (string of char or wchar)


Yes, I should have looked more carefully at the doc, I was 
assuming splitter would accept a simple input range, but it 
doesn't. I really didn't want to provide opSlice because then if 
it were called with an index higher than the length of the buffer 
I'd have to read more data and allocate memory to hold it. I'm 
not actually trying to do this any more though. Thanks.


Can't call splitter with range struct

2021-03-15 Thread David Skluzacek via Digitalmars-d-learn
I came across this problem as I was trying to see if could write 
a quick range-based solution with std.zlib to do what was asked 
about in a different Learn forum post - read a gzipped file.


This seems like it should work:

import std.stdio, std.algorithm, std.zlib;
import std.range.primitives;

void main(string[] args)
{
auto f = GZippedFile(File(args[1], "rb"));
f.splitter("\n").each!writeln;
}

struct GZippedFile
{
File file;
UnCompress uncompressor;
ubyte[] readBuffer;
const(char)[] buffer;

this(File f) {
file = f;
uncompressor = new UnCompress(HeaderFormat.gzip);
readBuffer = new ubyte[4096];
}

dchar front() const {
return buffer.front;
}

void popFront() {
if (buffer.empty) {
buffer = cast(const(char)[])
uncompressor.uncompress(file.rawRead(readBuffer));
}
else {
buffer.popFront();
}
}

bool empty() {
return buffer.empty && file.eof();
}
}

But I get:

Error: template std.algorithm.iteration.splitter cannot deduce 
function from argument types !()(GZippedFile, string), candidates 
are:
/usr/include/dlang/dmd/std/algorithm/iteration.d(4678):
splitter(alias pred = "a == b", Range, Separator)(Range r, 
Separator s)

  with pred = "a == b",
   Range = GZippedFile,
   Separator = string
  must satisfy the following constraint:
   is(typeof(binaryFun!pred(r.front, s)) : bool)
(...)

If I change the newline separator to a character literal, I get:

(...)
/usr/include/dlang/dmd/std/algorithm/iteration.d(5055):
splitter(alias pred = "a == b", Range, Separator)(Range r, 
Separator s)

  with pred = "a == b",
   Range = GZippedFile,
   Separator = char
  must satisfy the following constraint:
   is(typeof(binaryFun!pred(r.front, s.front)) : bool)

It seems like "\n" should pass the second constraint and '\n' 
should pass the first.  Using a dchar or dstring makes no 
difference. Adding @property to front makes no difference. Is 
this a bug?




Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-13 Thread David Skluzacek via Digitalmars-d-learn

On Thursday, 11 March 2021 at 22:10:04 UTC, David wrote:
I wasn't aware that object files could be manipulated like the 
strip manual page - thx for the heads up.


With the caveats that the linked post is almost 14 years old, I 
can't try this command myself, and the ldc solution is probably 
preferable if you can get it to work - if you want to compile 
with dmd and use the strip command, this might help you (the OP 
answered his own question at the bottom):


https://forum.juce.com/t/how-to-build-dylib-exporting-only-wanted-symbols/2180

He suggests doing:

strip -u -r -s FILE_CONTAINING_EXPORTS_LIST MY_DYLIB.dylib


Re: array of delegates

2016-04-13 Thread David Skluzacek via Digitalmars-d-learn
So, that message is a pretty cryptic, but the problem there is 
that map does its thing at runtime, but partial is a template and 
must be instantiated at compile time.


Instead you can use std.meta.staticMap, by doing something like 
this:




void main()
{
import std.stdio;
import std.functional;
import std.meta;

AA aa = new AA();
int delegate(int, Props) sg;
sg = 

template partialSG(alias a)
{
alias partialSG = partial!(sg, a);
}

alias indarr = AliasSeq!(0, 1, 2, 3, 4);
alias funs = staticMap!(partialSG, indarr);

foreach (fun; funs)
{
writeln( fun(Props.p1) );
writeln( fun(Props.p2) );
}
}