OT: Just saw fill() by accident and something caught my eye:
char[100] a;
fill(a[], bla); // fail, ok
int[100] a;
fill(a[], bla); // works
It could be a constraint issue. To bugzilla?
Where do you see those literals? I'm only seeing strings.
Have you tried https://github.com/JakobOvrum/LuaD ? It has binaries
here: http://github.com/JakobOvrum/LuaD/tree/binaries
foreach_reverse isn't going to help you much since AA's do not save
the order of the keys. A quick workaround:
http://pastebin.com/KkECqwUU
Others probably know efficient ways to do this.
Is there a Phobos function to compress all spaces to just one space in a string?
E.g. foo bar
becomes: foo bar
Oh cool, it even takes an optional parameter. Thanks!
On 2/21/12, bearophile bearophileh...@lycos.com wrote:
Andrej Mitrovic:
Is there a Phobos function to compress all spaces to just one space in a
string?
E.g. foo bar
becomes: foo bar
import std.string;
void main
N, it wasn't me. I keep having to tell this to people, it was
taken from http://www.dsource.org/projects/bindings/wiki/WindowsApi
but it often doesn't compile with the latest compiler version so I
keep it updated inside my project.
On 2/21/12, bearophile bearophileh...@lycos.com wrote:
Andrej Mitrovic:
Is there a Phobos function to compress all spaces to just one space in a
string?
E.g. foo bar
becomes: foo bar
import std.string;
void main() {
assert( foo bar .squeeze() == fo
class Foo
{
this(int) inout
{ }
Foo makeFoo() { return new Foo(1); }
}
void main() { }
test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of
type inout(Foo) to test.Foo
Is this a bug?
Hmm nevermind. The param type had to be inout, but to do that the ctor
itself has to be inout. Somehow I managed to put the inout specifier
in the wrong place when testing, I did this:
this(inout(void*) obj) { } inout
which is not the same as this:
this(inout(void*) obj) inout { }
Damn specs.
On 2/24/12, simendsjo simend...@gmail.com wrote:
I don't get it. This gives me a dynamic array, not a static:
char[1] a;
auto b = cast(void*)a;
auto c = (cast(char*)b)[0..1];
c.length = 10; // auch!
You can do:
char[1] c = (cast(char*)b)[0..1];
Well first I'd recommend not allocating the struct on the heap. Then you can do:
import std.stdio;
struct nagger
{
string name;
int age;
double weight;
string msg;
}
void main()
{
nagger lal;
lal.name = name;
lal.age= 23;
lal.weight = 108.5;
lal.msg
On 2/25/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
This doesn't work for heap-allocated structs.
Sorry my bad. .sizeof should always be set on Types and not variable
names, because a struct pointer will have sizeof == size_t, whereas a
simple struct variable will have sizeof equal
On 2/25/12, Ali Çehreli acehr...@yahoo.com wrote:
That passes because lal.name.ptr and dup.name.ptr have the same value.
Maybe that wasn't the intention but the data is not really in the file.
I'm not sure where you're getting that from:
import std.stdio;
struct nagger
{
string name;
To be honest the C fread and fwrite aren't even necessary since you
can do a rawRead and rawWrite instead.
On 2/25/12, Ali Çehreli acehr...@yahoo.com wrote:
But there is no way for fwrite to follow name.ptr to also write the
characters that are in the string, right?
Oh my I just got a big fat zero on the finals. You're absolutely
right, what gets copied is the length and the pointer. The only reason
On 2/26/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
allocated on the stack
Sorry, I meant the data segment not the stack. That's -1 score for me.
On 2/25/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
I'm not sure where you're getting that from:
Let that be a classic lesson on what never to do. Here's a
demonstration on how wrong I was:
import std.stdio;
struct Foo
{
char[] name;
}
void main(string[] args)
{
if (args[1
On 2/25/12, Ali Çehreli acehr...@yahoo.com wrote:
Apparently template parameters
with default values need not be at the end of the template parameter list
Well it would make variadic templates rather hard to use if this was illegal:
void print(bool pretty = false, T...)(T args) { }
void main()
On 2/27/12, Ali Çehreli acehr...@yahoo.com wrote:
D is awesome compared to C as it enables serializing/deserializing data
with its generic programming and compile-time reflection features like this:
http://dlang.org/traits.html#allMembers
ae's json uses .tupleof, and does it in 40(!)*
The immutable is not necessary, use:
auto h = new Parser!(Type.request)(Hello world);
Otherwise, if you really want to declare the type instead of infering
it you can write:
Parser!(Type.request) h = new Parser!(Type.request)(Hello world);
You can also do:
Parser!(Type.request) h;
h = new
On 2/27/12, Tyler Jameson Little beatgam...@gmail.com wrote:
That's why I thought this model would be so cool, because
I could remove conditions from the generated code, and get rid of a lot of
the conditionals.
I think Nick Sabalausky talks about this concept (removing
conditionals via
Also you can force property calls in your code if you compile with
-property. Property notation has not been enforced so far, but might
be in the future afaik.
On 2/29/12, James Miller ja...@aatch.net wrote:
Today I Learned that windows has insane escaping.
You won't have to worry about it for long:
https://github.com/D-Programming-Language/phobos/pull/457
Just noticed there's an std.traits import missing. I hate how D
silently ignores that FunctionTypeOf is left undefined.
On 2/29/12, Jacob Carlborg d...@me.com wrote:
Seems like what I have in my serialization library Orange:
Sweet. I was gonna take a look at Orange for just this purpose. Thanks.
On 2/29/12, Philippe Sigaud philippe.sig...@gmail.com wrote:
Nice. What does it give for:
- function overloads (PITA that)?
- type aliase (alias int Int;)?
- function aliases or member aliases?
- inner templates (struct template, etc, not pure template as these are not
allowed in a struct)?
On 2/29/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
Just noticed it doesn't work ok if there's a nested template
declaration in a struct. It would say Error: cannot resolve type for
t.temp(T).
Correction: it was the unittest block that was problematic. I've filed
it http
Boom: https://bitbucket.org/stqn/profiled
I've never used it though.
Luckily you can always use alias this and overload opCatAssign. 'alias
this' is a great tool for customizing APIs. :)
SDL_LoadBMP is declared as:
SDL_Surface *SDL_LoadBMP(const char *file);
http://www.libsdl.org/cgi/docwiki.cgi/SDL_LoadBMP
So you don't need a mutable char*. I'd recommend using Derelict since
it already has all these prototypes declared properly.
Is there a reason why there's no .empty property for hashes? std.array
defines it for arrays, and range types must have it defined. But
hashes are left out even though they define .length. This could be put
in std.array:
@property bool empty(T)(in T a)
if (isAssociativeArray!T)
{
return
Well, there is a way but it might wreak havoc on your object size
since it will instantiate a lot of templates. Therefore it would be a
good thing to only do it in debug mode:
import std.string;
class A
{
int opIndexDebug(int line = __LINE__, string file = __FILE__)(int x)
{
/*
On 3/3/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
throw new Exception(format(%s: %s, file, line));
That format is unnecessary but anywho. :)
Err wait a minute, that debug/else thing doesn't quite work well.. I
thought it would.
Ok this works: http://paste.pocoo.org/show/560103/
On 3/3/12, Adam D. Ruppe destructiona...@gmail.com wrote:
Since some time last year, it works on all functions, just
use regular default parameters:
Right, but what about template bloat? DMD doesn't seem to merge these
templates. It can try to inline them, but it's very easy to break the
Ah yeah, I forgot about those.
int opIndex(int x, int line = __LINE__, string file = __FILE__)
Tada. I overcomplicated.
On 3/3/12, bioinfornatics bioinfornat...@fedoraproject.org wrote:
I think __LINE__ is size_t not int
I'd love to see a 2_147_483_648 line source file! :D
On 3/3/12, H. S. Teoh hst...@quickfur.ath.cx wrote:
Of course, with D's templates, CTFE, and compile-time introspection
capabilities, I can't imagine when autogeneration would actually be
required, but we're talking about hypotheticals here.
It can be if you need an OOP D binding to a C/C++
import std.stdio;
void check() { writeln(check); }
struct Foo { bool isTrue = true; }
struct Bar { }
void test(T)(T t)
{
static if (is(T == Foo))
{
if (t.isTrue)
check();
}
else
{
check();
}
}
void main()
{
Foo foo;
Bar bar;
Ok, well a quick search shows socket.d:132 needs fixing. Also there's
two versioned out enforces in object_.d which use int line = __LINE__.
Interestingly, earlier versions of Phobos used int a lot (I guess in
pre-64bit compatible D days). I'm also seeing int used in Derelict,
pspemu, plot2kill
You're right it should be able do that dead-code elimination thing.
Slipped my mind. :)
On 3/4/12, Daniel Murphy yebbl...@nospamgmail.com wrote:
Andrej Mitrovic andrej.mitrov...@gmail.com wrote in message
news:mailman.364.1330825349.24984.digitalmars-d-le...@puremagic.com...
import std.stdio
On 3/4/12, Daniel Murphy yebbl...@nospamgmail.com wrote:
void f(Args...)(Args args) {
foreach(i, T; Args)
{
static if (isSomeString!T) args[i] = toUTFz(args[i]);
}
needs_wchar_t(args);
}
toUTFz returns a pointer, the isSomeString checks if a type is a
string. IOW that will try
There's a really useful function 'translate' in std.string, used like this:
__gshared dchar[dchar] MangleTable;
shared static this()
{
MangleTable =
[
'*':'p', // ptr
'':'r', // reference
'':'L', // left angle
'':'R', // right angle
' ':'_',
Hmm somehow I missed that. Thanks.
On 3/6/12, Ali Çehreli acehr...@yahoo.com wrote:
On 03/05/2012 04:32 PM, Andrej Mitrovic wrote:
There's a really useful function 'translate' in std.string, used like
this:
__gshared dchar[dchar] MangleTable;
shared static this()
{
MangleTable
You can use a cast as a workaround:
A[] objs = [cast(A)new B, new C ];
This bug has been around for a while, the first time I've seen it
mentioned was in the second code snippet in this blog post:
http://klickverbot.at/blog/2010/11/announcing-d-support-in-swig/
On 3/6/12, Trass3r u...@known.com wrote:
Sadly, using regular expressions is much more efficient.
Do you have some script that does that and sorta works? I've tried
others (e.g. dstep but couldn't get LLVM to compile unfortunately..).
On 3/7/12, Timon Gehr timon.g...@gmx.ch wrote:
The problem is not that length is unsigned. The issue is the implicit
conversion from signed to unsigned.
You bet. I've once had this hard to spot bug where I've used a call
that was something like max(0, min(10, expression)), and this ended
up
Don't worry Ali I thought the same thing. :p
I find it interesting that having this feature would somehow enable
abuse, yet we can do so much abuse already with CTFE, templates, and
string mixins. One large pain in the ass is to pass an integral at
compile time. I sometimes wish to use a syntax such as version(foo ==
5) {}. The only
I have a felling people will end up abusing string mixins to generate
version statements, and this will be the exact opposite effect Walter
wanted. The same story goes for unittests which can't be independently
ran to get a list of all failing unittests, and so people are coming
up with their own
Yeah I understood it as a general concept as well. Probably many
people did. Why doesn't Andrei chime in?
On 3/9/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
Yeah I understood it as a general concept as well. Probably many
people did. Why doesn't Andrei chime in?
Btw, we all know how much Andrei loves generics so why the heck would
he care about arrays so much to only give them special
On 3/9/12, Timon Gehr timon.g...@gmx.ch wrote:
On 03/09/2012 07:08 PM, Andrej Mitrovic wrote:
Yeah I understood it as a general concept as well. Probably many
people did. Why doesn't Andrei chime in?
I think he does not read the D.learn newsgroup.
Ah poo. This is like East Berlin in here
It took me a while to narrow this down:
struct Foo
{
int val = int.init;
this(inout(int) nval) inout {
this.val = nval;
}
}
test.d(18): Error: cannot modify const/immutable/inout expression this.val
Is there any special reason why this should be disallowed? I mean the
same
Does anyone else think this should be fixed?
import std.conv;
void main()
{
string s1 = ff;
string s2 = 0xff;
assert(parse!uint(s1, 16) == 0xff); // ok
assert(parse!uint(s2, 16) == 0xff); // fail, it's 0
}
I think parse should pop the first two characters if the string starts
Side-note, it would be nice if std.string.isNumeric took a radix. :)
Thanks for the input. http://d.puremagic.com/issues/show_bug.cgi?id=7692
On 3/12/12, Ali Çehreli acehr...@yahoo.com wrote:
Let's please also see the exact error message. an error message that
seems to indicate that DMD is looking for a global identifier is not
clear to mortals like myself. :)
He probably means something like this:
struct State { }
struct Input { }
I've completely lost track of what happened with the whole toUTF16z
story, but anyway since it's in std.utf why doesn't it just forward to
toUTFz?
const(wchar)* toUTF16z(T)(T input)
if (isSomeString!T)
{
return toUTFz!(const(wchar)*)(input);
}
That way it can take any string argument and
On 3/13/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
I've completely lost track of what happened with the whole toUTF16z
story
Btw, to!string still doesn't work with wchar* arguments. I currently
use this hack:
wstring fromUTF16z(in wchar* s)
{
if (s is null) return null
On 3/14/12, Jonathan M Davis jmdavisp...@gmx.com wrote:
As I understand it, auto ref is supposed to work with _any_ function. The
_compiler_ decides whether it's best to use a ref or a value.
I never really understood the need for 'const ref' with structures. If
the compiler knows the size of a
On 3/14/12, Alex Rønne Petersen xtzgzo...@gmail.com wrote:
void foo(S s) // compiler decides to pass by ref
{
s = S(2);
}
Well in this case it wouldn't pass by ref since it sees an assignment.
But I can see how this would become tricky business (e.g. why is my
code slow all of a sudden).
On 3/15/12, H. S. Teoh hst...@quickfur.ath.cx wrote:
It's correct, albeit a bit ugly. To alleviate the ugliness, you can tell
the compiler where the root directory for the library is supposed to
be. For example, if you invoked dmd with -ILibraries/Math, then you'll
be able to say:
On 3/21/12, Pedro Lacerda kanvua...@gmail.com wrote:
Ouch, void* is the same in both languages, sorry. I addressed a new problem:
typedef struct SomeFunctions {
void *(*funcA)(char*, size_t);
void *(*funcB)(void);
} SomeFunctions;
How do I convert that functions references into an
On 3/21/12, bearophile bearophileh...@lycos.com wrote:
Are you sure that works?
It's easy to test:
extern(C)
struct SomeFunctions {
void function(char*, size_t) funcA;
void function() funcB;
}
void main()
{
writeln(typeof(SomeFunctions.funcA).stringof);
}
On 3/21/12, Pedro Lacerda kanvua...@gmail.com wrote:
dnewbie, you're correct, the return type is void* instead of void.
I didn't notice the pointer thanks to the silly C function pointer syntax. :)
On 3/22/12, Tyro[17] nos...@home.com wrote:
issue #2
how do i read a string[] such that whitespace (all or one of
my choosing) delineate the string boundary?
Jesse Phillips has a cmdln.interact library that I think would work by using:
string[] result = userInput!(string[])(Enter
On 3/23/12, Ed McCardell edmcc...@hotmail.com wrote:
Is there a way to write a template constraint that matches any
specialization of a given type?
Nope. But there are simple workarounds:
class Foo(bool feature1, bool feature2) { enum _isFoo = true; }
template isFoo(T) {
enum bool isFoo =
On 3/23/12, Philippe Sigaud philippe.sig...@gmail.com wrote:
testFoo is a function that accepts any Foo!( ... ) for any ... The
second line tests it on a value of type T (T.init).
That can't work. For a Foo!int your code will expand like so:
// original code
void tester(Args...)(Foo!Args
On 3/23/12, bearophile bearophileh...@lycos.com wrote:
This is one way to do it:
immutable(char)** p = array(map!toStringz(data)).ptr;
This is asked so frequently that I think we could consider adding it to Phobos.
On 3/23/12, Philippe Sigaud philippe.sig...@gmail.com wrote:
It works for me
Yes but check the isA template. It seems there's something causing a
nested variadic template to fail. This won't work in a template
constraint (it returns false):
template isA(alias Foo)
{
template isA(T)
{
Does someone have a map implementation that maintains the insertion
order of the keys?
E.g.:
string[string] map;
map[foo] = x;
map[bar] = y;
When iterating over map keys I want to visit foo first, then bar, and so on.
On 3/23/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
Does someone have a map implementation that maintains the insertion
order of the keys?
Here's a sloppy implementation:
module test;
import std.stdio;
import std.traits;
template KeyType(V : V[K], K)
if (isAssociativeArray!(V[K
On 3/24/12, Jonathan M Davis jmdavisp...@gmx.com wrote:
I can't think of any data structure that does that off the top of my head
Java has it and they call it a LinkedHashMap:
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/LinkedHashMap.html
That _does_ require having two data
On 3/24/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
On 3/23/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
Does someone have a map implementation that maintains the insertion
order of the keys?
Here's a sloppy implementation:
I forgot to make opIndex ref, but also
On 3/24/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
static if (isArray!Value)
{
template isValue(T)
{
enum bool isValue = is(typeof( { Value v; T t; v = t; } )) ||
is(BaseElement!Value == T);
}
}
Correction, it's:
template isValue(T)
{
enum bool isValue
On 3/24/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
Correction, it's:
template isValue(T)
{
enum bool isValue = is(typeof( { Value v; T t; v = t; } ))
|| is(typeof( { BaseElement!Value v; T t; v = t; } ))
|| is(BaseElement!Value == T);
}
Last check not needed, so
I'd like to get a list of indexes into an array that matches a character. E.g.:
a foo a bar a.indexes(a) == [0, 6, 12]
Anything like that in Phobos?
3/28/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
I'd like to get a list of indexes into an array that matches a character.
E.g.:
a foo a bar a.indexes(a) == [0, 6, 12]
Hah I even managed to screw up that bar has an 'a' there. Anywho
this works just fine:
size_t[] indexes(string
On 3/28/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
snip
Also a better name might be 'indices'.
class Foo
{
bool test() { return true; }
}
class Bar
{
this() { foo = new Foo; }
Foo foo;
alias foo this;
}
class FooBar : Bar
{
bool test(int x) { return true; }
alias super.test test;
}
void main() {}
test.d(17): Error: 'this' is only defined in non-static member
On 12/1/11, Kai Meyer k...@unixlords.com wrote:
I'm finding std.json extremely well written, with one glaring exception.
I'm finding it to be crap. The last time I used it I just kept getting
access violations (or was that std.xml? They're both crap when I used
them.). ae.json beats its pants
This is related to wrapping wxWidgets.
One issue with the new wxWidgets 2.9.x series is that there seem to be
more multiply-inherited classes than before. In particular some of the
main classes have become MI classes (e.g. wxApp derives from
wxAppConsole which is now an MI class). Some wrappers
On 4/2/12, Justin Whear jus...@economicmodeling.com wrote:
Classic singly-linked lists must be iterated to determine length, so use
std.range.walkLength on it.
Specifically call it on its range. You can get a range by slicing the
slist, e.g.:
import std.range;
import std.container;
void
On 4/2/12, Justin Whear jus...@economicmodeling.com wrote:
Classic singly-linked lists must be iterated to determine length
I'm no algorithms buff, but I don't understand the benefit of not
storing the length in the SList. What does it cost to maintain an
extra variable? It's a single
On 4/2/12, Steven Schveighoffer schvei...@yahoo.com wrote:
(i.e. sublists are also valid SLists)
I haven't thought of that, good point. :)
On 4/4/12, jicman cabr...@wrc.xerox.com wrote:
imagine this code...
I'm assuming you're using D2.
import core.runtime;
void c()
{
char[] t = Runtime.args[0].dup;
}
void main(char[][] args)
{
int i = 1;
}
.dup is necessary since Runtime keeps the args as a string[] and not a char[][].
There's rmdirRecurse in std.file, but it removes the folder itself as
well as its contents. I'm looking for a function that removes only the
contents of the dir. Is this in Phobos, and if not can we add it?
Otherwise I have to use platform-specific calls to system() like del *.*.
On 4/5/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
Otherwise I have to use platform-specific calls to system() like del *.*.
Actually nevermind that, I can just remove the dir entirely and then
re-create it.
On 4/5/12, Minas minas_mina1...@hotmail.co.uk wrote:
And this is the time execution of the programs
C via GCC (gcc -m32 test.c -o testgcc.exe -std=c99 -lm -O5)
Elapsed Time: 0:00:02.015
D via DMD (dmd test.d -oftestdmd.exe -release -inline -O -noboundscheck)
Elapsed Time: 0:00:08.312
D
On 4/5/12, Jonathan M Davis jmdavisp...@gmx.com wrote:
But it does have the downside of
the new directory possibly not matching the original one with regards to
permissions or ownership
That's a very good point. Since I run all of my code locally I never
run into these issues and so I've never
On 4/8/12, dnewbie r...@myopera.com wrote:
I have a wchar[] and I want to convert it to UTF8
then append a string. This is my code.
import std.c.windows.windows;
import std.string;
import std.utf;
int main()
{
wchar[100] v;
v[0] = 'H';
v[1] = 'e';
v[2] = 'l';
v[3] =
On 4/8/12, Stefan ste...@schuerger.com wrote:
Any good tools for this (link)? So far I only found old .obj
tools from the 90s on the web...
I use objconv. http://www.agner.org/optimize/#objconv
I use this batch script to disasm an .obj file and open the .asm file:
@echo off
setlocal
On 4/9/12, Eyyub eyyub.pangeara...@gmail.com wrote:
Np :D, you don't know how can I do for the example 2 ?
Well for one thing, there are no global operators in D. Others might
help out with writing a proper opBinary that's defined in Value
itself.
On 4/9/12, Jonas jo...@lophus.org wrote:
On Saturday, 7 April 2012 at 22:42:19 UTC, Stefan wrote:
printf is a C function which expects 0-terminated strings. D's
strings are variable-length arrays and not zero-terminated.
Don't use printf. Try using writef instead. Same arguments.
import std.string;
void main()
{
string foo = foo;
string bar = format(%s %s %s, foo);
}
format expects 3 arguments, but what I really want is foo to be used
for all 3 specifiers and not repeat 'foo' 3 times manually. Are there
any format specifiers that do what I want? I've tried using
On 4/9/12, Artur Skawina art.08...@gmail.com wrote:
However, there's no reason why *std.stdio* should expose the raw printf
function - i didn't even realize it did until now...
It either shouldn't be available via std.stdio at all, or something
like this wrapper should be added there, to catch
On 4/9/12, q66 quake...@gmail.com wrote:
Positional specifier works just fine for me.
Which version are you using? I'm on 2.058.
1 - 100 of 1449 matches
Mail list logo