Information about overloading opIn and opIn_r is missing from the
docs, so I'm writing that section. But I don't know what is the formal
name of this operator so I can put it in the title. Maybe I should
just name the title "Overloading the In Operator"?
On 9/23/11, Jonathan M Davis wrote:
> Though given that allSatisfy!(isNumeric, int, short) will work with
> std.traits.isNumeric and not std.string.isNumeric, I suspect that a template
> constraint could be added which would fix the problem simply by checking
> whether the compilation succeeds or
import std.string;
import std.traits;
import std.typetuple;
void main()
{
if (allSatisfy!(isNumeric, int, short))
{
}
}
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\typetuple.d(576): Error:
template instance F is not a template declaration, it is a overloadset
This took a good while
import std.typetuple;
import std.traits;
struct Foo
{
this(T1, T2)(T1 x, T2 y) if (allSatisfy!(isIntegral, T1, T2))
{
this.x = x;
this.y = y;
}
this(P)(P point) // ..constraints needed of course
{
this(point.x, point.y);
}
int x, y;
}
struct
On 9/21/11, Jacob Carlborg wrote:
> Have a look at: http://d-programming-language.org/templates-revisited.html
Right, but as I've said conv.to works at compile-time so that's
unnecessary. Maybe adding a note there about this would be nice, so
people don't spend time reimplementing common compile-
On 9/21/11, Adam D. Ruppe wrote:
> I'd suggest having a version(warnings_suck) { static assert(0); }
> so people who want more info can just stick a -version= on the build
> and get the compiler's help.
Yeah that was already planned, no worries. :)
Ah, you're right. It should have been a compile-time argument, conv.to
actually works in CTFE:
import std.conv;
struct Bar { }
struct Foo
{
this(int line = __LINE__)(Bar bar)
{
pragma(msg, "Warning: Constructing Foo with Bar incurs
precision loss. Line: " ~ to!string(line));
}
}
Won't compile for obvious reasons:
struct Bar { }
struct Foo
{
this(Bar bar, int line = __LINE__)
{
pragma(msg, "Warning: Constructing Foo with Bar incurs
precision loss. Line: " ~ line);
}
}
void main()
{
auto foo = Foo(Bar());
}
That's just an example, but I want to iss
On 9/20/11, Jonathan M Davis wrote:
> We specifically avoid having aliases in Phobos simply for having alternate
> function names. Aliases need to actually be useful, or they shouldn't be
> there.
And function names have to be useful to library users. walkLength is
an awful name for something tha
One other thing, count can only take an array which seems too
restrictive since walkLength can take any range at all. So maybe count
should be just an alias to walkLength or it should possibly be removed
(I'm against fully removing it because I already use it in code and I
think the name does make
On 9/20/11, Jonathan M Davis wrote:
> Or std.range.walkLength. I don't know why we really have std.utf.count. I
> just
> calls walkLength anyway. I suspect that it's a function that predates
> walkLength and was made to use walkLength after walkLength was introduced.
> But
> it's kind of pointless
Don't use length, use std.utf.count, ala:
import std.utf;
alias toUTFz!(const(wchar)*, string) toUTF16z;
GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s);
I like to keep that alias for my code since I was already using it beforehand.
I'm pretty sure (ok maybe 80% sure) that GetTextExt
struct Bar { int x; }
struct Foo
{
Bar _bar;
Bar bar()
{
return _bar;
}
}
void main()
{
Foo foo;
with (foo.bar)
{
}
}
Error: foo.bar() is not an lvalue
I've made a getter because I want to control how _bar is manipulated.
I've lost the ability to use the w
On 9/15/11, Jonathan M Davis wrote:
> Every template instantiation is a new set of code with _zero_ assocation
> with
> any other template instantation.
Yeah, I know. But I don't think this has to be set in stone. Having
some specific compile-time type information about a template instance
would
On 9/15/11, Timon Gehr wrote:
> template bar(T : Foo!S,S){ }
Yeah, that should do it too. Thanks.
Cool, that works, thanks. Is this in Phobos by any chance? Otherwise
I'll just use a more flexible version of that.
I can do this:
struct Foo(T) { }
template bar(T : Foo!int) { }
I can check if T is a specific instantiation of Foo. But I want to
check whether T is *any* instantiation of Foo. Is this possible to do?
Otherwise I'm currently having to hardcode via:
template bar(T) if (isOneOf!(T, Foo!int, Foo!d
struct Foo(T = int) {}
void main()
{
Foo foo; // fail
Foo!() bar; // ok
}
It would be very convenient to be able to default to one type like this.
For example, in CairoD there's a Point structure which takes doubles
as its storage type, and then there's PointInt that takes ints. The
re
foo\bar.d:
module foo.bar;
private class Foo {}
main.d:
import foo.bar : Foo;
void main()
{
auto foo = new Foo();
}
This should be a compile error, no?
On 9/10/11, Jonathan M Davis wrote:
> Personally, I think that marking a class with an attribute should only apply
> to the class and _nothing_ in it.
Agreed. But this doesn't seem to work currently unless I'm doing
something wrong..
On 9/10/11, bearophile wrote:
> Andrej Mitrovic Wrote:
>
>> Wait a minute, I've just realized private on a class definition has no
>> effect. Why is that?
>
> Try to import that class from another module...
It doesn't stop imports, that's what I'm sa
Ok so this is much more involved than I thought. I need to re-read
parts of TDPL again. Sorry for the excessive noise. :p
For crying out loud, shared fails too:
class Foo
{
shared this()
{
value = true;
}
@property bool value() { return true; }
@property void value(bool value) { }
}
void main()
{
auto foo1 = new Foo;
auto val1 = foo1.value; // fail
}
On 9/9/11, Jonathan M Davis wrote:
> But make the constructor shared. Otherwise, it gets initialized once per
> thread in spite of the fact that immutable is implicitly shared.
Good call!
So much for that idea, immutable breaks property functions. Take a look:
class Foo
{
this()
{
value = true;
}
@property bool value() { return true; }
@property void value(bool value) { }
}
void main()
{
auto foo1 = new Foo;
auto val1 = foo1.value;
auto fo
On 9/9/11, bearophile wrote:
>
> private class Foo {}
> immutable Foo foo1;
>
> static this() {
> foo1 = new immutable(Foo);
> }
Oh right, that's the syntax. Thanks!
Wait a minute, I've just realized private on a class definition has no
effect. Why is that?
Ok it seems using const works, so I can use that instead. Still I'm
wondering why I can't initialize foo inside a module ctor.
I need to have an object which is initialized only once, so I thought
I could use immutable for that. But I can't do this:
private class Foo {}
immutable Foo foo;
static this()
{
foo = new Foo;
}
void main() {}
And I can't new the object when it's declared. Even if CTFE could new
objects, i
Thanks. I'll refactor my code to eliminate the need for package in
this case. I was going to use it as a quick workaround anyway. :)
abstract class Foo
{
package void test();
}
class Bar : Foo
{
override package void test() { }
}
function test.Bar.test cannot override a non-virtual function
TDPL says package can only be used at class-level (i.e. package class
Bar : Foo), outside classes or inside a struct.
I want to
On 9/8/11, Steven Schveighoffer wrote:
> This is the plan for the revamped version of std.process, which is held up
> waiting for DMC changes.
That's good news, thanks. I'll try the various pipe/redirect methods soon.
E.g.:
import std.process;
void main()
{
auto res = shell("dmd bla.d");
}
where bla.d doesn't exist. This will throw an exception, but even if I
caught the exception I will still loose the error message. Is there
any way I could grab the error message? In this case it would be:
"std.exceptio
On 9/5/11, Johannes Pfau wrote:
> You're talking about phobos std.signals, not my implementation, right?
Yes.
On 9/5/11, Johannes Pfau wrote:
> However, I think it's useless as long as it can't be used by multiple
> threads. But when I wanted to add 'shared' support to it, I always hit
> a dead
On 9/6/11, Jonathan M Davis wrote:
> Why would you
> ever try and use an object that had been cleared?
TDPL, that's why. Things might have changed but how would someone new
to D know that?
On 9/5/11, Johannes Pfau wrote:
> I started a std.signal rewrite ~1 year ago: This is what I came up
> with:
> http://dl.dropbox.com/u/24218791/d/src/signals.html
> https://gist.github.com/1194497
This actually works great for me since it supports lambdas, I've tried
it and it works. I'll put my
Well it seems I can't use this with freeform delegates that are not
class fields. This could definitely use some improvement.
Thanks, Vladimir. :)
I'm trying to use a minimal subset of the API (ironically, to avoid
winapi bugs) for experimenting with Cairo. It's nice having the
boilerplate of features already implemented such as clipped drawing
and moving windows relative to their parent instead of relative to the
screen
This is breaking my neck right now. I have two separate windows,
window #2 hides and then shows window #1 whenever it detects the mouse
has moved in window #2. So, if the mouse stops moving, it should stop
doing that.
But instead what I get is an infinite loop. Somehow, the hiding and
showing of w
I sure hope that code is well tested though. Does anyone know why
calloc/realloc are used inside of connect() instead of letting the GC
do its thing?
On 9/5/11, Cal wrote:
> You can have multiple signals per class by naming the mixins:
Seems like you're right. I completely missed this in the docs. I think
I could make a pull to add another example of multiple signals, I
didn't know they were supported.
I'm looking at compare() in class TypeInfo_Array and it's defined as:
override int compare(in void* p1, in void* p2)
{
void[] a1 = *cast(void[]*)p1;
void[] a2 = *cast(void[]*)p2;
size_t sz = value.tsize();
size_t len = a1.length;
if (a2.length < len)
len = a2.length;
>From what I can tell std.signal is designed around the idea that an
entire class acts as a signal emitter, without the ability to write
multiple signals within one class and making arbitrary connections
between signals and slots.
If you actually read the full paper it links to:
http://www.elpauer
On 9/3/11, Andrej Mitrovic wrote:
> On 9/3/11, Timon Gehr wrote:
>> What happens if you declare the function final?
>
> Doesn't help. But it has to be virtual as every object needs to have
> it's own set of delegates.
Erm, sorry that reasoning was wrong. The fu
On 9/3/11, Timon Gehr wrote:
> What happens if you declare the function final?
Doesn't help. But it has to be virtual as every object needs to have
it's own set of delegates.
And wow, it seems to be random as well. If I do this:
@property void connect(Signal signal = Signal.MouseClick)(void
There's no question here but just an observation. I've recently had
this sort of bug:
class Foo {
void test() {
static size_t count;
// ..
count++;
}
}
void main() {
auto foo1 = new Foo;
foo1.test();
auto foo2 = new Foo;
foo2.test(); // affects the same
On 9/2/11, Steven Schveighoffer wrote:
> Am I missing something, or is it this simple?
>
> void appendMenuButton()
> {
> static size_t menuIndex;
> auto frameIndex = menuIndex++;
> button.connect!(Signal.MouseClick) = { this.showMenu(frameIndex); };
> }
>
> -Steve
>
Actually It *is* t
Damn it looks like I've ran into some template bug as well.
With this:
@property void connect(Signal signal = Signal.MouseClick)(void
delegate() dg)
{
clickHandlers ~= dg;
}
and a call like this:
item.connect = { this.showMenu(0); };
this crashes with an access violation. But
So I have this code right here (semi-pseudocode) inside a "MenuBar" widget:
void showMenu(index menuIndex) { }
void appendMenuButton()
{
static size_t menuIndex;
// create menu button, and then:
button.connect!(Signal.MouseClick) = { this.showMenu(menuIndex); };
menuIndex++;
}
but
Thanks guys!
string[2][] results;
results ~= ["foo", ""];
results ~= ["foobar", ""];
size_t len;
foreach (res; results)
{
len = max(len, res[0].length);
}
That gives me '6'. I want to convert this to functional-style code
with reduce. I've tried:
len = reduce!(max!"a[0].length")(results);
That's not it.
This is probably relevant to:
http://d.puremagic.com/issues/show_bug.cgi?id=6329
http://d.puremagic.com/issues/show_bug.cgi?id=6308
But that is all still broken from what I can tell. It used to work
fine in 2.053.
Hey btw, do you think we could use this in Phobos?
template BaseElementType(R)
{
static if (isArray!(ElementType!R))
alias BaseElementType!(ElementType!R) BaseElementType;
else static if (is(typeof({return R.init.front();}()) T))
alias T BaseElementType;
else
al
Right, but I was just trying to temporarily avoid GC allocation so
I've used a static array instead of a dynamic ones. Also, I don't know
of another term that is used to describe a int[][] array, other than
multidimensional.
Anyway this works fine for me (int wasn't a requirement in this case):
v
Take a look:
void main()
{
int[2] single;
// foo(single); // no
foo(single[]); // int[2][] slice, ok
int[2][2] multi;
// bar(multi); // int[2][2] no
// bar(multi[]); // int[2][] slice, no
// bar(multi[][]); // int[2][] slice, no
}
void foo(int[] value) {}
voi
I've always used array.replicate for this.
std.range.replicate seems to be scheduled for deprecation, it only
aliases itself to repeat():
/// Equivalent to $(D repeat(value, n)). Scheduled for deprecation.
Take!(Repeat!T) replicate(T)(T value, size_t n)
{
return repeat(value, n);
}
to!(T[]) is awesome.
I've ported this little C thingy:
sscanf(oneline, "%f %f %f %f %f", &x, &y, &z, &u, &v);
to this:
to!(float[])(line.split);
Can't get easier than that!
with doesn't work properly with alias this, I've already filed this in
bugzilla though.
Req'd: http://d.puremagic.com/issues/show_bug.cgi?id=6550
On 8/24/11, Timon Gehr wrote:
> it is usually faster
> in debug mode
Huh.. How come?
P.S. I'm aware I'm loosing the reference to the first foo object but
this is just demonstration code.
Here's some code that iterates through "parents" of some class object
until it finds an object with no parent (where parent is null):
import std.stdio;
class Foo
{
Foo parent;
int state;
this (int state) { this.state = state; }
}
void main()
{
auto foo = new Foo(0);
Here's what I can do with a variadic function:
void main()
{
int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5];
process(a[a.countUntil(7) .. $]);
process(1);
}
void process(int[] vals...)
{
foreach (val; vals)
{
}
}
Very simple, pass one or multiple arguments. But then I thought
class Foo
{
this(int x, int y) { }
}
class Bar : Foo
{
}
Bar has to define its own ctor even if it only forwards the call to
the super() ctor, e.g.:
class Bar : Foo
{
this(int x, int y) { super(x, y); }
}
But I'm curious why this works this way. If I have a large inheritance
tree of cla
Maybe ./readingHamlet < hamlet.txt
Usually this calls for a a build system, e.g. a build script or
something, that you use for specific projects which require GtkD or
something else.
For example (I'm assuming you're on win32), you could have this batch
file (build.bat):
http://codepad.org/vt0TskPy
And you could invoke it via "buil
You are explicitly linking to GtkD.lib and win32.lib, that's what's
causing the increase in size.
void foo(T)(T t) if(is(X == struct)) { }
void main()
{
foo(4);
}
This prints out:
test.d(9): Error: template test.foo(T) if (is(X == struct)) does not
match any function template declaration
test.d(9): Error: template test.foo(T) if (is(X == struct)) cannot
deduce template function
from argu
On 8/20/11, maarten van damme wrote:
> Now only how come that
> "dmd hello.d" results in a 1.70 mb application whereas
> "dmd -c hello.d" && "dmd hello.obj phobos.lib" results in a 144 kb app
In both cases on my system it produces a 464Kb app. You must be doing
something wrong. :)
You don't need the damn -L flag, just pass the .lib file directly and
DMD will pass it to the linker.
http://d.puremagic.com/issues/show_bug.cgi?id=6531
import std.range;
import std.stdio;
void main()
{
auto r1 = iota(0.0, 4.0, 0.03); // ok
auto r2 = iota(0.0, 3.0, 0.03); //
core.exception.AssertError@std.range(4001): Assertion failure
}
I want a range in steps of 0.03, beginning at 0.0 and ending at the
closest point to 3.0.
Line 4001
Okay but I wasn't really thinking about locales, underscores between
digits is a D syntax feature and it makes numbers more readable.
I meant underscores not dashes.
Can format do something like this yet?
auto str = format("%s", 100);
assert(str == "1_000_000");
%s would have to be replaced with something else, obviously.
Is this what you're after?
import std.string;
void main()
{
auto str = format("%.4s", 4);
assert(str == "0004");
}
Thanks!
Thanks, but I'll wait for the next release before I use it. In the
meantime I guess I'll use this monster:
array(until!(not!isWhite)(line)).length
That doesn't work:
import std.algorithm;
import std.stdio;
import std.functional;
import std.uni;
void main()
{
auto line = " foo";
writeln(countUntil!(not!isWhite)(line));
}
test.d(9): Error: template std.algorithm.countUntil(alias pred = "a ==
b",R1,R2) if (is(typeof(startsWith!(pred)
This will print the count of whitespace chars in a line:
writeln(count!isWhite(line));
What I need is the count of whitspace chars until the first
non-whitespace char is found, essentially I need a "countWhile"
template:
writeln(countWhile!isWhite(line));
Can I do this with existing templates s
On 8/15/11, Steven Schveighoffer wrote:
> Ouch!
It's not that big of an ouch actually: http://codepad.org/m1zKlP0e
Strings are an exception again, that code won't work for strings. Damn..
Simplified (and slow) implementation:
T[] splitLength(T)(T arr, size_t count) if (isArray!T)
{
T[] result;
while (arr.length)
{
result ~= arr.take(count);
arr.popFrontN(count);
}
return result;
}
Is there something in Phobos with which I could do:
auto arr = [1, 2, 3, 4, 5, 6];
int[][] newarr = arr.splitLength(2);
assert(newarr.length == 3);
?
This seems ancient, but maybe it could help:
http://www.dsource.org/projects/bindings/browser/trunk/gmp
I don't recall the last time `void main()` was a bottleneck in my apps. :p
Maybe it would actually make a big difference in CGI apps though.
On 8/13/11, bearophile wrote:
> Andrej Mitrovic:
>
>> void main(string[] args)
>> {
>> args.popFront; // get rid of name
>>
>> foreach (arg; args)
>> {
>> }
>> }
>
> If I see code like that I probably rewrite it lik
That's pretty stupid, of course you want to modify the arguments.
Classic example:
void main(string[] args)
{
args.popFront; // get rid of name
foreach (arg; args)
{
}
}
On 8/12/11, Jason King wrote:
> I'm attempting to convert a c header to d using htod. If this is not
> current best practice please point me in another direction.
>
> C:\dir>htod -I c:\d\dm\include ocilib.h
> Fatal error: unable to open input file 'stdlib.h'
You have an extra space there. Use:
On 8/8/11, Steven Schveighoffer wrote:
>
> I like this idea. I think it belongs in phobos somewhere, if not already.
>
> -Steve
>
Allow me to +1 on that, I've had a need for this (but now I can't
remember why, hah!).
On 8/5/11, Kagamin wrote:
> Andrej Mitrovic Wrote:
>
>> Don't forget having to minimize all the time
>> to chat to someone on MSN while playing a game. So there are some
>> benefits to having a browser based interface for a game, imo.
>
> Older games work even b
http://d-programming-language.org/interfaceToC.html
Originally the table just showed D and C types, the 32/64 bit columns
weren't there. On my last commit I had this:
D type | C type
c_long (in core.stdc.config) | long
c_ulong (in core.stdc.config) | unsigned long
long | long long
ulong | unsign
Cool. I've submitted a bug report for this, but maybe it's a duplicate.
I thought MSN had a pretty large network of users. IIRC arstechnica
recently had an article comparing the userbase of msn and skype.
I think we're misunderstanding each other.
I'm not saying move the game to the browser, just the part of the game
where you can browse the servers for that game. That's the part of
QLive that I liked, I don't care if the game actually runs in the
browser or not. I don't know what this NaCI busines
On 8/4/11, Jacob Carlborg wrote:
> I would say that the correct solution is to rewrite the examples to work
> with any CPU speed.
>
> --
> /Jacob Carlborg
>
That's what I did. The framerate isn't clamped, and the threads don't
sleep, there's no spinning going on, I've replaced all of that with
ti
On 8/4/11, Nick Sabalausky wrote:
> There is nothing you've mentioned that can't be (better) fixed without
> cramming everything into a browser.
Where would you cram it then? Put MSN inside the game itself?
I liked QLive before they forced 30 second commercials on server joins
for non-subscribers. :(
It was cool being able to casually browse to other tabs, then going
back to qlive and finding a game.
UT for example had an integrated IRC client, but people preferred
using mIRC and having a ut://123.1
On 8/3/11, Andrej Mitrovic wrote:
> if ((t - t_prev).usecs > (1_000_000.0 / FPS))
> {
> t_prev = t;
> DrawGLScene();
> }
>
> SwapBuffers(hDC);
My mistake here, SwapBuffers belongs inside the if body, there's an
unrelated keyboard bug t
On 8/3/11, Jacob Carlborg wrote:
> Why would you want to slow down framerate?
Because the examples were written in the 90s and CPUs and graphic
cards are so fast these days that the old code runs at an enormous
framerate.
Anyway, after a bit of googling I've found a solution:
enum float FPS = 6
801 - 900 of 1567 matches
Mail list logo