On Thursday, 21 August 2014 at 12:58:13 UTC, MarisaLovesUsAll
wrote:
I found a rough solution. It's not ideal and I still want to
make autoinject, but it works.
mixin template Manager(T) {};
class Component {};
class Sprite:Component
{
mixin Manager!Sprite;
};
1) How to make mixin inject
On Thursday, 21 August 2014 at 14:09:24 UTC, Ricky C wrote:
I'm trying to make a tree data structure in part of my first
non-trivial D-based program. Turns out that DMD likes to
re-use PODs - sounds good, but that trapped me, and I'm not
sure how to clear myself out of the problem nicely.
On Thursday, 21 August 2014 at 19:58:18 UTC, MarisaLovesUsAll
wrote:
When I make mixin injection in one class, I want auto-injection
in another class. How can I do this?
class Component:GameObject
{
//second injection must be here and must be automatic
};
class Sprite:Component
{
On Thursday, 21 August 2014 at 20:05:13 UTC, Ary Borenszweig
wrote:
I'll tell you how it's done in Crystal in case someone wants to
come up with a proposal to make it work in D.
~~~
class Foo
macro inherited
def method_in_{{@class_name.downcase.id}}
puts Hello {{@class_name.id}}!
Dlang Dlang Über Alles
as a German, O_O
On Wednesday, 20 August 2014 at 21:43:26 UTC, Walter Bright wrote:
On 8/20/2014 2:33 PM, anonymous wrote:
Dlang Dlang Über Alles
as a German, O_O
I'm not surprised that the German programming community has
taken to D. After all, German cars all have those D stickers
on them :-)
No, no,
On Wednesday, 20 August 2014 at 15:11:53 UTC, Dominikus Dittes
Scherkl wrote:
I have several times seen a construct
template foo(T...) if(T.length == 1)
{
...
}
What is that good for?
Why using variadic parameter if anyway exactly one parameter is
required?!?
That's because template
On Wednesday, 20 August 2014 at 20:17:49 UTC, Newbie wrote:
#!/usr/bin/gdc
import std.stdio;
void main()
{
writeln(Hello, world with automated script running!);
}
When I compile the code above normal to an a.out binary it runs
like expected. But running it with shebang it does nothing. No
On Monday, 18 August 2014 at 15:35:26 UTC, Uranuz wrote:
date.day++;
date.day -= 5;
Should be treated as:
date.day = date.day + 1;
date.day = date.day - 5;
if the were not oveloaded. So if we have get and set property
methods I see that it could be calculated and this should
working.
This
On Monday, 11 August 2014 at 13:00:27 UTC, John Colvin wrote:
can someone talk me through the reasoning behind this:
import std.typetuple;
void foo(T)(T v){}
void foo(){}
version(ThisCompiles)
{
alias Parent = TypeTuple!(__traits(parent, foo))[0];
pragma(msg, __traits(getOverloads,
On Monday, 11 August 2014 at 18:21:04 UTC, Baz wrote:
interface itf{
void a_int(int p);
void a_uint(uint p);
}
[...]
// FAILS because: alias are probably generated after the itf
check
class impl3: itf{
void tmp(T)(T p){};
alias a_int = tmp!int;
alias a_uint = tmp!uint;
}
On Tuesday, 12 August 2014 at 12:08:14 UTC, John Colvin wrote:
I think the problem is that impl3.tmp is not virtual because
it's
a template, and interfaces need to be implemented by virtual
methods.
The instantiations of the template are just normal functions
though, no?
They are not
On Sunday, 10 August 2014 at 15:37:41 UTC, seany wrote:
On Sunday, 10 August 2014 at 15:34:30 UTC, ketmar via
Digitalmars-d-learn wrote:
from D side -- yes. just don't store passed pointer on C side,
'cause
it can be changed on array resize.
Excellent,
So if I have
int [] array;
void *
On Friday, 8 August 2014 at 17:07:37 UTC, seany wrote:
And as discussed earlier, I was trying to save the pointers in
an ulong (which is same as size_t or ptr_t, those are aliased)
(when compiling for x86-64 that is)
Generally, casting pointers to size_t is a horrible idea. Why
can't you at
On Monday, 4 August 2014 at 22:00:18 UTC, splatterdash wrote:
```
File f = File(input_file)
// detect gzip ...
if (isGzip)
{
auto fileIter = new MyFileReader!GzipIterator(f)
}
else
{
auto fileIter = new MyFileReader!NormalIterator(f)
}
foreach(string line; fileIter) {
// do
On Monday, 4 August 2014 at 22:18:24 UTC, splatterdash wrote:
Indeed I do. I'm not sure which type I should use for the
common base type, though. MyFileReader is a templated class, so
using it plainly did not work. I also tried `InputRange!string`
to no avail despite `MyFileReader`
-- Functions --
Ref implies the type is a reference type, i.e. changes inside
the functions will change the variable outside the function. in
means immutable out is an alias for ref(preferably used for
parameters)
`ref` doesn't imply a reference, it declares or states or
something.
`in`
On Sunday, 3 August 2014 at 10:57:26 UTC, Bayan Rafeh wrote:
-- Functions --
Ref implies the type is a reference type
[...]
`ref` doesn't imply a reference, it declares or states or
something.
I'm basing this on the wiki: http://dlang.org/function.html
ref parameter is passed by
On Sunday, 3 August 2014 at 19:07:32 UTC, Vlad Levenfeld wrote:
bool less_than (T)(auto ref T a, auto ref T b)
{
return a b;
}
Error: auto can only be used for template function parameters
Works for me with dmd versions back to 2.060. What compiler are
you using?
On Sunday, 3 August 2014 at 19:30:38 UTC, Vlad Levenfeld wrote:
On Sunday, 3 August 2014 at 19:26:28 UTC, anonymous wrote:
Works for me with dmd versions back to 2.060. What compiler are
you using?
dmd 2.065
Here's how I'm testing this:
$ dmd | head -n 1
DMD64 D Compiler v2.065
$ cat
On Sunday, 3 August 2014 at 22:01:23 UTC, matt wrote:
auto value(Parent item, int type)
{
if(item.type == 1)
{
return Fun!double(cast(Child!double)item);
Here you're returning a double.
}
else if(item.type==2)
return
module test;
import std.stdio;
class buffer(T, size_t sz) {
auto arr = new T[sz];
enum end = sz-1;
}
void foo(T, size_t sz)() {
auto buf = new buffer!(T,sz);
writeln(before , buf.arr);
foreach(ref ele; buf.arr) ++ele;
writeln(after , buf.arr);
}
Whoops, that is writeln(a ,a.arr); and so on.
On Thursday, 31 July 2014 at 18:51:09 UTC, Sean Kelly wrote:
This looks like an optimizer bug. Do you see the same result
with -release set vs. not, etc?
I get it regardless of -release or -O.
Replacing the arr declaration with T[sz] arr; fixes the problem.
On Thursday, 31 July 2014 at 21:50:25 UTC, Eric wrote:
objdump -d -M intel simpleOctal
Not sure what the switches are for;
-d
disassemble - Essential if you want to, well, disassemble.
-M intel
Intel syntax - Because no one likes ATT syntax. Wikipedia has a
comparison:
Random guy here. I think the redesign is good. Populating the On
This Page box with the function, enum etc. names would be nice.
Preserving some form of site/page link navigation in the narrow
mode is essential, be it switching to boxes at the top/bottom of
the page or minimizing/maximizing
On Thursday, 24 July 2014 at 04:53:41 UTC, Manu via Digitalmars-d
wrote:
struct S(size_t len = 10)
{
ubyte[len] data;
}
S!100 x; // this works fine
S y; // this doesn't work (!)
S!() z; // this works
The template arg has a default arg, why require !() ??
So that the type S!() is (easily)
On Thursday, 24 July 2014 at 06:17:26 UTC, Manu via Digitalmars-d
wrote:
On 24 July 2014 16:02, anonymous via Digitalmars-d
digitalmars-d@puremagic.com wrote:
On Thursday, 24 July 2014 at 04:53:41 UTC, Manu via
Digitalmars-d
wrote:
[...]
This causes problems in meta code, where you want
On Tuesday, 22 July 2014 at 16:50:47 UTC, Eric wrote:
private void getNumber(MCInputStreamRange buf)
{
auto s = buf.until(a = '0' || a = '9');
curTok.kind = Token_t.NUMBER;
curTok.image = to!string(s);
}
The problem is that until seems to not stop at the end of the
number,
and
On Sunday, 20 July 2014 at 15:48:19 UTC, Uranuz wrote:
Sorry, but this example doesn't work too.
Ugh, 2.065 doesn't like it, but it works for me with git head
(v2.066-devel-82b031c).
On Sunday, 20 July 2014 at 16:47:30 UTC, Uranuz wrote:
Where did you get it? Or you compiled it yourself?
I'm building it myself. It's not difficult, when you know basic
git. And it doesn't take long. You can find instructions here:
http://wiki.dlang.org/Building_DMD
Because I tried beta4
import std.stdio;
interface IBase
{
template getStr(string fieldName)
{
final string getStr()
{
return George;
}
}
string getStr(string fieldName);
}
class
On Tuesday, 15 July 2014 at 14:05:14 UTC, Alexandre wrote:
Strange..., why '@' ?
because x40 == @
struct Subscription {
const Object handle;
private immutable size_t index;
@disable this();
private this(Object o, size_t i) {
handle = o;
index = i;
}
}
I'd like this to be constructed with a handle to some object, and
On Tuesday, 15 July 2014 at 17:06:14 UTC, Ali Çehreli wrote:
On 07/15/2014 09:39 AM, Anonymous wrote:
struct Subscription {
const Object handle;
private immutable size_t index;
@disable this();
private this(Object o, size_t i) {
handle = o;
index =
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote:
Hi,
I noticed that in Andrei's talks and his book, he used braces
on the same line of delcaration, however Phobos and other D
libraries I know use braces on their own line. Now I'm in a
position where I need to take decision on
I got to typing one day and came up with this. What it does is
search an aggregate for a member named match. If it's a direct
member, it evaluates to that. If it's not, then it searches any
aggregate type sub-members (deep members) for match. If there's
only one deep member tree with match, it
One way I've used it in code
struct MapBy(T,string key) if (hasDeepMember!(T,key)) {
alias key_t = DeepMemberType!(T,key);
private const(T)[key_t] _map;
bool has(key_t id) const nothrow {
if ((id in _map) != null) return true;
else return
On Friday, 11 July 2014 at 16:10:31 UTC, Nordlöw wrote:
Is there a trait to check if a type is a
- value type (struct, static array, etc)
- reference type (class, dynamic array, string, etc)
?
There's http://dlang.org/phobos/std_traits.html#hasIndirections
Note that structs and static
On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote:
Here's a code example:
module main;
import foo;
enum Get = GET;
void bar (string a)
{
assert(a is Get);
}
void main ()
{
asd();
}
module foo;
import main;
void asd()
{
bar(Get);
}
Running the above code will
On Wednesday, 9 July 2014 at 17:13:21 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
For the comparison s u, where s is a signed value and u is an
unsigned
value, whenever s is negative, the return value of opCmp must be
negative. Assuming 2's-complement representation of integers,
this
On Tuesday, 8 July 2014 at 19:40:59 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
template TypesOf(T...)
{
static if (T.length == 1)
alias TypesOf = typeof(T[0]);
else
alias TypesOf =
On Monday, 7 July 2014 at 12:06:21 UTC, Frédérik wrote:
I'm trying to achieve something like that (approximate D code):
interface MyObjectSet
{
void add(MyObject o);
void SortedRange!MyObject opSlice();
}
class SomeRedBlackBasedImplementation
{
private RedBlackTree!MyObject
On Monday, 7 July 2014 at 14:51:37 UTC, Fr wrote:
The solution of making an array from the range works, but I'm
concerned about the cost of instantiating a (potentially very
large) array each time I need to walk across the set. Unless
doing that is costless in D for any reason, it does not
On Monday, 7 July 2014 at 19:20:24 UTC, Fr wrote:
On Monday, 7 July 2014 at 16:58:51 UTC, anonymous wrote:
No array is created in the example. Where do you think an array
is created?
It's in the example above :
SortedRange!(MyObject[]) opSlice() {
sequence[].array.assumeSorted; }
I
On Monday, 7 July 2014 at 20:10:10 UTC, Archibald wrote:
Using std.algorithm.sort(a,b,c,d,e) I get the error message :
core.exception.AssertError@C:\dmd\windows\bin\..\..\src\phobos\std\algorithm.d(1
0350): Predicate for isSorted is not antisymmetric. Both
pred(a, b) and pred(b,
a) are true
On Thursday, 3 July 2014 at 21:06:12 UTC, Jet wrote:
There, how to distinguish between const and immutable? thank
you~:)
/**
Const types are like immutable types, except that const forms
a read-only view of data. Other aliases to that same data may
change it at any time.
Any data
On Thursday, 3 July 2014 at 20:43:33 UTC, Jet wrote:
void foo(immutable int* x, int* y) {
bar(*x); // bar(3)
*y = 4; // undefined behavior
bar(*x); // bar(??)
}
...
int i = 3;
foo(cast(immutable)i, i);
--
In the 2.065 version, I can compile. But that is not in
On Thursday, 19 June 2014 at 22:22:33 UTC, w0rp wrote:
I haven't yet figured out a good way to make opApply
implementations get all of the nice qualifiers without writing
a bunch of overloads.
I don't know how practical this is, but since attributes are
inferred for templated methods ...
That really is it. The other methods are just other gets to the
buffer, like this:
T[] get_dup(TS strat=TS.cyclic)(size_t n) const {
static if (strat==TS.once) size_t numreads = fixNToFill(n);
else size_t numreads = n;
auto ret = new T[](numreads);
On Friday, 13 June 2014 at 18:18:21 UTC, H. S. Teoh via
Digitalmars-d wrote:
Aliasing super.prop to .prop in the derived class didn't work,
in fact,
it made things worse; now I have an infinite loop because all
occurrences of .prop get redirected back to the base class
(including
the setter),
This seems to work from quick testing, but it has casts in
get_ref that I want to avoid.
cast(T*) refs[i] is obviously not @safe.
cast(T*) _buffer[read].ptr doesn't seem necessary, since
_buffer[read] is conceivably a T so _buffer[read].ptr should be a
T*. But without it I get Error: cannot
On Saturday, 7 June 2014 at 20:53:03 UTC, Paul wrote:
I can not understand, why this code works:
char s[2] = ['0', 'A'];
string ss = to!string(s);
writeln(parse!uint(ss, 16));
but this can deduces template:
char s[2] = ['0', 'A'];
writeln(parse!uint(to!string(s), 16));
On Saturday, 7 June 2014 at 21:18:39 UTC, Denis Martinez wrote:
Thanks for the answer Chris, you are correct.
I was expecting the closure to work similarly to Clang's
blocks, which apparently it does not. I guess that delegates
pass by copy, like structs do.
So far I have tried a variety of
On Wednesday, 4 June 2014 at 23:25:13 UTC, cal wrote:
I have the following code (on dpaste,
http://dpaste.dzfl.pl/636c04430a33):
enum : uint { a, b, c }
enum list = [a, b];
void foo(T...)()
{
pragma(msg, T[0].length); // fine
pragma(msg, T[0][0]); // fine
pragma(msg, T[0][1]);
On Friday, 30 May 2014 at 13:35:59 UTC, Thomas wrote:
I made the following performance test, which adds 10^9 Double’s
on Linux with the latest dmd compiler in the Eclipse IDE and
with the Gdc-Compiler also on Linux. Then the same test was
done with C++ on Linux and with Scala in the Java
On Friday, 30 May 2014 at 12:35:46 UTC, francesco cattoglio wrote:
class MyClass {
[...]
const (Foo) getQ () const { return _Q; } // OK
// const Foo getQ () const { return _Q; } // fails
}
[...]
I don't really understand what's going on here. Why is const
Foo getQ() wrong?
On Friday, 30 May 2014 at 12:57:52 UTC, anonymous wrote:
The const in the front is the same as the front in the back.
... the same as the const in the back
With VS2013 installed, I had an issue with the DMD installer's
config. mspdb*.dll are located in VC/bin, not VC/bin/x86_amd64,
and using -m64 caused a linker error. Adding %VCINSTALLDIR%\bin
to sc.ini's PATH fixed the problem and produced a working hello
world with -m64.
On Tuesday, 20 May 2014 at 20:15:09 UTC, Dominikus Dittes Scherkl
wrote:
/// create a fixed size array with the given name and with
*max* entries
max + 1 entries
/// of immutable values of the same type as the return value of
the
/// given function.
/// it contains the values of that
On Tuesday, 20 May 2014 at 21:16:26 UTC, monarch_dodra wrote:
enum ReturnType!fn[length] lookupTable = [elements];
Depending on what the usecase is, you might want to change that
to static immutable instead:
static immutable ReturnType!fn[length] lookupTable = [elements];
Remember that
On Tuesday, 20 May 2014 at 21:48:08 UTC, Timon Gehr wrote:
Wtf. Is this really the point you are trying to make? :o)
This achieves the same:
template lookupTable(alias fn,uint max=255){
static assert(maxuint.max);
enum ReturnType!fn[max+1]
lookupTable=iota(0,max+1).map!fn.array;
}
On Monday, 19 May 2014 at 11:36:43 UTC, Darren wrote:
String hexnum = 16D81B16E091F31BEF;
string (lowercase)
I'd like to convert it into a ubyte[] in order to Base64 encode
it (or, indeed ASCII85 or Base32).
eg, [16, D8, 1B, 16, E0, 91, F3, 1B, EF]
Is there an idiomatic/simple way to do
On Tuesday, 13 May 2014 at 19:53:17 UTC, Tim Holzschuh via
Digitalmars-d-learn wrote:
If I also want to create a RegEx to filter string-expressions a
la xyz , how would I do this?
At least match( src, r^\ (.*) $\ ); doesn't seem to work
and I couldn't find in the Library Reference how to
On Friday, 9 May 2014 at 05:26:12 UTC, Arne Ludwig wrote:
Hello,
when using opApply it seems natural to have two versions: one
normal and one const. My problem is that I cannot find a way to
describe both versions with one code block. Since there could
be a number of basic variants with
On Friday, 9 May 2014 at 14:23:41 UTC, Luís Marques wrote:
If you have an array of structs, such as...
struct Foo
{
int x;
int y;
}
Foo[] foos;
...and you wanted to sort the foos then you'd do something
like...
foos.sort!(a.x b.x),
..and, of
On Friday, 2 May 2014 at 10:23:03 UTC, Andrej Mitrovic via
Digitalmars-d-learn wrote:
Ouch, ouch, ouch! What's happening is that the 'clear' Appender
method
is only compiled-in if the data is mutable, otherwise you end up
calling the object.clear UFCS function. So don't use clear here.
I don't
On Thursday, 1 May 2014 at 10:42:36 UTC, Unwise wrote:
In the following example from the documentation, are strings
concatenated at compile time?
template foo(string s) {
string bar() { return s ~ betty; }
}
void main() {
writefln(%s, foo!(hello).bar()); // prints: hello betty
}
I
On Tuesday, 29 April 2014 at 09:57:08 UTC, ketmar wrote:
On Monday, 28 April 2014 at 15:57:16 UTC, anonymous wrote:
`zmod.symbol` works, too.
no, it's not. at least on latest GDC.
Works for me with Ubuntu's gdc 4.8.2-1ubuntu6. My little test
case:
my/module_.d:
---
module my.module_;
On Tuesday, 29 April 2014 at 11:23:56 UTC, ketmar wrote:
ah, don't you believe that i *really tested* it before posting,
with latest GDC from git (which i builds routinely on dayly
basis)?
You may have made mistakes when testing, or maybe I have. That's
why I provided my testcase. Does it
On Monday, 28 April 2014 at 00:52:50 UTC, ketmar wrote:
module my.module;
public import other.module;
…
module mainprogram;
import my.module;
now i can access other.module symbols without qualifiers
and another case:
module mainprogram;
import zmod = my.module;
now i CAN'T access
On Monday, 21 April 2014 at 19:40:01 UTC, Plorf wrote:
I downloaded the DMD Windows compiler, installed it in the
default directory, added its location to the system path,
restarted my computer and wrote a sample hello, world
program, and it won't compile; instead it says Error: cannot
read
On Sunday, 20 April 2014 at 18:08:19 UTC, Frustrated wrote:
In D though, I guess because of the GC(but which is why I am
asking because I don't know specifically), classes could be
much slower due to all the references causing the GC to take
longer scan the heap and all that. If allocate or
801 - 873 of 873 matches
Mail list logo