Hi everyone,
Was hoping someone could help me make sense of this bit of C++ code:
class canvas
{
operator HDC() { return _hdc; }
protected:
canvas(HDC hdc): _hdc(hdc) {}
HDC _hdc;
}
>From what I understand, HDC is an alias for HANDLE in Windows. So
they are overloading canvas such th
Thaks to everyone for your assistance.
I requested some assistance with operator overlaoding yesterday
and I really appreciate the assistance provided. However, trying
to incorporate the example just confused me a little more, it does
not meld well with the code I translated from the tutorial I am
reading. I am hoping that one of you ex
bearophile,
You do have a point there, and I actually expected that response.
I would have posted my attempt at implementation, but am unable to
transfer info between the computer I'm typing this message on and
the one I'm programming on at the moment.
I have no problems converting small problems
i can't install dmd or gdc in arch linux from AUR
i don't way?
in dmd:
this the error massage
object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = /usr/include/d
import path[1] = /usr/include/d/druntime/import
in gdc:
i can't install it and i use this command
yaourt -R gdc
== Quote from %u (asm...@hotmail.com)'s article
> i can't install it and i use this command
> yaourt -R gdc
i mean yaourt -S gdc
this is part of the code:
void WritePushPop(cmd command, string segment, int index)
{
string temp = "TextFile.Asm";
AsmFile = new File(temp, FileMode.OutNew );
string x = toString(index);
AsmFile.writeString(
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
> and add /path/to/unzipped/dmd2/linux/bin to your path.
how can i add path ?
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
> On Monday, March 07, 2011 12:10:27 %u wrote:
> > == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
> >
> > > and add /path/to/unzipped/dmd2/linux/bin to your path.
> >
> > ho
is there any different b/w:
auto arr = new int[10];
and
int[10] arr;
?
what is the equivalent for this code in D?
#include
main()
{
struct S { int i; };
struct S s, *s_ptr;
s_ptr = &s;
s_ptr->i = 9;
printf("%d\n", s_ptr->i);
}
I have function which have more than one return, and the code compile and run
but it gives rong result -I guess-, so i use tuple but the compiler can't
return tuple.
how can I return values?
why I can't return tuple?
thanks you all, it works.
last thing, I have this
Tuple!(int,int,int)(1, 2, 3)
how can I use the return values individual?
to be more clear if I rturn tuple(a, b, c) can I write in the code
void main() {
//call the function here
writeln(a);
}
In Patterns of Human Error, the slide 31 point that you should replce int with
size_t
why that consider an error ?
size_t val1 = int.max+1;
int val2 = int.max+1;
writeln(val1); // 2147483648
writeln(val2); // -2147483648
very clear example
thanks you both
I have a question,
can I write all functions like this object.function() instead of
functin(object) ?
or that form for some function or cases.
what is the purpose of nested comments ?
commenting out code?? example please
I understand it
thanks
hi
I create two arrays and I want the change in one of them effects the other one.
i try
int[] array1 = [1, 2, 3, 4, 5];
int[] array2;
array2 = array1; // without .dup
assert(array1 == array2);
assert(array1 is array2); // here i am confused because 'is' mean thay have
the same address or what?
is there a way to install gdc without gcc because I already have gcc install
in archlunix?
I have 2 issue:
1- i can't install the package, there is problem I don't know what is it?
2-it is not updated.
template factorial(int n) { const factorial = n * factorial!(n-1); }
template factorial(int n : 1) { const factorial = 1; }
i think this pattern matching or like it, can i do the same thing with regular
function
int factorial(int n) {
return n* factorial(n-1);
return 1 ;
}
int factorial(int n
i have qustion why filter can't return int[]
and if lambda return the last Expression without return keyword it would much
cleaner
does D compatibility with C restrict D from evolving ?
and if D drop this will that prevent complexity?
Hello.
I go to digitalmars to read digitalmars.D.learn newsgroup, but I
have to click the http link. The http interface is kind of
awkward. I'd like to try the newsgroup link.
But, I don't know how to use it. How do I? Is there a client I
can download and use for free that you recommend? I d
== Quote from Nick Sabalausky (a@a.a)'s article
> "%u" wrote in message
news:j655f0$fm8$1...@digitalmars.com...
> > Hello.
> >
> > I go to digitalmars to read digitalmars.D.learn newsgroup, but
I
> > have to click the http link. The http interface is
== Quote from Nick Sabalausky (a@a.a)'s article
> > I guess I don't know how to setup my outlook client to use the
news
> > link? When I click the news link. Nothing happens.
> I don't have access to a Win7 machine ATM, but on both XP and
Vista, you can
> do:
> Tools -> Accounts. There will be a
Hello. I'm having problems compiling the following:
// From chapter 1 of D Programming Language.
//
import std.stdio, std.string;
void main() {
uint[string] dictionary;
foreach( line; stdin.byLine()) {
// Break sentence into words
// Add each word in the sentence to the vocabulary
== Quote from Zardoz (luis.panad...@gmail.com)'s article
> Recently I've been asked if I could give a speech about D in my
university. It
> will be of one hour of long.
> I not respond yet, but I think that I will do it. Actually I have
the problem
> that I don't know well how explain well too many
== Quote from simendsjo (simend...@gmail.com)'s article
> Seems some functionality was moved in 2.052. From std.string
documentation:
> "IMPORTANT NOTE: Beginning with version 2.052, the following
symbols
> have been generalized beyond strings and moved to different
modules."
> And
> "split
Thanks. It works, but I get something weird in the output. I get
the problem if I run it in a dos prompt or in a cygwin prompt:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
D>echo hello | wordcount2.exe
0 hello
std.stdio.StdioExceptio
== Quote from bearophile (bearophileh...@lycos.com)'s article
> simendsjo:
> > Shouldn't the original way work too?
> I don't remember.
> > Another point: I recommend compiling with debug symbols as it
gives you
> > a nice stacktrace.
> I think debug symbols should be present on default, to produce
Hello. I downloaded gtkD MS Windows installer, and I tried to
compile one of the examples shown on the gtkD website:
http://www.dsource.org/projects/gtkd
The example is below along with the problem:
import gtk.MainWindow;
import gtk.Label;
import gtk.Main;
void main(string[] args)
{
Ma
Hello.
I know D isn't Java, but one trivial thing I liked about Java is
the introduction of 'extends' and 'implements' as keywords as ways
to clarify the class relationships when defining a class. You
know:
class Subclass extends SuperClass implements AnInterface {
...
}
Will they ever add this
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Mon, 07 Nov 2011 13:22:07 -0500, %u wrote:
> In order for such a humongously code-breaking change to occur,
there would
> have to be dire reasons why this was necessary. Because you
liked Java is
> not a
Shouldn't this go into 'digitalmars.D' ?
I've been working on porting an old D library to D2, and I'm running into a
nasty issue with templates and inheritance. I've got a base class like this:
class Reader {
void get(T)(ref T[] buffer);
}
and a subclass like this:
class SubReader {
void get()(SomeClass param);
}
The problem i
In the interim, I'm just redefining the template in the base class, but that's a
really annoying hack to have to perform every single time I have to make a new
form of the template.
Correction: redefining in the *subclass*. Silly me.
Thanks! I guess I'll just have to live with redefining the functions, do some
sort
of interface/mixin thing, or change the class interface. It makes sense that
template functions aren't virtual (how are you supposed to deal with vtables?),
but I wish that at least an alias declaration could work.
I think I got it! This seems to work:
class Derived {
//Pulls in all the template forms in the base class
template get(args ...) {
alias Base.get!args get;
}
//Create new versions of get() here.
}
is there a script engine for D 2.x
thanks.
How to parse a simple format with ranges? For example a query string format:
string[string] params = parse("foo=1&bar=1%202&baz=1+2+3");
assert(params["foo"] == "1");
assert(params["bar"] == "1 2");
assert(params["baz"] == "1 2 3");
parse() should accept a string, an stream or anything else that
I'm porting some code from Java to D and am getting stuck on what Java calls
static class fields. I can't find out how to write the functional (or best
practices) equivalent in D.
(There are other syntax errors in D code, I'm fixing them one by one)
# Begin D code (ported from Java code
I get the following strange message when linking:
==
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 23: No Stack
first.obj(first)
Error 42: Symbol Undefined _D3std5stdio6stdoutS3std5stdio4File
first.obj(first)
Error 42: Symbol Undefin
enum X { A=3, B=1, C }
void main() {
foreach(e;X)
writefln(e.stringof," = ",e);
}
//X.A = 3
//X.B = 1
//X.C = 2
or
//X.B = 1
//X.C = 2
//X.A = 3
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> %u wrote:
> > enum X { A=3, B=1, C }
> >
> > void main() {
> > foreach(e;X)
> > writefln(e.stringof," = ",e);
> > }
> > //X.A = 3
> > //X.B = 1
> >
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> %u wrote:
> > == Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> >> %u wrote:
> >> > enum X { A=3, B=1, C }
> >> >
> >> > void main() {
&g
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> %u wrote:
> > The code didn't compile, so I tried fixing it.. and failed as I don't
> > really get
> > what you want it to do (or even how to call it :)
> > Please explain it to me.
>
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> Sorry, it was late and I was tired. Updated code (tested, even! :p):
> module foo;
> import std.stdio;
> template defineStaticImpl( T, int value, string name, args... ) {
> mixin( "static T " ~ name ~ " = cast(T)value; " );
>
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> %u wrote:
> > First question, shouldn't the first foreach be replaced by a simple for
> > loop:
> > for(int i = 0; i It certainly could, and that would explain the presence of 'num', but
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> %u wrote:
> >> I'm not sure what you're getting at here. In what way that you don't
> >> like
> >> it is it enum-unlike?
> >
> > These two have distinctly diffe
== Quote from Nick B ("nick_NOSPAM_.barbalich"@gmail.com)'s article
> there is also the tango community.
> check out here: http://www.dsource.org/projects/tango
> Also many of these projects have IRC chat rooms, most of them on the
> irc.freenode.net server. "d.tango" is the name of the IRC chat r
Hi,
I'm learning D right now and got a question about property.
I tried to add a property for built-in type like the following
@property bool equalZero(double a) { return a == 0.0; }
void main()
{
...
double x = 4.4;
bool isXZero = x.equalZero;
...
}
but got an error message
main.d(75):
Thanks for the reply.
I wonder are there any alternatives to achieve similar things for built-in
types?
I think this is very helpful for template function for built-in types.
/The following binary expressions are evaluated in an implementation-defined
order:
AssignExpression/../AddExpression/
/It is an error to depend on order of evaluation when it is not specified./
That makes this an error!?
y = x + 1;
Am I being paranoid or should I be adding more brackets?
== Quote from Denis Koroskin (2kor...@gmail.com)'s article
> On Fri, 08 Oct 2010 18:49:36 +0400, %u wrote:
> > /The following binary expressions are evaluated in an
> > implementation-defined
> > order:
> > AssignExpression/../AddExpression/
> >
>
Incomplete mixin expression + char[] to char assignment = crash :)
--
char[] foo()
{
char[2] res = "1 ";
res[1] = ";"; // should be a char
return res;
}
struct S(T)
{
int i = mixin( foo() ); // incomplete mixin expression
}
S!(int) s;
--
Assertion failure: '0' on line 1342 in file 'expre
Done & Thanks!
== Quote from bearophile (bearophileh...@lycos.com)'s article
> %u:
> > Incomplete mixin expression + char[] to char assignment = crash :)
> You (or me or someone else) may add this to Bugzilla:
> char[2] foo() {
> char[2] code;
> c
How gc unfriendly is an union of objects and sizet_t?
union{
size_t arr[10];
Class obj[10];
}
And, if multiple arrays contain exclusively the same objects, is it then
safe/useful to mark all but the smallest array with gc.hasNoPointers?
Any object removal/addition happens simultaneous across
== Quote from Ivo Kasiuk (i.kas...@gmx.de)'s article
> Hi!
~snip
>
> This writes:
> new uint
> no reference
> == reference, f7490e20, f7490e10, f7490df0, f74
> 90dd0
> AA
> struct
> uint
> reference
> So in most but not all situations the integer val
== Quote from Ivo Kasiuk (i.kas...@gmx.de)'s article
> > ~snip
> > >
> > > This writes:
> > > new uint
> > > no reference
> > > == reference, f7490e20, f7490e10, f7490df0,
> f74
> > > 90dd0
> > > AA
> > > struct
> > > uint
> > > reference
> ...
> >
== Quote from Ivo Kasiuk (i.kas...@gmx.de)'s article
> > I added the struct again and also ran without the enclosing X class.
> >
> > With X :
> > no reference
> > == reference, ad3fd0, ad3fc0, ad3fa0, ad3f80
> > new uint
> > AA
> > struct
> > uint
> > reference
> >
> > Without X :
> > no r
Please tell me if anything is unclear/stupid :)
== Quote from %u (e...@ee.com)'s article
> How gc unfriendly is an union of objects and sizet_t?
> union{
> size_t arr[10];
> Class obj[10];
> }
> And, if multiple arrays contain exclusively the same objects, is it then
&g
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> %u wrote:
> > How gc unfriendly is an union of objects and sizet_t?
> >
> > union{
> > size_t arr[10];
> > Class obj[10];
> > }
> All elements of this union will be considered poin
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> %u wrote:
> > == Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> >> %u wrote:
> >> > How gc unfriendly is an union of objects and sizet_t?
> >> >
> >
Yay, free access to a!
I searched for this bug in the bug-reports..
Why are there so many basic import bugs?
--
module main;
import b;
void main(){
a.write();
}
--
module a;
import std.stdio;
void write(){
writefln("a");
}
--
module b;
import a; //also with static
--
See subject^^
And why does the spec say that -unittest turns on asserts?
http://www.digitalmars.com/d/1.0/dmd-windows.html#switches
-unittest
compile in unittest code, turns on asserts, and sets the unittest version
identifier
http://www.digitalmars.com/d/1.0/unittest.html
The version identif
What is the fastest way to fill a static multidimensional array?
Looping over all dimension's elements sounds inefficient, especially as a
static array is essentially continuous memory.
What is the best practice?
int[2][2][2] arr = 0;
arr[] = 3; //Error: cannot implicitly convert expression (3) o
== Quote from Don (nos...@nospam.com)'s article
> That's true in D2 only. Shouldn't be in the D1 spec.
filed ;)
== Quote from bearophile (bearophileh...@lycos.com)'s article
> %u:
> > What is the fastest way to fill a static multidimensional array?
> If you want a safe solution, then you probably need nested loops, and a
> array[]
= x; in the inner loop (such loops may be generated wit
== Quote from spir (denis.s...@gmail.com)'s article
> How does this method perform? would you be kind enough to include it in you
> r tests, %u? Even if it's slightly slower than "(cast(int[n1*n2*n3])arr)[]
> = e;", I would use it because I find it cleaner.
Bu
http://www.digitalmars.com/d/1.0/template.html
..
assert(__traits(isRef, x[i]));
..
static assert(!__traits(compiles, min(3, y) = 10));
These won't compile with my D1 :(
== Quote from Jacob Carlborg (d...@me.com)'s article
> On 2010-10-22 20:57, %u wrote:
> > http://www.digitalmars.com/d/1.0/template.html
> > ..
> > assert(__traits(isRef, x[i]));
> > ..
> > static assert(!__traits(compiles, min(3, y) = 10));
> >
> &
The code below results in:
i.d(7): Error: a.B at a.d(2) conflicts with c.B at c.d(4)
changing main to only import i results in:
b.d(4): Error: struct b.B unable to resolve forward reference in definition
a.d(4): Error: struct a.A unable to resolve forward reference in definition
repeated 5 times
Disregard that, here is the real bug. I removed the circular struct definition.
The code below results in:
i.d(7): Error: b.B at b.d(5) conflicts with c.B at c.d(3)
But if the selective imports are changed to non-selective public imports(
bug[314]
) the error is gone.
--
module main;
import c;
%a looks neat as a lossless float formatter, but how do I get the float back
from the string?
At the moment most of my public member functions are littered with these kind
of in-out clauses.
in{
assert(wellformed, toString);
}
out{
assert(wellformed, toString);
}
They just beg for invariants, I though..
But invariants don't report the location of failure of contract, only the
location
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
> On Wednesday 08 December 2010 00:22:23 %u wrote:
> > At the moment most of my public member functions are littered with these
> > kind of in-out clauses.
> >
> > in{
> > assert(wellformed,
Is it possible to give a function a class(type) as an argument such that the
function can call its constructor, without using templates.
void func(T t){
new T();
}
Or, what is the type of a type? :)
Should have been this:
void func(type t){
new t();
}
== Quote from Denis Koroskin (2kor...@gmail.com)'s article
> On Fri, 24 Dec 2010 01:28:49 +0300, %u wrote:
> > Should have been this:
> >
> > void func(type t){
> > new t();
> > }
> >
> >
> Try this (not tested):
> class Test {}
> O
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Thu, 23 Dec 2010 17:28:49 -0500, %u wrote:
> > Should have been this:
> >
> > void func(type t){
> > new t();
> > }
> void func(T)(){
> new T();
> }
> When you are pas
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Wed, 29 Dec 2010 10:33:21 -0500, %u wrote:
> > == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> >> On Thu, 23 Dec 2010 17:28:49 -0500, %u wrote:
> >> > Should have
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Wed, 29 Dec 2010 07:29:29 -0500, spir wrote:
> > Hello,
> >
> > Is there a common idiom to pre-allocate a dynamic array. I mean
> > allocating to avoid numerous re-allocations in loop, not setting length
> > & filling content.
Is it not possible to have a "type" type?
Hi,
I would like to perform compile-time reflection on a module (such as
enumerating all the classes inside the module) and/or on all modules in the
code -- are either of these possible? And if so, how?
Thank you!
Hi,
There's a question that's been lurking in the back of my mind ever since I
learned about D:
How does the GC distinguish code from data when determining the objects to
collect? (E.g. void[] from uint[], size_t from void*, etc.?)
If I have a large uint[], it's practically guaranteed to have da
> If you have allocated a large uint[], most likely =C3=ACt will be flagged
NO_SCAN, meaning it has no pointers in it, and the GC will ignore it.
Ah, but the trouble is, no one said that this array has to be in the GC heap! I
could easily have a void[] and a uint[] that both point to non-GC manag
> It assumes everything on the stack is pointers, at the moment, I believe
Uh-oh... not the answer I wanted to hear, but I was half-expecting this.
So doesn't that mean that, at the moment, D will leak memory?
> If it's not on the garbage collected heap, it won't scan it unless you
tell it to.
B
> Kinda sorta. I haven't had any problems from that. If you allocate very large
blocks in the garbage collector you may face trouble :-)
Haha okay, thanks. :) (This makes me shiver quite a bit...)
> You have to add it to the garbage collector's list of roots
But if I need to do that, then what
> None what so ever.
Huh.. then what about what is said in this link?
http://d.puremagic.com/issues/show_bug.cgi?id=5326#c1
I was told that void[] could contain references, but that ubyte[] would not, and
that the GC would need to scan the former but not the latter. Is that wrong?
Thank you!
> First, you should understand that the GC does not know what data is in a
> memory
block.
That is exactly why I was wondering how it figures things out. :)
> Data *allocated* as a void[] (which I highly recommend *not* doing) will be
conservatively marked as containing pointers.
Ah, all right
Hi,
This code seems to leak memory, as the memory isn't reclaimed:
//Test memory here: low
{
auto b = Array!(bool)();
b.length = 1024 * 1024 * 128 * 8;
//Test memory here: high
}
//Test memory here: high
Am I missing something about how Array(T) (and RefCounted) works, or
> What method are you using to test the memory?
> I'm puzzled that you've put a comment there rather than the code you're
> actually
using.
I'm not using code, I'm checking the working set of my process in Task Manager,
and through every iteration, it adds 128 MB.
> If you run this code twice,
Isn't it possible to have a hierarchy in interface definitions such that it is
possible to overload according to best interface match?
This now won't compile due to multiple matches.
module main;
interface I1{}
interface I2 : I1{}
class C : I2{
this(){}
}
void func(I1 i){}
void func(I2
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
> On Saturday 08 January 2011 22:01:11 %u wrote:
> > Isn't it possible to have a hierarchy in interface definitions such that it
> > is possible to overload according to best interface match?
> >
&g
== Quote from bearophile (bearophileh...@lycos.com)'s article
> %u:
> > func(cast(I2)(new C()));
> That code smells a bit (http://en.wikipedia.org/wiki/Code_smell ).
> Bye,
> bearophile
Extract the construction and you get:
module main;
interface I1{}
interface
1 - 100 of 146 matches
Mail list logo