Re: Structs insted of classes for Performance

2014-04-20 Thread anonymous via Digitalmars-d-learn
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

Re: import with renaming and public import inside module

2014-04-28 Thread anonymous via Digitalmars-d-learn
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

Re: import with renaming and public import inside module

2014-04-29 Thread anonymous via Digitalmars-d-learn
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_;

Re: import with renaming and public import inside module

2014-04-29 Thread anonymous via Digitalmars-d-learn
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

Re: Strings concatenated at compile time?

2014-05-01 Thread anonymous via Digitalmars-d-learn
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

Re: formattedWrite writes nothing

2014-05-02 Thread anonymous via Digitalmars-d-learn
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

Re: sort struct of arrays

2014-05-09 Thread anonymous via Digitalmars-d-learn
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

Re: RegEx for a simple Lexer

2014-05-13 Thread anonymous via Digitalmars-d-learn
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

Re: Convert a hex string into a ubyte[] or OutBuffer

2014-05-19 Thread anonymous via Digitalmars-d-learn
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

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
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

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
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

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
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; }

Re: Differences between const Type function() and const(Type) function()

2014-05-30 Thread anonymous via Digitalmars-d-learn
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?

Re: Differences between const Type function() and const(Type) function()

2014-05-30 Thread anonymous via Digitalmars-d-learn
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

Re: Arrays as template parameters

2014-06-05 Thread anonymous via Digitalmars-d-learn
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]);

Re: Conversion string-int

2014-06-07 Thread anonymous via Digitalmars-d-learn
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));

Re: Running a delegate inside a C function

2014-06-07 Thread anonymous via Digitalmars-d-learn
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

Casts and @trusted

2014-06-13 Thread Anonymous via Digitalmars-d-learn
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

Re: Casts and @trusted

2014-06-14 Thread Anonymous via Digitalmars-d-learn
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);

Re: immutable/mutable aliasing

2014-07-03 Thread anonymous via Digitalmars-d-learn
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

Re: immutable/mutable aliasing

2014-07-03 Thread anonymous via Digitalmars-d-learn
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

Re: Ranges containers : is it possible to get a SortedRange from a RedBlackTree ?

2014-07-07 Thread anonymous via Digitalmars-d-learn
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

Re: Ranges containers : is it possible to get a SortedRange from a RedBlackTree ?

2014-07-07 Thread anonymous via Digitalmars-d-learn
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

Re: Ranges containers : is it possible to get a SortedRange from a RedBlackTree ?

2014-07-07 Thread anonymous via Digitalmars-d-learn
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

Re: std.algorithm.sort error with default predicate

2014-07-07 Thread anonymous via Digitalmars-d-learn
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

Re: Tuple and tie?

2014-07-08 Thread anonymous via Digitalmars-d-learn
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 =

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread anonymous via Digitalmars-d-learn
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

Re: Using enum constant from different modules

2014-07-10 Thread anonymous via Digitalmars-d-learn
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

Re: Value Reference Type Traits

2014-07-11 Thread anonymous via Digitalmars-d-learn
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

Re: DStyle: Braces on same line

2014-07-12 Thread anonymous via Digitalmars-d-learn
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

Template help

2014-07-12 Thread Anonymous via Digitalmars-d-learn
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

Re: Template help

2014-07-12 Thread Anonymous via Digitalmars-d-learn
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

Re: String to int exception

2014-07-15 Thread anonymous via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 14:05:14 UTC, Alexandre wrote: Strange..., why '@' ? because x40 == @

Handle to some object, call its methods

2014-07-15 Thread Anonymous via Digitalmars-d-learn
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

Re: Handle to some object, call its methods

2014-07-15 Thread Anonymous via Digitalmars-d-learn
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 =

Re: How to say to compiler that I want to inherit final template bethod of base interface into derived class

2014-07-20 Thread anonymous via Digitalmars-d-learn
import std.stdio; interface IBase { template getStr(string fieldName) { final string getStr() { return George; } } string getStr(string fieldName); } class

Re: How to say to compiler that I want to inherit final template bethod of base interface into derived class

2014-07-21 Thread anonymous via Digitalmars-d-learn
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).

Re: How to say to compiler that I want to inherit final template bethod of base interface into derived class

2014-07-21 Thread anonymous via Digitalmars-d-learn
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

Re: Need help with basic functional programming

2014-07-22 Thread anonymous via Digitalmars-d-learn
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

Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
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); }

Re: Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
Whoops, that is writeln(a ,a.arr); and so on.

Re: Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
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.

Re: memory/array question

2014-07-31 Thread anonymous via Digitalmars-d-learn
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:

Re: auto ref function parameters in a free function

2014-08-03 Thread anonymous via Digitalmars-d-learn
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?

Re: auto ref function parameters in a free function

2014-08-03 Thread anonymous via Digitalmars-d-learn
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

Re: mismatched function return type inference of string and double

2014-08-03 Thread anonymous via Digitalmars-d-learn
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

Re: Declaring run time variables

2014-08-04 Thread anonymous via Digitalmars-d-learn
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

Re: Declaring run time variables

2014-08-04 Thread anonymous via Digitalmars-d-learn
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`

Re: d malloc

2014-08-08 Thread anonymous via Digitalmars-d-learn
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

Re: Communication between D and C with dynamic arrays

2014-08-10 Thread anonymous via Digitalmars-d-learn
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 *

Re: overloads and parents. __traits confusion

2014-08-12 Thread anonymous via Digitalmars-d-learn
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,

Re: Destroy two assumptions: interface implementation generated by TMP

2014-08-12 Thread anonymous via Digitalmars-d-learn
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; }

Re: Destroy two assumptions: interface implementation generated by TMP

2014-08-12 Thread anonymous via Digitalmars-d-learn
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

Re: Question about operations on class/struct properties

2014-08-18 Thread anonymous via Digitalmars-d-learn
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

Re: Variadic parameter of length 1

2014-08-20 Thread anonymous via Digitalmars-d-learn
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

Re: No Output with shebang.

2014-08-20 Thread anonymous via Digitalmars-d-learn
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

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
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

Re: Generating a tree structure

2014-08-21 Thread anonymous via Digitalmars-d-learn
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.

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
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 {

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
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}}!

Re: Error: template cannot deduce function from argument types.

2014-08-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 August 2014 at 02:53:41 UTC, Damian Day wrote: Hi, I've been trying to reduce a bug in the containers (8824). From the example below it seems the dup method is passing the constructor an array of dchars and the template is failing. Is this a compiler bug, or ? import

Re: std.stdio.tmpfile() return shared(_IO_FILE)* and not File

2014-08-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 August 2014 at 17:55:05 UTC, simendsjo wrote: Using DMD 2.066 on GNU/Linux x86_64. This is strange: import std.stdio; void main() { auto f = tmpfile(); pragma(msg, typeof(f)); // shared(_IO_FILE)* } But stdio.d looks like the following: static File tmpfile() @safe

Re: How to cast to void*, while bypassing alias this or opCast

2014-08-28 Thread anonymous via Digitalmars-d-learn
On Thursday, 28 August 2014 at 10:45:52 UTC, monarch_dodra wrote: I'm investigating a phobos regression. From doesPointTo: // static if (isPointer!S || is(S == class) || is(S == interface)) { const m = cast(void*) source; // Basically, given a pointer like structure,

Re: Is this a bug when creating proxies in classes?

2014-08-28 Thread anonymous via Digitalmars-d-learn
On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby wrote: With that in mind what is strange is that if in my example you change the class for a struct everything works as expected. Why is that? That's because when not mixed into a class, Proxy did import std.traits: static if

Re: Building library

2014-08-28 Thread anonymous via Digitalmars-d-learn
On Thursday, 28 August 2014 at 19:29:40 UTC, papaboo wrote: My current file and module layout is test.d src/math/vector.d - module dragonfly.math.vector src/math/quaternion.d - module dragonfly.math.quaternion Compiling with $ dmd test.d src/math/vector.d src/math/quaternion.d ./test works

Re: Why does this not work?

2014-09-17 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 September 2014 at 13:20:15 UTC, Shachar wrote: On Wednesday, 17 September 2014 at 13:03:05 UTC, flamencofantasy wrote: the result of ubyte + ubyte is int I believe. Try; void func( int c ) { ubyte a; a = cast(ubyte)(cast(ubyte)c + cast(ubyte)c); } From

Re: String[] pointer to void* and back

2014-09-18 Thread anonymous via Digitalmars-d-learn
On Thursday, 18 September 2014 at 21:35:50 UTC, seany wrote: Yes, thank you, I corrected that. However, if this v is a member of a class, like import std.stdio; import std.conv; import core.vararg; struct S { void *v; } class C { S* sx = new S; void dothings() {

Re: String[] pointer to void* and back

2014-09-19 Thread anonymous via Digitalmars-d-learn
On Friday, 19 September 2014 at 12:14:19 UTC, seany wrote: On Thursday, 18 September 2014 at 22:16:48 UTC, Ali Çehreli wrote: If you are holding an address in a void*, you must make sure that the original object is still at that location when you attempt to access the object. Does that

Re: regex problems

2014-09-20 Thread anonymous via Digitalmars-d-learn
On Saturday, 20 September 2014 at 15:28:54 UTC, seany wrote: In haystack, there are two such ID : -s. once at the beginning, ID : generateWorld. and then the final, last ID However, this is returning all 5 ID-s as match what am I doing wrong? Prints ID : ID : for me. I'd advise against

Re: parallel foreach hangs

2014-09-22 Thread anonymous via Digitalmars-d-learn
On Monday, 22 September 2014 at 11:25:53 UTC, Daniel Kozak wrote: this code never end import std.stdio; import std.file; import std.parallelism : parallel; import std.algorithm : filter; void main(string[] args) { foreach(d; parallel(args[1 .. $], 1)) { auto phpFiles =

Re: Cannot deduce from type

2014-09-22 Thread anonymous via Digitalmars-d-learn
On Monday, 22 September 2014 at 14:45:31 UTC, Chris wrote: Why is that? import std.stdio, std.array void main() { auto output = appender!(string); output ~= world!; // output.data.insertInPlace(0, Hello, ); // Doesn't work auto asString = output.data; asString.insertInPlace(0, Hello,

Re: Recursive function call

2014-09-24 Thread anonymous via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 10:57:27 UTC, Suliman wrote: string getFileName() { [...] getFilename(); //I need something similar, to call function again. You mistyped the function name, it's getFileName (capital N), and you forgot return. So: return getFileName();

Re: find all public properties at compile time

2014-09-30 Thread anonymous via Digitalmars-d-learn
On Tuesday, 30 September 2014 at 20:04:29 UTC, gedaiu wrote: [sorry... this is the edit for the prev post] Thank you for your response! I don't think that it helps me... I wanted to get an array like this [ a, b, c ] for this class class test { int a; string b; double c; } import

Re: How do I check if a function got CTFE?

2014-10-02 Thread anonymous via Digitalmars-d-learn
On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote: I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time. I'm trying to convert the binary executable to assembly by using objconv tool but I'm finding it very

Re: How do I check if a function got CTFE?

2014-10-02 Thread anonymous via Digitalmars-d-learn
On Thursday, 2 October 2014 at 18:42:56 UTC, AsmMan wrote: I was thiking the dmd compiler did CTFE without someone ask for this, in the way as I've mentioned, checking for constant arguments + function's purity and if all this is true, it did the CTFE rather than generate code to compute it at

Re: How to detect start of Unicode symbol and count amount of graphemes

2014-10-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 October 2014 at 17:28:45 UTC, Uranuz wrote: ( str[index] 0b1000 ) == 0 || ( str[index] 0b1110 ) == 0b1100 || ( str[index] 0b ) == 0b1110 || ( str[index] 0b1000 ) == 0b If it is true it means that first byte of sequence found and I can count

Re: (this MyType) and interface: Symbol undefined

2014-10-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 13:00:56 UTC, andre wrote: Hi, please consider following example. I want to acces class B by interface I. Method work should print the actual class (B). The linker say: Error 42: Symbol Undefined _D3app1I17__T4workTC3app1IZ4workMFZv Is this is missing

Re: (this MyType) automatic deduction?

2014-10-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 10:36:33 UTC, andre wrote: Hi, could you check whether it is correct, that second line in main failes with a compiler error? I think the compiler should be able to deduce the type without explicitly passing it to the method call. Kind regards André template

Re: Formatted output of range of tuples

2014-10-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 21:21:47 UTC, antropod wrote: Hello! Consider this code: +++ import std.stdio; import std.range; import std.algorithm; void printIndexedArray1(T, Range)(T[] source, Range indexes) { foreach(row; zip(indexes, source)) {

Re: Using inline assembler

2014-10-09 Thread anonymous via Digitalmars-d-learn
On Thursday, 9 October 2014 at 12:37:20 UTC, Etienne wrote: I'm a bit new to the inline assembler, I'm trying to use the `movdqu` operation to move a 128 bit double quadword from a pointer location into another location like this: align(16) union __m128i { ubyte[16] data }; void

Re: Using inline assembler

2014-10-09 Thread anonymous via Digitalmars-d-learn
On Thursday, 9 October 2014 at 13:29:27 UTC, Etienne wrote: On 2014-10-09 8:54 AM, anonymous wrote: This compiles: align(16) union __m128i { ubyte[16] data; } /* note the position of the semicolon */ void store(__m128i* src, __m128i* dst) { asm { movdqu XMM0, [src]; /*

Re: how to call class' template constructor

2014-10-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 October 2014 at 19:46:41 UTC, ketmar via Digitalmars-d-learn wrote: Hello. please, how to call template constructor of a class? it's completely escaped my mind. i.e. i have this class: class A { this(alias ent) (string name) { ... } } and i want to do:

Re: Mixin template functions are ignored in struct

2014-10-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 October 2014 at 20:58:19 UTC, tcak wrote: I have written a struct and a mixin template, and that mixin template is mixed into that struct as follows. private mixin template TestCommonMethods(){ public bool apply( int d, int e ){ return false; } }

Re: Function parameters from TypeTuple

2014-10-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 October 2014 at 17:57:58 UTC, Tofu Ninja wrote: On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote: Not sure if what I wrote made sense, instead I will just post the code that is vomiting on me... You forgot the imports. template arrayType(T) { alias

Re: Function parameters from TypeTuple

2014-10-17 Thread anonymous via Digitalmars-d-learn
On Friday, 17 October 2014 at 19:18:29 UTC, Tofu Ninja wrote: I had the imports, I just didn't post them. My problem is most likely that I used Tuple! instead of tuple... which is probably because the differences between the like 20(exaggeration) different types of tuples in D are confusing as

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Wednesday, 15 October 2014 at 21:15:14 UTC, Nordlöw wrote: https://github.com/nordlow/phobos/commit/9daf235d7091f76cd941e29e3c167d559bf56a94 but that triggers a new interesting suite of errors Error: mutable method std.container.array.Array!int.Array.__fieldPostBlit is not callable using

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 18:58:50 UTC, Nordlöw wrote: On Sunday, 19 October 2014 at 15:21:02 UTC, anonymous wrote: version(none) _outer = data; /* Error: mutable method [...].Array.opAssign is not callable using a const object */ What do these comments

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 19:30:40 UTC, Nordlöw wrote: On Sunday, 19 October 2014 at 19:13:33 UTC, anonymous wrote: Yes, they don't compile. It's three slightly different versions of initializing _outer. The first one, `_outer = data;`, is the original one. It's understandable that it

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 20:10:33 UTC, Nordlöw wrote: Used your ideas here https://github.com/nordlow/phobos/commit/be6b5f8c4d428a9708a52757a3f31aab6878d379 but unittests now fails as array.d(234,13): Error: mutable method std.container.array.Array!int.Array.opAssign is not callable

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 20:39:18 UTC, anonymous wrote: Spell the type out or use `typeof(result)`. Should be `typeof(return)`.

Re: Really in need of help with std.container.array.d

2014-10-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 15:21:02 UTC, anonymous wrote: struct RefCounted { this(this) /* const doesn't help */ {} ~this() /* const doesn't help */ {} } struct Array { RefCounted _data; } void main() {const Array a; const copy = a;} /* works */ struct RangeM {Array a;}

Re: Really in need of help with std.container.array.d

2014-10-20 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote: https://github.com/nordlow/phobos/commit/ce6b9e9ae600b7c28ecddd1e3af7b1516247fb33 now errors as array.d(927,15): Error: None of the overloads of 'opSlice' are callable using a const object, candidates are: array.d(472,25):

Re: Really in need of help with std.container.array.d

2014-10-20 Thread anonymous via Digitalmars-d-learn
On Monday, 20 October 2014 at 11:20:30 UTC, Nordlöw wrote: On Monday, 20 October 2014 at 10:56:43 UTC, anonymous wrote: On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote: By the way, since we're in D.learn, I'm assuming you want to do this yourself. But if you'd like, I could make a

Re: Global const variables

2014-10-21 Thread anonymous via Digitalmars-d-learn
On Tuesday, 21 October 2014 at 12:08:35 UTC, Solomon E wrote: On Tuesday, 21 October 2014 at 08:48:09 UTC, safety0ff wrote: const int[] a; int[] b; static this() { b = [1]; a = b; } `a` isn't a reference to `b`. `a` is assigned by value and has its own storage. `a` is indeed a copy

Re: Destructor order

2014-10-22 Thread anonymous via Digitalmars-d-learn
On Wednesday, 22 October 2014 at 15:45:02 UTC, eles wrote: D version: { //displays ~A~B~C A foo = scoped!(A)(); B bar = scoped!(B)(); C caz = new C(); destroy(caz); } Why the objects are not destroyed in the inverse order of their

Re: parser bug?

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 18:15:26 UTC, Charles Hixson via Digitalmars-d-learn wrote: The code: voidgo(ulongrecNum) {assert (buf[0] == (fh.sizeof + recNo * buf.length) 0x7f); if(dirty) yields the error message: ells$ dmd test.d test.d(78): Error:

Re: std.stdio breaks casting operation

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 18:43:54 UTC, tcak wrote: Then I change the Test.setIt method as follows: import std.stdio; s = cast( typeof( s ) )sock; Error on s = cast... line: cannot cast module socket of type void to shared(Socket) Apparently std.stdio

Re: Bug?

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 21:17:25 UTC, deed wrote: Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8 for both Windows and Linux. This just illustrates the sin function. I think the tests marked [1] are expected to fail. They involve converting one operand of the

Re: Bug?

2014-10-23 Thread anonymous via Digitalmars-d-learn
On Thursday, 23 October 2014 at 21:42:46 UTC, anonymous wrote: On Thursday, 23 October 2014 at 21:17:25 UTC, deed wrote: Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8 for both Windows and Linux. This just illustrates the sin function. I think the tests marked [1] are

Re: forum.dlang.org open source?

2014-10-26 Thread anonymous via Digitalmars-d-learn
On Sunday, 26 October 2014 at 23:57:41 UTC, Mike wrote: Does forum.dlang.org have an open source repository somewhere that we can contribute pull requests to, or are bug reports to recommended procedure. http://forum.dlang.org/help#contributing

  1   2   3   4   5   6   >