On Friday, 6 December 2019 at 07:03:45 UTC, berni44 wrote:
My real question is: Can this code duplication be avoided
somehow? (I ask, because I've got a PR running, which increases
the size of these functions and it doesn't feel good to have
two long, almost identical functions.)
You can use
In std.typecons, in Tuple there are two opCmp functions, that are
almost identical; they only differ by one being const and the
other not:
int opCmp(R)(R rhs)
if (areCompatibleTuples!(typeof(this), R, "<"))
{
static foreach (i; 0 .. Types.length)
On Friday, 6 December 2019 at 05:09:58 UTC, Paul Backus wrote:
On Thursday, 5 December 2019 at 17:27:45 UTC, Taylor Hillegeist
wrote:
I agree with this.
I wasn't clear enough in my question though.
I was trying to distinguish between std.functional.compose and
std.functional.pipe
they look
On Thursday, 5 December 2019 at 17:27:45 UTC, Taylor Hillegeist
wrote:
I agree with this.
I wasn't clear enough in my question though.
I was trying to distinguish between std.functional.compose and
std.functional.pipe
they look very the same. Pipe says it reverses functions order.
Which
Learning all the ins and outs of the std library is fun. But
there are soo many hidden gems that its hard to tell when to keep
looking and when to just write something. I was working on a
split function with some particulars:
Split but keep exactly one delimiter at the beginning of each
On Friday, 11 October 2019 at 06:18:03 UTC, Ali Çehreli wrote:
Your threads must allocate as little memory as possible because
memory allocation can trigger garbage collection and garbage
collection stops all threads (except the one that's performing
collection).
We studied the effects of
On Friday, 11 October 2019 at 06:57:46 UTC, Russel Winder wrote:
A neural net is, at it's heart, a set of communicating nodes.
This is as much
an I/O bound model as it is compute bound one – nodes are
generally waiting
for input as much as they are computing a value. The obvious
solution
On Thursday, 5 December 2019 at 15:43:30 UTC, Paul Backus wrote:
On Thursday, 5 December 2019 at 15:30:52 UTC, Taylor Hillegeist
wrote:
On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote:
.pipe!((output) {
if (sortOutput)
return output.sort!("a < b");
else
On 12/5/19 3:57 AM, Robert M. Münch wrote:
On 2019-12-04 19:23:07 +, Steven Schveighoffer said:
Is one a delegate and one a function pointer? This can easily happen
for untyped lambdas.
That's a very good point and hint. A function pointer will be 8LU and a
delegate 16LU, right? This is
On Thursday, 5 December 2019 at 15:30:52 UTC, Taylor Hillegeist
wrote:
On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote:
.pipe!((output) {
if (sortOutput)
return output.sort!("a < b");
else
return output;
})
.writeln(); // maybe you meant
On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote:
.pipe!((output) {
if (sortOutput)
return output.sort!("a < b");
else
return output;
})
.writeln(); // maybe you meant each!writeln ?
Why pipe as apposed to compose?
Pipes functions in
On 2019-12-04 19:23:07 +, Steven Schveighoffer said:
Is one a delegate and one a function pointer? This can easily happen
for untyped lambdas.
Not sure if the code-snippets already give an explanation but the
differences I have are:
1. Working case
template filter(alias pred)
{
On Thursday, 5 December 2019 at 11:28:51 UTC, Marcone wrote:
Simple example:
writeln("Hi\nHow are
you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]);
How to refer to this string in lastIndexOf() without create a
variable?
Thank you.
.splitLines[0] already just produces "Hi", containing
On Thursday, 5 December 2019 at 11:28:51 UTC, Marcone wrote:
Simple example:
writeln("Hi\nHow are
you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]);
How to refer to this string in lastIndexOf() without create a
variable?
Thank you.
One solution:
writeln(
"Hello\nHow are
On Thursday, 5 December 2019 at 12:00:23 UTC, Ola Fosheim Grøstad
wrote:
So basically, templated functions get flow-typing.
But it is not reliable :-(
struct node {int value; node* next;}
node n0 = {1,null};
node mk_node1()(node* n){
node tmp = {2019, n};
return tmp;
}
node
So basically, templated functions get flow-typing. I guess that
is a good reason to use templated functions more...
What is the downside? E.g.:
struct node {int value; node* next;}
node mk_node2()(){
node tmp = {2019, null};
return tmp;
}
node mk_node(){
node tmp = {2019, null};
Simple example:
writeln("Hi\nHow are
you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]);
How to refer to this string in lastIndexOf() without create a
variable?
Thank you.
On Thursday, 5 December 2019 at 10:41:24 UTC, Ola Fosheim Grøstad
wrote:
immutable x1 = mk!node1(); //succeeds?
immutable y1 = mk_node1(); //fails
Nevermind, seems like templated functions get stronger coercion,
like:
immutable y1 = cast(immutable)mk_node1();
(Also no need to
I also find the following behaviour a bit unclear:
struct node0 {int value; node0* next;}
struct node1 {int value; const(node1)* next;}
struct node2 {int value; immutable(node0)* next;}
T mk(T)(){
T tmp = {2019, null};
return tmp;
}
node1 mk_node1(){
node1 tmp = {2019, null};
On 2019-12-04 19:23:07 +, Steven Schveighoffer said:
Is one a delegate and one a function pointer? This can easily happen
for untyped lambdas.
That's a very good point and hint. A function pointer will be 8LU and a
delegate 16LU, right? This is a strong argument that this is really the
On Wednesday, 4 December 2019 at 23:27:49 UTC, Steven
Schveighoffer wrote:
void foo(alias f)()
{
alias ConstType = const(typeof(f()));
pragma(msg, ConstType);
}
I expressed myself poorly, what I am interested in is this:
struct node1 {int value; const(node1)* next;}
struct node2 {int
I haven't used const much in the past because I got burned on
transitive const, so I managed to confuse myself. I am not
really interested in const/immutabel references here, only
values. Seems like there is no reason to ever use const values,
except when the value may contain a pointer to
I haven't used const much in the past because I got burned on
transitive const, so I managed to confuse myself. I am not
really interested in const/immutabel references here, but values.
Seems like there is no reason to ever use const values, except
when they contain a pointer to something
23 matches
Mail list logo