Re: Default method implementations in interfaces?

2015-10-23 Thread pineapple via Digitalmars-d-learn
On Friday, 23 October 2015 at 15:07:05 UTC, Alex Parrill wrote: Use template mixins: http://dlang.org/template-mixin.html On Friday, 23 October 2015 at 15:08:30 UTC, Adam D. Ruppe wrote: Use a mixin template together with your interface. Awesome, thanks! No way, though, to unite

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 18:28:50 UTC, Ali Çehreli wrote: If you already have a piece of memory, it is trivial to convert it to a slice in D: auto slice = existing_pointer[0 .. number_of_elements]; http://ddili.org/ders/d.en/pointers.html#ix_pointers.slice%20from%20pointer The

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
Answered my own question: Turns out File.getFP() does exactly what I needed

Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
I'd like to use fread and fwrite in place of File.rawRead and File.rawWrite which force the creation of an array where I'd rather specify a buffer location and length. I'd like to do this using a File object but the handle for the C stream is a private member and I can't find any way to access

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 13:58:56 UTC, Adam D. Ruppe wrote: D's templates are easy (you actually used one in there, the Generator is one!) Try this: import std.concurrency; Generator!T sequence(T)(T i){ return new Generator!T({ yield(i); while(i > 1){

Re: I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread pineapple via Digitalmars-d-learn
On Wednesday, 28 October 2015 at 11:40:14 UTC, tcak wrote: The "writebuffer" is defined to take an array as parameter. Yet, you are passing a pointer and a length to it. Instead, pass the parameter "str" to it directly. Also, you do not have to put "!char" to there. Compiler will solve it out

Re: I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread pineapple via Digitalmars-d-learn
On Wednesday, 28 October 2015 at 12:06:14 UTC, Kagamin wrote: On Wednesday, 28 October 2015 at 11:48:27 UTC, pineapple wrote: There's also a writebuffer method in the interface with this signature, though: streamint writebuffer(T)(in T* buffer, in streamint count); Interface can't have

I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread pineapple via Digitalmars-d-learn
When I attempt to compile my code I get the same linker error with both dmd and ldc2. I know where the problematic code is, as I don't get the error when I comment out lines 102 through 107, but I don't understand why it's bad. I must have some misconceptions about how templates work? Is there

Default method implementations in interfaces?

2015-10-23 Thread pineapple via Digitalmars-d-learn
Is it possible to have default method implementations in interfaces à la Java in D? Or some equivalent that allows multiple inheritance without a bunch of identical copypasted method bodies?

Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
I'm just starting to hammer D's very pleasant syntax into my head. After "Hello world", the first thing I do when learning any language is to write a simple program which generates and outputs the Collatz sequence for an arbitrary number. (I also like to golf it.) This is what I wrote in D:

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 14:36:52 UTC, John Colvin wrote: Using ranges instead of threads or fibers, slightly over-engineered to show off features: What does if(isIntegral!T) do? It looks like it would verify that the template type is a discrete number? If I were to create my own

Re: Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread pineapple via Digitalmars-d-learn
On Saturday, 4 June 2016 at 15:43:01 UTC, Mihail K wrote: As far as I recall, foreach_reverse is deprecated in favour of range operations. ie. import std.algorithm, std.range; static if(forward) { items.each!(item => doStuff()); } else { items.retro.each!(item =>

Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread pineapple via Digitalmars-d-learn
It would be fantastic if I could write this - static if(forward){ foreach(item; items) dostuff(); }else{ foreach_reverse(item; items) dostuff(); } as something like this - foreach!forward(item; items) dostuff(); Is there any way to accomplish this?

Re: How to call one static method from another?

2016-06-14 Thread pineapple via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote: Simply: method2(); Also, typeof(this).method2();

Re: how to get rid of "cannot deduce function from argument types" elegantly

2016-06-14 Thread pineapple via Digitalmars-d-learn
On Monday, 13 June 2016 at 22:54:13 UTC, Ali Çehreli wrote: Tree!T tree(TL, T, TR)(TL left, T node, TR right) { return new Tree!T(left, node, right); } There's also this: Tree!T tree(TL, T, TR)(TL left, T node, TR right) if( (is(TL == Tree!T) || is(TL == typeof(null))) &&

Re: I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-28 Thread pineapple via Digitalmars-d-learn
On Saturday, 28 May 2016 at 16:25:02 UTC, Seb wrote: If you are interested how it works under the hood - it's pretty simple & elegant: I checked up on the phobos implementation and found that arrays are mutated when iterated over as ranges, which didn't rest well with me. Nor did the idea of

Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
I found another post on this subject and the advice there was "don't put const members in your structs" - http://forum.dlang.org/thread/m87ln2$idv$1...@digitalmars.com This doesn't work out so well when the templated struct is referring to what happens to be a const array. I thought I could

Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
On Sunday, 29 May 2016 at 18:52:36 UTC, pineapple wrote: What's the best way to handle something like this? Well I did get something to work but it's ugly and I refuse to believe there isn't a better way to handle this. Where `Range` is an alias to a struct with an immutable member, and

Re: Operator overloading through UFCS doesn't work

2016-05-30 Thread pineapple via Digitalmars-d-learn
Here's one more vote for extending UFCS to operator overloading. Elie wrote that it's "a restriction that seems pointless and arbitrary"... which summarizes my own thoughts rather well, too. There are certainly concerning scenarios that can arise from making this change, but the correct way

Re: Why aren't overloaded nested functions allowed?

2016-05-30 Thread pineapple via Digitalmars-d-learn
On Monday, 30 May 2016 at 16:22:26 UTC, Max Samukha wrote: From the spec (https://dlang.org/spec/function.html#nested): "Nested functions cannot be overloaded." Anybody knows what's the rationale? I'm guessing it's related to - Unlike module level declarations, declarations within function

Getting the parameters and other attributes belonging to the function overload with the greatest number of arguments

2016-05-31 Thread pineapple via Digitalmars-d-learn
I'd like to find the overload of some function with the most parameters and (in this specific case) to get their identifiers using e.g. ParameterIdentifierTuple. There have also been cases where I'd have liked to iterate over the result of Parameters!func for each overload of that function.

Re: Getting the parameters and other attributes belonging to the function overload with the greatest number of arguments

2016-05-31 Thread pineapple via Digitalmars-d-learn
On Tuesday, 31 May 2016 at 20:46:37 UTC, Basile B. wrote: Yes this can be done, you must use the getOverload trait: https://dlang.org/spec/traits.html#getOverloads The result of this trait is the function itself so it's not hard to use, e.g the result can be passed directly to 'Parameters',

I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-27 Thread pineapple via Digitalmars-d-learn
I'm writing my own map function modeled after the one in phobos. (because I feel like it, that's why. good learning experience.) I've encountered one remarkable difference: The phobos function accepts arrays and mine does not. I understand why - I'm calling methods that arrays don't have - but

Unittests run without error when done individually, but when unittesting the package some fail

2016-06-01 Thread pineapple via Digitalmars-d-learn
How this could possibly be happening is confounding me and I have no idea if it's something I missed or some contrived compiler bug. This is the package.d that previously I've compiled with unittest every so often as a way of doing regression testing -

Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
On Sunday, 29 May 2016 at 19:52:37 UTC, Basile B. wrote: Do yo have a simple, concise runnable example to show ? This is the example I was using to test solutions, it's similar to where I encountered the problem in the first place import core.stdc.stdlib : malloc, free; import

Passing anonymous templated functions as template parameters

2016-06-15 Thread pineapple via Digitalmars-d-learn
Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){ return func!T(x); } } // Valid auto

Shorthand for defining numeric literals as size_t and ptrdiff_t

2016-06-23 Thread pineapple via Digitalmars-d-learn
There are suffixes for numbers like 0L, 0u, 0f, 0d, etc. What about suffixes representing size_t and ptrdiff_t? Do they exist? If not, why?

Re: String joining an array of structs or class instances implementing toString?

2016-02-11 Thread pineapple via Digitalmars-d-learn
Oh pardon the constructor I was playing with as a learning experience and forgot to get rid of.

String joining an array of structs or class instances implementing toString?

2016-02-11 Thread pineapple via Digitalmars-d-learn
It feels like there should be an out-of-the box way to do this but I haven't been able to find it? Help? This is the thing that I want to do: struct example{ const string str; //this(string str){ this.str = str; } string toString(){ return this.str; } } public void

Re: String joining an array of structs or class instances implementing toString?

2016-02-11 Thread pineapple via Digitalmars-d-learn
On Thursday, 11 February 2016 at 12:53:20 UTC, Edwin van Leeuwen wrote: I'd do it like this: import std.algorithm : map; pars.map!((part) => part.toString) // Turn them to strings .join(" ").writeln; // Join them. Thanks! Does the map function iterate without constructing an extra list

Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
With this bit of code, the first method seems to work fine - things go as expected. But I get a compile error with the second method, and I'm not sure how else to write this. override bool opEquals(Object value) const{ return this.equals(cast(typeof(this)) value); }

Re: Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
It also occurred to me to do something like this, but it isn't accepted either. override bool opEquals(T)(T value){ return this.equals(value); }

Can't run unit tests on Win7 64-bit?

2016-01-28 Thread pineapple via Digitalmars-d-learn
I have a super simple D file that looks like this: unittest{ import std.stdio; writeln("hello"); } On OSX Mavericks I run "rdmd --main -unittest test.d" and I get a nice "hello" and everything is well. On Win7 64-bit I run "> rdmd --main -unittest test.d" and rdmd seems to hang. It

Re: Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
On Friday, 29 January 2016 at 15:13:45 UTC, Mike Parker wrote: The first implementation is fine because you're overriding the implementation in the base class (Object). However, the second one fails because it's a template. Templates are non-virtual and cannot override anything. Even if you

Non-English characters in code - "character 0x2212 is not a valid token"

2016-01-28 Thread pineapple via Digitalmars-d-learn
I experimented with using the character 'ħ' in a variable name, and wasn't terribly surprised when the compiler didn't like it. What did surprise me is that I still got a compile error even when the character was in a comment. Is there any way to make dmd not get fussy about unicode?

Re: Non-English characters in code - "character 0x2212 is not a valid token"

2016-01-28 Thread pineapple via Digitalmars-d-learn
On Thursday, 28 January 2016 at 13:18:55 UTC, pineapple wrote: I experimented with using the character 'ħ' in a variable name, and wasn't terribly surprised when the compiler didn't like it. What did surprise me is that I still got a compile error even when the character was in a comment. Is

Error using templates: "cannot use template to add field to aggregate ''"

2016-01-25 Thread pineapple via Digitalmars-d-learn
I'm getting several of these since I'm trying to do the same thing in a few places. Here's a complete error: path\to\file.d(55): Error: variable units.unitvalue.opmethod!("sum(in unitvalue value)", "add(value)").methodtemplate cannot use template to add field to aggregate 'unitvalue'

Re: Error using templates: "cannot use template to add field to aggregate ''"

2016-01-25 Thread pineapple via Digitalmars-d-learn
Thanks so much for the help! I'm still getting used to D's compile-time code.

Not getting expected behavior from compile-time conditional

2016-01-26 Thread pineapple via Digitalmars-d-learn
Here's a simple programming showing where I'm tripping up - void test(T)(in T value){ import std.traits; static if(is(T == char)){ writeln("char"); }else static if(is(isNumeric!(T))){ writeln("number"); } writeln("hi"); } public void main(){ test('g');

Re: Not getting expected behavior from compile-time conditional

2016-01-26 Thread pineapple via Digitalmars-d-learn
On Wednesday, 27 January 2016 at 00:17:18 UTC, Ali Çehreli wrote: Remove the extra is: :) Huh, I swear I tried that. Thanks!

Function accepting variadic arguments

2016-01-20 Thread pineapple via Digitalmars-d-learn
I'd like to make a constructor which takes a variable list of arguments, of a short list of possible types, with different handling depending on the type. I haven't been able to find any documentation or examples that did quite what I'm trying to. Help? A fun pseudocode example of what I'm

Re: Function accepting variadic arguments

2016-01-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 12:56:51 UTC, Ali Çehreli wrote: And there is another example here: http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.tuple%20template%20parameter Ali Thank you! What's the purpose of "is" in the type checks? Also, how would I utilize

Re: Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 13:17:38 UTC, Anonymouse wrote: You can't get rid of the signature completely as the functions still need a parameter list with x declared. You will get "Error: undefined identifier 'x'" otherwise. You can largely omit the *type* of x if it can be inferred from the

Re: overriding methods

2016-04-05 Thread pineapple via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 18:54:39 UTC, stunaep wrote: I had no error on the examples I posted, only when using @Override previously. It just says to use override attribute instead of @Override Unlike in Java, D's override indicator doesn't look like an annotation, it's just a keyword

Practical difference between a struct with const members and with mutable members?

2016-04-09 Thread pineapple via Digitalmars-d-learn
I'm mainly coming from languages that haven't got structs, let alone the kind of differentiation D offers between mutable/immutable/const/etc variables, so I'm still trying to work out just when to use each - What's different between these two examples, practically speaking? When would you use

Re: Why do my stack traces look like this? How can I get more informative ones?

2016-04-09 Thread pineapple via Digitalmars-d-learn
On Sunday, 10 April 2016 at 00:48:23 UTC, pineapple wrote: How can I fix this, and get something human-readable? Oh, answered my own question. Appending the -g flag to dmd options makes the stack trace much prettier.

Why do my stack traces look like this? How can I get more informative ones?

2016-04-09 Thread pineapple via Digitalmars-d-learn
I'm getting a RangeError and the stack trace is being spectacularly unhelpful in debugging the problem, because it looks like this: core.exception.RangeError@E:\Dropbox\Projects\d\lib\wip_ansi_2.d(78): Range violation 0x0040A240 0x00402E37 0x00402B5E 0x00402985 0x00402F29

Putting things in an enum's scope

2016-04-06 Thread pineapple via Digitalmars-d-learn
Is there any way in D to define static methods or members within an enum's scope, as one might do in Java? It can sometimes help with code organization. For example, this is something that coming from Java I'd have expected to be valid but isn't: enum SomeEnum{ NORTH, SOUTH, EAST, WEST;

Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
If I have a common function signature I'm using throughout my code, and I feel like there should be a way to condense it using a macro. The intuitive method isn't working, but this seems like something D would be able to do. What've I got wrong in this example? alias somelongsignature =

Re: Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
Ah, aside from the mismatched "examplefunc" numbers - please disregard Can't post example code without stupid typos for the life of me

Re: How to run unit tests on Windows?

2016-04-14 Thread pineapple via Digitalmars-d-learn
On Thursday, 14 April 2016 at 10:50:00 UTC, ag0aep6g wrote: Invoked like that, dmd doesn't run the program at all. It just makes an .exe file of it. To run the program simply type its name into the command prompt. So if your source file is foo.d, `dmd foo.d -main -unittest` creates foo.exe,

Confusion with anonymous functions and method overloads

2016-05-21 Thread pineapple via Digitalmars-d-learn
I wrote a pair of methods that looked like this: void clean(in void delegate(in T value) func){ this.clean((in T values[]) => { foreach(value; values) func(value); }); } void clean(in void delegate(in T values[]) func){ ... } I was getting a

Re: Compiler silently ignores some method overloads

2016-05-10 Thread pineapple via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 09:57:11 UTC, pineapple wrote: On Monday, 9 May 2016 at 18:56:15 UTC, Peter Häggman wrote: No problem here (tested with everything in a single module). I can't help more. Front end version ? Well, this is the full struct that has those malfeasant overrides:

Method doesn't compile when defined in a mixin, but is fine without?

2016-05-01 Thread pineapple via Digitalmars-d-learn
I'm working on an SDL wrapper based on the derelict sdl2 and opengl3 bindings and so I've got a method like this I wrote: @property Vector2!int minsize(){ int x, y; SDL_GetWindowMinimumSize(this.window, , ); return Vector2!int(x, y); } I've got several almost identical methods for

Re: Method doesn't compile when defined in a mixin, but is fine without?

2016-05-01 Thread pineapple via Digitalmars-d-learn
On Sunday, 1 May 2016 at 13:46:14 UTC, ag0aep6g wrote: On 01.05.2016 15:32, pineapple wrote: static string vectorpropertymixin(string name, string SDL_getter, string SDL_setter){ [...] mixin(vectorpropertymixin( "minsize", "SDL_GetWindowMinimumSize", "SDL_GetWindowMinimumSize" ));

Re: Method doesn't compile when defined in a mixin, but is fine without?

2016-05-01 Thread pineapple via Digitalmars-d-learn
Strangely, though I'm getting this error when wrapping SDL_GetWindowMinimumSize and SDL_GetWindowMaximumSize, I don't get any compilation errors wrapping the identically-signatured SDL_GetWindowSize and SDL_GetWindowPosition using the same mixin.

Re: what's the right way to get char* from string?

2016-05-05 Thread pineapple via Digitalmars-d-learn
On Thursday, 5 May 2016 at 07:49:46 UTC, aki wrote: Hello, When I need to call C function, often need to have char* pointer from string. This might help: import std.traits : isSomeString; import std.string : toStringz; extern (C) int strcmp(char* string1, char* string2); int strcmpD0(S)(in

Re: Compiler silently ignores some method overloads

2016-05-10 Thread pineapple via Digitalmars-d-learn
On Monday, 9 May 2016 at 18:56:15 UTC, Peter Häggman wrote: No problem here (tested with everything in a single module). I can't help more. Front end version ? Well, this is the full struct that has those malfeasant overrides: http://pastebin.com/9h2s028J

Accessing __FILE__ and __LINE__ of caller in combination with varargs?

2016-04-15 Thread pineapple via Digitalmars-d-learn
I've written a very handy assertf method whose signature looks like this: void assertf(Args...)(lazy bool condition, in string message, Args args) But I'd also like to access the caller's file and line to use them in constructing a thrown AssertError, and I'm stumbling on how I can get

Re: Accessing __FILE__ and __LINE__ of caller in combination with varargs?

2016-04-15 Thread pineapple via Digitalmars-d-learn
On Friday, 15 April 2016 at 20:52:42 UTC, WebFreak001 wrote: void assertf(string file = __FILE__, size_t line = __LINE__, Args...)(lazy bool condition, in string message, Args args) { Aha, you are the best. Thanks!

Compiler silently ignores some method overloads

2016-05-08 Thread pineapple via Digitalmars-d-learn
In my struct I have some methods with these signatures: void opIndexAssign(T)(in GLColor!T color, in int x, in int y) void opIndexAssign(T1, T2)(in GLColor!T1 color, in Vector2!T2 vector) void opIndexAssign(in uint value, in int x, in int y) And when I try to do this:

Re: Compiler silently ignores some method overloads

2016-05-09 Thread pineapple via Digitalmars-d-learn
On Monday, 9 May 2016 at 00:27:17 UTC, Peter Häggman wrote: Can you show your GLColor struct ? Maybe it contains an alias this or something else that mess the overload resolution. My GLColor struct: http://pastebin.com/mUcA6G85

What's wrong with my usage of std.algorithm.map in this code example?

2016-05-24 Thread pineapple via Digitalmars-d-learn
I would've expected this to work, but instead I get a compile error. Is my syntax wrong? Is this just not a case that map can handle, and I should be doing something else? import std.algorithm : map; import std.conv : to; import std.stdio : writeln; import std.string : join;

Re: What's wrong with my usage of std.algorithm.map in this code example?

2016-05-25 Thread pineapple via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 20:18:34 UTC, Steven Schveighoffer wrote: Slice assignment from range to array is not supported. In your example, I'm curious why the efforts to specify the type? I think it would work with just saying auto itemstrings = ... -Steve I still get an error if I use

Re: Verifying the arguments of a function with ref parameters?

2016-07-28 Thread pineapple via Digitalmars-d-learn
On Thursday, 28 July 2016 at 21:49:00 UTC, pineapple wrote: On Thursday, 28 July 2016 at 20:28:39 UTC, jdfgjdf wrote: "Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with" What would be a better

Re: Verifying the arguments of a function with ref parameters?

2016-07-28 Thread pineapple via Digitalmars-d-learn
On Thursday, 28 July 2016 at 20:28:39 UTC, jdfgjdf wrote: "Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with" What would be a better way to check whether some callable can be called using a

Re: string mixin and alias

2016-07-29 Thread pineapple via Digitalmars-d-learn
On Friday, 29 July 2016 at 12:22:54 UTC, Andre Pany wrote: It is more or less syntax sugar. In the main function instead of writing "mixin(generateCode(s));" I want to write "foo(s);". So, the mixin statement is hidden while the functionality of mixin stays. Kind regards André As far as I

Re: string mixin and alias

2016-07-29 Thread pineapple via Digitalmars-d-learn
On Friday, 29 July 2016 at 06:38:17 UTC, Andre Pany wrote: Hi, is there a way to alias a string mixin? Neither foo nor foo2 compiles. import std.meta : Alias; alias foo = (s) => Alias!(mixin(generateCode(s))); alias foo2(string s) = Alias!(mixin(generateCode(s))); string generateCode(string

FunctionTypeOf behaves unexpectedly for function pointers?

2016-07-29 Thread pineapple via Digitalmars-d-learn
This failure seems curious and I haven't been able to understand why it occurs, or whether it might be intentional. For all other callable types, including functions and delegates and types implementing opCall, the assertion passes. import std.traits : FunctionTypeOf; void function()

Re: FunctionTypeOf behaves unexpectedly for function pointers?

2016-08-01 Thread pineapple via Digitalmars-d-learn
On Saturday, 30 July 2016 at 12:54:32 UTC, Basile B. wrote: func is a pointer to a function but FunctionTypeOf extracts the target type. So the correct assertion is static assert(is(FunctionTypeOf!func* == typeof(func))); I can't believe that it worked for delegates because the same

Re: Why Does Dscanner Warn About a Missing toHash if opEquals is Defined?

2016-08-01 Thread pineapple via Digitalmars-d-learn
On Sunday, 31 July 2016 at 18:57:50 UTC, Jack Stouffer wrote: Next question: what's the fastest hashing implementation that will provide the least collisions? Is there a hash implementation that's perfered for AAs? There's no hashing function that would be specifically better for associative

Re: minor question of the difference between " and '

2016-08-11 Thread pineapple via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 23:32:54 UTC, WhatMeWorry wrote: Afterall, isn't that the definition of a string? So what's up with the two groupings of single quotes? http://www.howtogeek.com/howto/29980/whats-the-difference-between-single-and-double-quotes-in-the-bash-shell/

Interface final methods are erased by the overloads of a subclass

2016-07-13 Thread pineapple via Digitalmars-d-learn
I was surprised when this didn't work. What's the rationale? Is there any better workaround than renaming methods? interface A{ void foo(); final void foo(int x){} } class B: A{ void foo(){} } void main(){ auto b = new B(); b.foo();

Re: shuffle a character array

2016-07-21 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 18:32:15 UTC, Jesse Phillips wrote: I think you mean that your range library treats them as arrays of code units, meaning your library will break (some) unicode strings. Right - I disagree with the assessment that all (or even most) char[] types are intended to

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread pineapple via Digitalmars-d-learn
On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. most of the time you can put `immutable` or something like that there to note that it is not reusing (purely cosmetical thing), but sometimes you

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread pineapple via Digitalmars-d-learn
On Sunday, 17 July 2016 at 01:57:21 UTC, pineapple wrote: On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. most of the time you can put `immutable` or something like that there to note that it is not

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 08:02:07 UTC, Mike Parker wrote: You can then go to the documentation for std.range.primitives.isRandomAccessRange [2], where you'll find the following: "Although char[] and wchar[] (as well as their qualified versions including string and wstring) are arrays,

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 13:33:34 UTC, Mike Parker wrote: There is no auto-decoding going on here, as char[] and wchar[] are rejected outright since they are not considered random access ranges. They are considered random access ranges by my ranges library, because they are treated as

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 16:03:27 UTC, pineapple wrote: On Wednesday, 20 July 2016 at 13:33:34 UTC, Mike Parker wrote: There is no auto-decoding going on here, as char[] and wchar[] are rejected outright since they are not considered random access ranges. They are considered random

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 16:04:50 UTC, pineapple wrote: On Wednesday, 20 July 2016 at 16:03:27 UTC, pineapple wrote: On Wednesday, 20 July 2016 at 13:33:34 UTC, Mike Parker wrote: There is no auto-decoding going on here, as char[] and wchar[] are rejected outright since they are not

Re: Typesafe variadic functions requiring at least one argument

2016-07-07 Thread pineapple via Digitalmars-d-learn
On Thursday, 7 July 2016 at 03:52:40 UTC, Jonathan M Davis wrote: However, it looks like you can combine those two types of variadic functions to get more or less what you want (albeit more verbosely). e.g. template isInt(T) { enum isInt = is(std.traits.Unqual!T == int); } void

Typesafe variadic functions requiring at least one argument

2016-07-06 Thread pineapple via Digitalmars-d-learn
I'd like to do something like this but it doesn't seem to be legal - void test(int[] ints...) if(ints.length){ // stuff } Not being able to specify this interferes with how I'd like to define my method overloads. What's the best way to achieve what I'm looking for?

Defining and overriding methods of an abstract base class which must accept a template parameter

2016-07-10 Thread pineapple via Digitalmars-d-learn
This is essentially what I'm trying to accomplish. The intuitive solution, of course, does not work. In theory I could write a separate method for every anticipated return type, but that would be horrible and in that case I'd probably just write the damn thing in a dynamically-typed language

Re: Defining and overriding methods of an abstract base class which must accept a template parameter

2016-07-10 Thread pineapple via Digitalmars-d-learn
On Sunday, 10 July 2016 at 21:20:34 UTC, Basile B. wrote: The problem you encounter here is that templatized functions cannot be virtual. If you remove "abstract" and put an empty body than it works, but you lose the whole OOP thing, i.e you cannot call the most derived override from the base.

Verifying the arguments of a function with ref parameters?

2016-07-28 Thread pineapple via Digitalmars-d-learn
Why doesn't this code do what I'd expect it to, and how can I fix it? unittest{ import std.traits : Parameters; // Works as expected alias dg = int delegate(int value); enum bool dgcallable = is(typeof((){dg(Parameters!dg.init);})); pragma(msg,

Re: compile error while use `extern(C++, class)`

2016-08-18 Thread pineapple via Digitalmars-d-learn
On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta wrote: On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote: On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta wrote: Which kind of error? An error message by the compiler? One by the linker? The compiler crashes?

Re: Getting the superclass of a type?

2016-09-05 Thread pineapple via Digitalmars-d-learn
On Monday, 5 September 2016 at 15:43:52 UTC, Lodovico Giaretta wrote: On Monday, 5 September 2016 at 15:20:10 UTC, pineapple wrote: I'd like to be able to write something like this, but I haven't been able to find anything in the docs class Base{} class Sub: Base{} static

Re: Inexplicable invalid memory operation when program terminates

2016-09-05 Thread pineapple via Digitalmars-d-learn
On Monday, 5 September 2016 at 17:33:17 UTC, pineapple wrote: Am I missing something or is this an obnoxious bug with the GC? Oh, I've been trying to figure this out on and off for days and of course five minutes after I post I fix the problem. I'm not really sure why, but it did fix it.

Getting the superclass of a type?

2016-09-05 Thread pineapple via Digitalmars-d-learn
I'd like to be able to write something like this, but I haven't been able to find anything in the docs class Base{} class Sub: Base{} static assert(is(SuperClassOf!Sub == Base));

What is this behavior and how do I disable or get around it?

2016-09-04 Thread pineapple via Digitalmars-d-learn
This program does not compile. Error: cannot implicitly convert expression (cast(int)x - cast(int)x) of type int to ubyte void main(){ ubyte x; x = x - x; } I don't even know what to say. Who thought this behavior was a good idea?

Re: Templates problem

2016-09-07 Thread pineapple via Digitalmars-d-learn
On Wednesday, 7 September 2016 at 20:29:42 UTC, jmh530 wrote: Thanks for the reply. It looks like an interesting idea. You might consider adding this (or a modified version) to a read me in the range subfolder. Fuck it, I took an hour to document the most significant modules.

Re: Checking all elements are unique.

2016-08-31 Thread pineapple via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund wrote: Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C

Re: Prevent copy of range in foreach

2016-08-31 Thread pineapple via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 14:03:20 UTC, Yuxuan Shui wrote: I want to make a hash table that uses std.experiment.allocator. The bucket is allocated from an allocator, and freed in ~this(). I don't want to copy the whole bucket in this(this). Maybe I should use a reference counter or

Re: Fully-qualified symbol disambiguation is deprecated???

2016-09-09 Thread pineapple via Digitalmars-d-learn
On Friday, 9 September 2016 at 11:54:42 UTC, Steven Schveighoffer wrote: Can you demonstrate the issue? I have never heard of this. imports should work when done inside a function. -Steve Tried and failed to reproduce with a simple example, but any time I've tried doing it in the code I'm

Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-10 Thread pineapple via Digitalmars-d-learn
I've got a struct and it would be very convenient if I could specify what happens when I write `if(value)` - is this possible?

Re: Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-10 Thread pineapple via Digitalmars-d-learn
On Saturday, 10 September 2016 at 14:24:23 UTC, ag0aep6g wrote: On 09/10/2016 04:10 PM, pineapple wrote: I've got a struct and it would be very convenient if I could specify what happens when I write `if(value)` - is this possible? `if (value)` implies a cast to bool. Define opCast!bool and

Re: Using local import path

2016-09-09 Thread pineapple via Digitalmars-d-learn
On Friday, 9 September 2016 at 09:43:15 UTC, O-N-S wrote: On Friday, 9 September 2016 at 09:31:54 UTC, pineapple wrote: On Friday, 9 September 2016 at 08:25:40 UTC, rikki cattermole wrote: TLDR: no you cannot do what you were thinking. Seems like something one ought to be able to do, though.

Re: Using local import path

2016-09-09 Thread pineapple via Digitalmars-d-learn
On Friday, 9 September 2016 at 08:25:40 UTC, rikki cattermole wrote: TLDR: no you cannot do what you were thinking. Seems like something one ought to be able to do, though. DIP time?

Re: Fully-qualified symbol disambiguation is deprecated???

2016-09-09 Thread pineapple via Digitalmars-d-learn
On Thursday, 8 September 2016 at 22:13:26 UTC, Steven Schveighoffer wrote: I posted an article on this: http://www.schveiguy.com/blog/2016/03/import-changes-in-d-2-071/ -Steve Regarding that article: Another import-related bug fix is to prevent unintentional hijacking of symbols inside a

Re: Why can't static arrays be sorted?

2016-10-06 Thread pineapple via Digitalmars-d-learn
On Wednesday, 5 October 2016 at 19:30:01 UTC, Jonathan M Davis wrote: Would just like to point out that this is design weirdness on Phobos' part - the library I've been writing does not have this problem. It doesn't even make conceptual sense for a static array to be a range, because you

  1   2   >