Re: Struct that destroys its original handle on copy-by-value

2015-07-29 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 19:10:36 UTC, Adam D. Ruppe wrote: On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: My aim by contrast is to _allow_ that kind of use, but render the original handle empty when it's done. I don't think D offers any way to do that. With the

Re: Template function that accept strings and array of strings

2015-07-15 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote: Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T

Re: turning an array of structs into a struct of arrays

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 5 July 2015 at 00:07:59 UTC, Laeeth Isharc wrote: Posted short write-up here. Please make it better... http://wiki.dlang.org/Transforming_slice_of_structs_into_struct_of_slices In John Colvin's solution, should alias TransformMembers(alias TypeTransform, alias

documenting compile-time constants

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation.

Re: documenting compile-time constants

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 03:30:40 UTC, Rikki Cattermole wrote: On 7/07/2015 1:05 p.m., Vlad Levenfeld wrote: How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation. If: /// enum MyValue

Re: std.parallelism and multidimensional arrays

2015-05-22 Thread Vlad Levenfeld via Digitalmars-d-learn
On Friday, 22 May 2015 at 10:54:36 UTC, Stefan Frijters wrote: I have a code which does a lot of work on 2D/3D arrays, for which I use the 2.066 multidimensional slicing syntax through a fork of the Unstandard package [1]. Many times the order of operations doesn't matter and I thought I would

Re: functors with template lambdas

2015-05-15 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 16 May 2015 at 02:08:09 UTC, weaselcat wrote: On Saturday, 16 May 2015 at 02:06:45 UTC, weaselcat wrote: very long standing compiler bug https://issues.dlang.org/show_bug.cgi?id=3051 see also https://issues.dlang.org/show_bug.cgi?id=5710 unsure if they're duplicate bugs, never

functors with template lambdas

2015-05-15 Thread Vlad Levenfeld via Digitalmars-d-learn
I think this code should be allowed, but it isn't: struct Functor (T) { T a; auto ref fmap (alias f)() { return Functor (f(a)); } } auto ref identity (T)(auto ref T a)

anonymous template predicates

2015-04-30 Thread Vlad Levenfeld via Digitalmars-d-learn
I was wondering if there's a mechanism to make anonymous templates, e.g. given: enum Policy {A, B} alias List = TypeTuple!(...); instead of this: enum has_policy_A (T) = T.policy == Policy.A; alias Result = Filter!(has_policy_A, List); use something like this: Filter!(T = T.policy

Re: Private alias escaping -- is this a bug?

2015-04-25 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 25 April 2015 at 23:51:05 UTC, rcorre wrote: I ran into this infuriatingly confusing situation just now: static assert(is(typeof(Parent.init.new Child) == Parent.Child)); // fine alias P = Parent; alias T = Parent.Child; static assert(is(typeof(P.init.new T) == T)); // nope!

Re: how does isInputRange(T) actually work?

2015-04-22 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 22 April 2015 at 21:22:43 UTC, Meta wrote: That makes sense. It seems to me that D has very... special but effective syntax. I'm having a hard time remembering all the keywords and expression forms (especially of IsExpression) but it's definitely a vast improvement over C++'s

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 07:01:27 UTC, Per Nordlöw wrote: On Tuesday, 21 April 2015 at 06:56:33 UTC, Per Nordlöw wrote: On Monday, 20 April 2015 at 13:49:41 UTC, John Colvin wrote: On Thursday, 16 April 2015 at 18:12:35 UTC, Nordlöw wrote: Is there a way to CT-query the arity of all

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
As an aside, I've put a bit of work into the generic multidimensional containers problem lately and have an interface generating library as a result. https://github.com/evenex/autodata It's still in the nascent stages but contains a lot of tools for working with multidimensional structures.

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 08:09:38 UTC, Per Nordlöw wrote: On Tuesday, 21 April 2015 at 07:46:03 UTC, Vlad Levenfeld wrote: template dimensionality (S) { template count_dim (uint i = 0) { static if (is (typeof(S.init.opSlice!i (0,0 enum count_dim = count_dim!(i+1); else enum

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
template dimensionality (S) { template count_dim (uint i = 0) { static if (is (typeof(S.init.opSlice!i (0,0 enum count_dim = count_dim!(i+1); else static if (i == 0 (isInputRange!S || is (typeof(S.init[0]))) enum count_dim = 1; else enum count_dim = i; }

Re: CT-String as a Symbol

2015-04-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 19:46:03 UTC, Nordlöw wrote: On Tuesday, 21 April 2015 at 07:46:03 UTC, Vlad Levenfeld wrote: Then you throw in some more stuff to detect 1-dimensional cases. Could you please elaborate a bit? Well assuming the type is not multidimensional (does not define

Re: About @ and UDA

2015-04-16 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 15 April 2015 at 16:59:12 UTC, ketmar wrote: or make safe and company context keywords. along with body (oh, how i hate the unabilily to declare body member!) Ugh, yeah. Makes physics code awkward.

Re: alias this of non-public member

2015-04-07 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 19:17:41 UTC, Márcio Martins wrote: Proxy doesn't really help here :( Nothing will help you get around this. You have to expose a public member and alias to that. Try wrapping the access in a public zero-parameter member function.

Re: lambda code

2015-04-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Thursday, 2 April 2015 at 19:27:21 UTC, John Colvin wrote: On Wednesday, 1 April 2015 at 23:29:00 UTC, Vlad Levenfeld wrote: On Tuesday, 31 March 2015 at 13:25:47 UTC, John Colvin wrote: On Tuesday, 31 March 2015 at 12:49:36 UTC, Vlad Levenfeld wrote: Is there any way (or could there be any

Re: lambda code

2015-04-01 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 13:25:47 UTC, John Colvin wrote: On Tuesday, 31 March 2015 at 12:49:36 UTC, Vlad Levenfeld wrote: Is there any way (or could there be any way, in the future) of getting the code from lambda expressions as a string? I've noticed that if I have an error with a

lambda code

2015-03-31 Thread Vlad Levenfeld via Digitalmars-d-learn
Is there any way (or could there be any way, in the future) of getting the code from lambda expressions as a string? I've noticed that if I have an error with a lambda that looks like, say x=x+a the error message will come up referring to it as (x) = x + a so some level of processing

reflect on this function

2015-02-20 Thread Vlad Levenfeld via Digitalmars-d-learn
I'd like to do something like this: @reflexive @transitive bool relation (T)(T a, T b) out (result) { mixin(property_verification!result); } body { ... } which becomes out (result) { // generated from @reflexive assert (result == skip_contract!relation (b,a));

Re: reflect on this function

2015-02-20 Thread Vlad Levenfeld via Digitalmars-d-learn
On Friday, 20 February 2015 at 22:44:35 UTC, ketmar wrote: can you go with `relationImpl` and mixin/template that generates `relation` with contract then? something like: @reflexive @transitive bool relationImpl (T)(T a, T b) { ... } alias relation = buildWithContracts!relationImpl; then

Re: BigFloat?

2015-02-17 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 17 February 2015 at 14:03:45 UTC, Kagamin wrote: On Tuesday, 17 February 2015 at 09:08:17 UTC, Vlad Levenfeld wrote: For my use case I'm less concerned with absolute resolution than with preserving the information in the smaller operand when dealing with large magnitude

Re: BigFloat?

2015-02-17 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 17 February 2015 at 08:05:49 UTC, Kagamin wrote: Periodic fractions. Or transcendental numbers, for that matter, but arbitrary != infinite. A max_expansion template parameter could be useful here. For my use case I'm less concerned with absolute resolution than with preserving

BigFloat?

2015-02-16 Thread Vlad Levenfeld via Digitalmars-d-learn
We've got arbitrary precision integers, why not arbitrary precision floating point?

Re: function and variable

2015-02-09 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 03:59:22 UTC, Rikki Cattermole wrote: That's a bug. It should be using the function pointer. UFCS call should abide by the same scoping rules as anything else. https://issues.dlang.org/show_bug.cgi?id=14161 I thought that's how UFCS was explicitly designed?

Re: function and variable

2015-02-09 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 04:20:27 UTC, Fyodor Ustinov wrote: IMHO even if it is not a bug, it is a feature - it should not be compiled without notice. WBR, Fyodor. Agreed, should be a warning at least.

strange alias behavior

2015-02-05 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm expecting in this code http://dpaste.dzfl.pl/ee0d3cd31734 either line 8 should not compile, or lines 12 and 14 should have a totally different output. What's going on?

Re: Deducing a template retrun parameter type based on an assignment?

2015-01-29 Thread Vlad Levenfeld via Digitalmars-d-learn
On Friday, 30 January 2015 at 06:35:31 UTC, Jeremy DeHaan wrote: I have a template fuction that looks like this: immutable(T)[] getString(T)() const if (is(T == dchar)||is(T == wchar)||is(T == char)) Basically, I was hoping that the type would be deduced based on the prameter that was being

Re: Deducing a template retrun parameter type based on an assignment?

2015-01-29 Thread Vlad Levenfeld via Digitalmars-d-learn
On Friday, 30 January 2015 at 07:13:09 UTC, Jeremy DeHaan wrote: That seems strange. I figured that it would be smart enough to deduce the parameter type based on the type that it was trying to be assigned to. It seems sensible to me, as changing string to auto would leave the type of the

Re: using the full range of ubyte with iota

2015-01-24 Thread Vlad Levenfeld via Digitalmars-d-learn
you can always write your own iota replacement, which will do [] and use ubytes, for example. writing that things is way easier than in C++. something like myIota!ubyte(0, 255), for example -- to make it visible that it emits ubytes. I think closedInterval!T (T left, T right) would be a

Re: Defining a static array with values in a range

2015-01-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Thursday, 22 January 2015 at 05:56:40 UTC, tcak wrote: I want to define alphanumeric characters in an easy way. Something like that: char[] arr = ['a'..'z', 'A'..'Z', '0'..'9']; Though above example doesn't work. Is there any easy way to do this? I am trying to do something like EBNF

Re: import conflicts

2015-01-18 Thread Vlad Levenfeld via Digitalmars-d-learn
I get this all the time with std.array.array (I use my own array implementations, but phobos' array seems to secretly creep in everywhere). I think its got to do with that private import visibility bug (https://issues.dlang.org/show_bug.cgi?id=314 or

Re: Struggling with shared objects

2015-01-17 Thread Vlad Levenfeld via Digitalmars-d-learn
That's real weird. In D:\D\dmd2\src\phobos\std\concurrency.d(13,13) 13,13 isn't a line number and static assertions should go off during compilation, not runtime.

Re: Example usage of the core.sync classes

2015-01-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 3 January 2015 at 15:44:16 UTC, Matt wrote: Right, I've been looking at core.atomic, but it has very little documentation, and it's territory I haven't explored, yet. Any chance of some pointers along the way? Could you be more specific about what you need help understanding?

Re: Example usage of the core.sync classes

2015-01-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 4 January 2015 at 01:02:07 UTC, Matt wrote: What I mean is that I don't understand what atomicStore, atomicLoad, etc. actually DO, although in the case of the two mentioned, I can hazard a pretty good guess. The documentation doesn't exist to tell me how to use the functions found

Re: Example usage of the core.sync classes

2015-01-02 Thread Vlad Levenfeld via Digitalmars-d-learn
On Friday, 2 January 2015 at 17:39:19 UTC, Matt wrote: I'm trying to write a small 3D engine, and wanted to place the physics in a separate thread to the graphics, using events, possibly std.concurrency, to communicate between them. How, then, do I pass large amounts of data between threads?

Re: Data Frames in D - let's not wait for linear algebra; useful today in finance and Internet of Things

2014-12-28 Thread Vlad Levenfeld via Digitalmars-d-learn
Laeeth - I am not sure exactly what your needs are but I have a fairly complete solution for generic multidimensional interfaces (template-based, bounds checked, RAII-ready, non-integer indices, the whole shebang) that I have been building. Anyway I don't want to spam the forum if I've missed the

Re: dub dustmite

2014-12-14 Thread Vlad Levenfeld via Digitalmars-d-learn
No luck, unfortunately.

dub dustmite

2014-12-11 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm trying to reduce a bug with dub dustmite feature and I must be doing it wrong somehow, my regular dub output looks like this: source/experimental.d(2403): Error: struct experimental.Product!(int[], int[]).Product no size yet for forward reference ulong[2] source/experimental.d(2454):

Re: windows linker error

2014-11-25 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 25 November 2014 at 21:22:24 UTC, Vlad Levenfeld wrote: On Windows 7 I have built dmd (using the vcxproj), druntime (win64.mak) and phobos (win64.mak). I went into sc.ini and set the LINKCMD to point to Visual Studio 12.0's linker. When I try to compile anything with dmd, I get

Re: windows linker error

2014-11-25 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 26 November 2014 at 01:35:20 UTC, Joakim wrote: On Tuesday, 25 November 2014 at 23:08:07 UTC, Vlad Levenfeld wrote: On Tuesday, 25 November 2014 at 21:22:24 UTC, Vlad Levenfeld wrote: On Windows 7 I have built dmd (using the vcxproj), druntime (win64.mak) and phobos (win64.mak).

function not callable using argument types - i disagree

2014-10-07 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm trying to use the portaudio bindings and can't seem to call Pa_OpenStream, I get this error: source/pa_test.d(156): Error: function deimos.portaudio.Pa_OpenStream (void** stream, const(PaStreamParameters*) inputParameters, const(PaStreamParameters*) outputParameters, double

Re: function not callable using argument types - i disagree

2014-10-07 Thread Vlad Levenfeld via Digitalmars-d-learn
Update: I just did a manual cast. Still getting there error. Here's the new argument lists: (void**, const(PaStreamParameters*), const(PaStreamParameters*), double, uint, uint, extern (C) int function(const(void)*, void*, uint, const(PaStreamCallbackTimeInfo)*, uint, void*), void*) (void**,

Re: profiling issues

2014-09-12 Thread Vlad Levenfeld via Digitalmars-d-learn
Awesome! These are exactly what I was looking for. Thanks!

profiling issues

2014-09-11 Thread Vlad Levenfeld via Digitalmars-d-learn
I've got a library I've been building up over a few projects, and I've only ever run it under debug unittest and release (with dub buildOptions). Lately I've needed to control the performance more carefully, but unfortunately trying to compile with dub --profile gives me some strange errors:

Re: Intended behavior of std.range.cycle?

2014-09-05 Thread Vlad Levenfeld via Digitalmars-d-learn
On Thursday, 4 September 2014 at 11:43:28 UTC, monarch_dodra wrote: *Should* cycle be negatively index-able? Personally, I don't think so. And even if it could, it has been proven non-size_t indexing is not well supported at all. It was de-facto chosen after the iota-map fiasco that all ranges

Re: const-correctness in std.range

2014-09-02 Thread Vlad Levenfeld via Digitalmars-d-learn
Thanks for the reply. And indeed, I recently found that ByLine.empty can't be const because it writes and removes a character from the stream or something... and when I compile with optimizations, const empty gets totally wrecked. I suppose that making empty const doesn't really gain me

const-correctness in std.range

2014-08-31 Thread Vlad Levenfeld via Digitalmars-d-learn
I notice that some of the range adapters in std.range (iota, takeExactly) have a const empty property, while others (take, retro) don't. This makes maintaining const-correctness downstream (with my own range adapters atop phobos') more difficult. I'm wondering if there is a rationale for this,

Re: @safe, pure and nothrow at the beginning of a module

2014-08-15 Thread Vlad Levenfeld via Digitalmars-d-learn
On Friday, 15 August 2014 at 16:54:54 UTC, Philippe Sigaud wrote: So I'm trying to use @safe, pure and nothrow. If I understand correctly Adam Ruppe's Cookbook, by putting @safe: pure: nothrow: at the beginning of a module, I distribute it on all definitions, right? Even methods, inner

undefined references

2014-08-10 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm compiling with DMD 2.065 using dub, and I've gotten some undefined reference errors for symbols inside my own project. Trying to run dustmite doesn't help, it keeps reporting that its done in one iteration, and gives me an empty results folder. I've used it before, its pretty

Re: undefined references

2014-08-10 Thread Vlad Levenfeld via Digitalmars-d-learn
Ok, I've gotten to the bottom of this issue but I'm not totally sure how to submit a bug report for this (no SSCCE: can't get dustmite to work on it, and the problem won't show itself when I use the offending module in isolation) so I will try to sum up the issue and maybe I can provide some

Re: opDispatch compiles fine, but still fails to resolve?

2014-08-09 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 9 August 2014 at 10:36:55 UTC, Artur Skawina via Digitalmars-d-learn wrote: On 08/09/14 03:20, Vlad Levenfeld via Digitalmars-d-learn wrote: More opDispatch woes. This feature keeps biting me, yet I keep trying to use it. This time I'm trying to access elements of a vector GLSL

Re: opDispatch compiles fine, but still fails to resolve?

2014-08-09 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 9 August 2014 at 05:42:09 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Why would having opDispatch actually generate compile errors cause problems for __traits(compiles,...)? __traits(compiles...) already works fine with a whole bunch of other non-compiling stuff (by gagging

tuple slicing operator

2014-08-09 Thread Vlad Levenfeld via Digitalmars-d-learn
I may be misunderstanding the intended semantics of the [] operator but I've come to interpret x[] to mean give me x as a range and this is the meaning I intend when I overload it in my own structs. But - auto z = tuple (1,1,1); pragma (msg, typeof(z)); // Tuple!(int, int, int) pragma (msg,

Re: tuple slicing operator

2014-08-09 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 9 August 2014 at 19:26:46 UTC, Meta wrote: (which is why z[] gives you a type of (int, int, int) instead of Tuple!(int, int, int)). That makes sense, and on second thought it wouldn't make sense to use a tuple as a range because it's not guaranteed to have only one element type.

opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread Vlad Levenfeld via Digitalmars-d-learn
More opDispatch woes. This feature keeps biting me, yet I keep trying to use it. This time I'm trying to access elements of a vector GLSL-style (without swizzling... for now). Here's the relevant code: struct Vector (uint length, Element = double) { ref @property component

Re: opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread Vlad Levenfeld via Digitalmars-d-learn
Yep, replacing @property with auto did the trick. The lack of error messages in opDispatch is frustrating. I realize that, due to tricks like __traits(compiles, Foo.testing_for_some_function), having opDispatch stop compilation if it fails is not going to work, but there's gotta be some way

Re: multidimensional indexing/slicing docs?

2014-08-06 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 08:48:25 UTC, John Colvin wrote: Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this? I'm curious about this as well. I've just come across a case where I need to work with a 2D array of channels*samples from an

private selective imports

2014-08-06 Thread Vlad Levenfeld via Digitalmars-d-learn
Is there any way to make selective imports private? I've got a name clash from importing an all module that has a bunch of public imports, one of which is circular, it goes sort of like this: module math.all; public: import geometry; import vectors; --- module vectors; struct Vector {}

Re: private selective imports

2014-08-06 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 +1 from me as well. This is unfortunate. D otherwise has a very comfortable import system.

Re: private selective imports

2014-08-06 Thread Vlad Levenfeld via Digitalmars-d-learn
Sure, but people keep using them at the module-level, which really shouldn't be done until the bug is fixed. IMHO, we'd be better off making it illegal to use selective imports at the module-level rather than keeping it as-is. - Jonathan M Davis I'm curious, what's the problem with it

auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
This doesn't work: 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 What am I doing wrong? Is this not a template function?

Re: auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
This would make the function always take its argument by reference. I'm trying to use the feature here: http://dlang.org/template.html from the section Function Templates with Auto Ref Parameters

Re: auto ref function parameters in a free function

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

Re: auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 3 August 2014 at 19:43:53 UTC, anonymous wrote: If this exact code errors for you, it ... uhh ... could be platform specific? Are you on Windows? Debian, and your code works for me. I figured out the problem - I made less_than to serve as a default sorting predicate, so in a few

Re: auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 3 August 2014 at 20:10:39 UTC, Martijn Pot wrote: What is the benefit of 'auto ref' over 'in' as you are changing a nor b? Because less_than (T)(T a, T b) (or in, or const T) will copy a and b on their way into the function. Usually this is ok but certain data structures I use

Re: auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 3 August 2014 at 21:24:03 UTC, Vlad Levenfeld wrote: certain data structures I use are not intended to be copied, . although these cases are probably better off being compared by some kind of key rather than directly... so, auto ref isn't necessary here, it was just something

Re: auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 3 August 2014 at 21:47:06 UTC, Artur Skawina via Digitalmars-d-learn wrote: void sort (R, T = ElementType!R, alias compare = less_than)(R range, T item) [should work iff the sort implementation only calls the predicate] artur This works! Thanks!

why does isForwardRange work like this?

2014-07-31 Thread Vlad Levenfeld via Digitalmars-d-learn
I've been having trouble propagating range traits for range-wrapper structs. Consider this sample code: struct Wrapper (R) { R range; static if (isInputRange!R) { /* input range stuff */ } static if (isForwardRange!R) {

Re: memory/array question

2014-07-31 Thread Vlad Levenfeld via Digitalmars-d-learn
On Thursday, 31 July 2014 at 20:43:11 UTC, bearophile wrote: Take a look at the asm! Bye, bearophile I use DMD and Dub, how do I view the asm?

Re: why does isForwardRange work like this?

2014-07-31 Thread Vlad Levenfeld via Digitalmars-d-learn
Yes, I see the problem now. I can't think of any reason why I'd want to make save anything but a function (especially since `save` is a verb) but I guess someone out there might have a good one. So, what is gained by (inout int = 0) over ()? I wasn't even aware that giving a default value

pure delegates and opApply

2014-07-29 Thread Vlad Levenfeld via Digitalmars-d-learn
I have some use cases where I am trying to iterate over a collection in a pure function. The collection doesn't change, but the foreach loop body updates a variable elsewhere in the function body. (I'm reimplementing reduce as pure nothrow, and the variable in question is the accumulator).

Re: Showing a user specified error message when no overloads match

2014-07-29 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 29 July 2014 at 15:47:08 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Maybe we should file an enhancement bug to improve error reporting for opDispatch. I found this https://issues.dlang.org/show_bug.cgi?id=8387 and cast a vote for it. I've cast a few votes in the bugtracker,

clear works better than it ought to considered i never defined it

2014-07-28 Thread Vlad Levenfeld via Digitalmars-d-learn
A weird thing happened: I was building a dictionary struct which contains a custom array of values and a differently-typed custom array of keys. Both of them implicitly define clear by aliasing a backing array. The dictionary type doesn't have clear, though. And it doesn't alias anything.

Re: clear works better than it ought to considered i never defined it

2014-07-28 Thread Vlad Levenfeld via Digitalmars-d-learn
Yep, just checked in the debugger. So, that's actually a bad thing, then. Good thing its being deprecated!

Re: Showing a user specified error message when no overloads match

2014-07-28 Thread Vlad Levenfeld via Digitalmars-d-learn
opDispatch behaves as though it has SFINAE. When something fails in the definition (like I am having now, some of the symbols I used in it hadn't been imported) there won't ever be an error message, I just get Error: no property 'bar' for type 'Foo' In one case I had to use static ifs and

Re: Map one tuple to another Tuple of different type

2014-07-22 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm just confused about how static while is supposed to work because static foreach, to my understanding, would have to work by making a new type for each iteration. I say this because, 1) runtime foreach works like that (with type = range), and 2) without ctfe foreach, the only way I know of

Re: Map one tuple to another Tuple of different type

2014-07-22 Thread Vlad Levenfeld via Digitalmars-d-learn
Yes, though the loop unrolling is news to me. I'll have to keep that in mind next time I'm trying to squeeze some extra performance out of a loop. btw, found a static switch enhancement request here: https://issues.dlang.org/show_bug.cgi?id=6921

Re: Compile-Time Interfaces (Concepts)

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 20 July 2014 at 15:45:37 UTC, Atila Neves wrote: On Thursday, 17 July 2014 at 22:52:37 UTC, Justin Whear wrote: On Thu, 17 Jul 2014 22:49:30 +, Nordlöw wrote: AFAIK there is no compile-time variant of interfaces right? Why is that? Wouldn't it be nice to say something like

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
Thats real weird that it would reject your i variable, given that T.length is known at compile time. I think this is a bug. I can get your code to compile if I change your foreach loop to this: foreach(i, U; T) modTuple[i] = transTupleElem(argTuple[i]); // ok

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Monday, 21 July 2014 at 01:29:40 UTC, Daniel Gibson wrote: Am 21.07.2014 03:05, schrieb Vlad Levenfeld: Thats real weird that it would reject your i variable, given that T.length is known at compile time. I think this is a bug. I can get your code to compile if I change your foreach loop

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread Vlad Levenfeld via Digitalmars-d-learn
On Monday, 21 July 2014 at 19:02:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: functionality is desirable. Maybe we should rouse a racket on the main D forum to either make staticIota public, or implement static foreach. ;-) static switch would be so sick. I frequently find myself doing

Re: shared and nonshared dtor

2014-07-20 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 20 July 2014 at 08:29:55 UTC, Jonathan M Davis wrote: What you will probably need to do is to not try and use the same type as both shared and non-shared if it has a destructor. Unfortunately this option would require an unrealistic lot of refactoring for me. I'm basically using

shared and nonshared dtor

2014-07-19 Thread Vlad Levenfeld via Digitalmars-d-learn
I have a Resource struct that is supposed to free some memory when it gets destroyed. Unfortunately, I can't define a destructor. If I do, the compiler complains that it can't destroy the shared versions. If I define a shared destructor, the compiler complains that it can't disambiguate

Re: dependency graph

2014-07-07 Thread Vlad Levenfeld via Digitalmars-d-learn
Thanks! Between the -deps flag and duml I think this is exactly what I need.

Re: break on assertion in GDB?

2014-07-05 Thread Vlad Levenfeld via Digitalmars-d-learn
The reason it worked one time and not the other was because the other time was an exception, not an assertion. How do I break on exceptions? (ps. is there a guide anywhere to using GDB with D?)

Re: Trouble initializing a templated class

2014-07-05 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 5 July 2014 at 16:47:32 UTC, quakkels wrote: I'm going through Adam Wilson's talk 'C# to D' and I've gotten hung up by one of his examples regarding generic programming in D. Specifically, I'm trying to implement the code example found here: http://youtu.be/6_xdfSVRrKo?t=16m44s.

Re: Trouble initializing a templated class

2014-07-05 Thread Vlad Levenfeld via Digitalmars-d-learn
On Saturday, 5 July 2014 at 17:17:03 UTC, quakkels wrote: try SomeClass (T): BaseClass Not sure which line you want me to change. I don't want SomeClass to inherit from BaseClass. Rather, I want T to be restricted to classes that inherit from BaseClass. When I change `class SomeClass(T :

overloading InExpression

2014-07-02 Thread Vlad Levenfeld via Digitalmars-d-learn
Is this possible? The documentation for std.container lists in as an operator in the container API but only associative arrays actually seem to support it.

Re: overloading InExpression

2014-07-02 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 2 July 2014 at 14:14:57 UTC, Dicebot wrote: struct S { int opIn_r(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); } Thanks! I wonder, why the _r and lack of documentation?

Re: overloading InExpression

2014-07-02 Thread Vlad Levenfeld via Digitalmars-d-learn
Ah yes I never noticed that in was in the binary op table. In my defense, searching for in usually yields too many results to be useful. Thanks to everyone for your help!

why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm trying to implement some wrappers atop preallocated arrays, so I'm calling reserve in the constructor, have an invariant to ensure that the array.ptr never moves, and use in-contracts to make sure any insertion and appends don't put me over the array capacity. I find that I'm able to

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
I was mistaken earlier, decrementing the length counter also sets the capacity to 0.

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
Thanks for your replies. The article was quite helpful in clarifying some questions I had. I decided to benchmark the different append methods (with [releaseMode, inline, noBoundsCheck, optimize]) by appending 10,000 elements to arrays with ~=, Appender, with and without first

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
How did you allocate your array? The GC has the APPENDABLE attribute special for memory blocks that are going to be used as slices: I allocated with new T[n]. I've tried allocating with both the APPENDABLE and NO_SCAN blocks but beyond a certain allocation size this doesn't work, I get a

break on assertion in GDB?

2014-06-30 Thread Vlad Levenfeld via Digitalmars-d-learn
Is this possible? I find myself having to set breakpoints up the callchain and step through every invocation till I find the one that breaks. This is a really bad way to work, but when I fail an assertion in GDB, it just reports program terminated.

Re: break on assertion in GDB?

2014-06-30 Thread Vlad Levenfeld via Digitalmars-d-learn
On Monday, 30 June 2014 at 12:08:31 UTC, Dicebot wrote: On Monday, 30 June 2014 at 11:56:27 UTC, Vlad Levenfeld wrote: Is this possible? I find myself having to set breakpoints up the callchain and step through every invocation till I find the one that breaks. This is a really bad way to work,

Re: break on assertion in GDB?

2014-06-30 Thread Vlad Levenfeld via Digitalmars-d-learn
I tried it again in a different context and it worked. Odd. Anyway, thanks for the information.

  1   2   >