Re: the best language I have ever met(?)

2016-11-25 Thread Artur Skawina via Digitalmars-d-learn
On 11/25/16 18:33, Jonathan M Davis via Digitalmars-d-learn wrote: > On Friday, November 25, 2016 18:20:11 Artur Skawina via Digitalmars-d-learn > wrote: >> On 11/25/16 17:30, Jonathan M Davis via Digitalmars-d-learn wrote: >>> On Friday, November 25, 2016 17:03:32 Artur Ska

Re: the best language I have ever met(?)

2016-11-25 Thread Artur Skawina via Digitalmars-d-learn
On 11/25/16 17:30, Jonathan M Davis via Digitalmars-d-learn wrote: > On Friday, November 25, 2016 17:03:32 Artur Skawina via Digitalmars-d-learn > wrote: >> On 11/25/16 15:51, Jonathan M Davis via Digitalmars-d-learn wrote: >>> On Friday, November 25, 2016 14:27:

Re: the best language I have ever met(?)

2016-11-25 Thread Artur Skawina via Digitalmars-d-learn
On 11/25/16 15:51, Jonathan M Davis via Digitalmars-d-learn wrote: > On Friday, November 25, 2016 14:27:39 Igor Shirkalin via Digitalmars-d-learn > wrote: >> I think you may write it (I mean actual D) with using some >> template like this: >> >> auto array = static_array!uint(1, 2, 3, 4) >> >> Cou

Re: a lambda with arguments has type void?

2016-06-09 Thread Artur Skawina via Digitalmars-d-learn
On 06/09/16 07:20, cy via Digitalmars-d-learn wrote: > Like this is why it doesn't really make sense: > > import std.stdio; > > auto foo(Callable)(Callable c) { > return c(42); > } > > auto foo2(alias c)() { > return c(42); > } > > void main() { > // this works, when you know it's an int

Re: Issue Turning Template into Variadic Template

2016-03-31 Thread Artur Skawina via Digitalmars-d-learn
On 03/30/16 20:12, jmh530 via Digitalmars-d-learn wrote: > I wrote a version of cartesianProduct that will return the cartesian product > when the some of the types are not ranges. The original code is below. > > My issue is that I can't figure out how to turn it into a variadic template. > auto

Re: static if else behavior and is type comparison

2016-03-11 Thread Artur Skawina via Digitalmars-d-learn
On 03/11/16 09:21, Ali Çehreli via Digitalmars-d-learn wrote: > You've been bitten by a common usability issue. :) > > On 03/11/2016 12:02 AM, Fynn Schröder wrote: >> static if (is(U == ubyte)) { >> } else if (is(U == ushort)) { > > You mean 'else static if'. (Not your fault: I (and ot

Re: Decoding Pattern to a Tuple

2016-02-22 Thread Artur Skawina via Digitalmars-d-learn
On 02/19/16 19:10, Nordlöw via Digitalmars-d-learn wrote: > Have anybody put together a generalised form of findSplit that can split and > decode using a compile time parameters somewhat like > > "(1)-(2.0)".decode!("(", int, ")", char, "(", double, ")") > > evaluates to > > to a > > tuple!(in

Re: print function

2016-02-05 Thread Artur Skawina via Digitalmars-d-learn
On 02/05/16 14:38, Ola Fosheim Grøstad via Digitalmars-d-learn wrote: > On Friday, 5 February 2016 at 12:35:14 UTC, Artur Skawina wrote: >> call used to print diagnostics. What I saw made me never use or look at D's >> std lib again. Except for meta programing and toy/examp

Re: print function

2016-02-05 Thread Artur Skawina via Digitalmars-d-learn
On 02/05/16 08:04, cy via Digitalmars-d-learn wrote: > On Thursday, 4 February 2016 at 15:32:48 UTC, Artur Skawina wrote: >>void print(A...)(A a) { >> foreach (N, ref e; a) >> write(e, N==A.length-1?"\n":" "); >>} > &

Re: print function

2016-02-04 Thread Artur Skawina via Digitalmars-d-learn
On 02/04/16 18:53, ixid via Digitalmars-d-learn wrote: > On Thursday, 4 February 2016 at 17:34:33 UTC, Artur Skawina wrote: >> On 02/04/16 16:32, Artur Skawina wrote: >> but that seems too expensive, when the use is just in toy programs and >> debugging. > > I h

Re: print function

2016-02-04 Thread Artur Skawina via Digitalmars-d-learn
On 02/04/16 16:32, Artur Skawina wrote: > >void print(A...)(A a) { > foreach (N, ref e; a) > write(e, N==A.length-1?"\n":" "); >} BTW, that was *deliberately* written that way as a compromise between efficiency and template bloat. It

Re: print function

2016-02-04 Thread Artur Skawina via Digitalmars-d-learn
On 02/04/16 15:02, ixid via Digitalmars-d-learn wrote: > On Thursday, 4 February 2016 at 13:46:46 UTC, Dejan Lekic wrote: >> On Thursday, 4 February 2016 at 00:23:07 UTC, ixid wrote: >>> It would be nice to have a simple writeln that adds spaces automatically >>> like Python's 'print' in std.stdio

Re: how do I tell if something is lvalue?

2016-02-01 Thread Artur Skawina via Digitalmars-d-learn
On 02/01/16 21:42, Artur Skawina wrote: > On 02/01/16 20:47, Meta via Digitalmars-d-learn wrote: >> That looks much nicer. It still needs work to properly handle functions with >> non-empty argument lists. > > Then it gets a bit long for a one-liner ;) > >enum

Re: how do I tell if something is lvalue?

2016-02-01 Thread Artur Skawina via Digitalmars-d-learn
On 02/01/16 20:47, Meta via Digitalmars-d-learn wrote: > On Monday, 1 February 2016 at 18:28:05 UTC, Artur Skawina wrote: >> On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: >>> Thanks! I was surprised this is not straightforward. >> >>enum

Re: how do I tell if something is lvalue?

2016-02-01 Thread Artur Skawina via Digitalmars-d-learn
On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: > Thanks! I was surprised this is not straightforward. enum isLvalue(alias A) = is(typeof((ref _){}(A))); artur

Re: Forward declaration issue

2015-12-04 Thread Artur Skawina via Digitalmars-d-learn
On 12/04/15 09:12, Andre via Digitalmars-d-learn wrote: > Hi, > > I have a strange issue with following coding. > > void baz(); // forward declaration > > void foo() > { > void bar() > { > baz(); // (1) without f.d. syntax error > } > > void baz() > { > b

Re: Binding to GSL library

2015-11-26 Thread Artur Skawina via Digitalmars-d-learn
On 11/25/15 17:11, Radek via Digitalmars-d-learn wrote: > Hi, I'm making a trying to bind a gsl library > http://www.gnu.org/software/gsl/ so far it was working but when i started > binding complex numbers some functions won't work, like trigonometric > functions - called they return null. > >

Re: Check template parameter whether it has "length"

2015-10-08 Thread Artur Skawina via Digitalmars-d-learn
On 10/08/15 11:29, tcak via Digitalmars-d-learn wrote: > I am "trying" to write a function that takes an array of items, and returns > the length of longest item. > > [code] > size_t maxLength(A)( const A[] listOfString ) if( __traits( hasMember, A, > "length" ) ) > { > return 0; // not impl

Re: Get template parameter value

2015-09-29 Thread Artur Skawina via Digitalmars-d-learn
On 09/29/15 12:13, rumbu via Digitalmars-d-learn wrote: > On Tuesday, 29 September 2015 at 09:53:39 UTC, Kagamin wrote: >> On Tuesday, 29 September 2015 at 09:11:15 UTC, John Colvin wrote: >>> Welcome to the weird and wonderful work of >>> http://dlang.org/expression.html#IsExpression >> >> No, u

Re: What is the corect behavour for lazy in foreach variadic template

2015-09-25 Thread Artur Skawina via Digitalmars-d-learn
On 09/25/15 17:47, Ali Çehreli via Digitalmars-d-learn wrote: > Perhaps we need an enhancement that either works in your original code [...] His original code does work (`foreach` evaluates `args[N]` and assigns the result to `arg`). If he wanted to delay the evaluation, he would have written it

Re: Why is the constructor of B called?

2015-09-24 Thread Artur Skawina via Digitalmars-d-learn
On 09/24/15 13:26, Marc Schütz via Digitalmars-d-learn wrote: > On Thursday, 24 September 2015 at 01:01:09 UTC, Nicholas Wilson wrote: >> On Wednesday, 23 September 2015 at 21:25:15 UTC, tcak wrote: >>> On Wednesday, 23 September 2015 at 21:14:17 UTC, Adam D. Ruppe wrote: On Wednesday, 23 Sept

Re: __traits(allMembers) and aliases

2015-08-26 Thread Artur Skawina via Digitalmars-d-learn
On 08/26/15 14:42, Mike Parker via Digitalmars-d-learn wrote: > This doesn't help me distinguish aliased function names. [...] > I don't want to put any restrictions on what the user can have in the > module/class/struct that contains the function pointer. It's just that > aliased function name

Re: Problem with casting instance reference to void* and back.

2015-07-27 Thread Artur Skawina via Digitalmars-d-learn
On 07/27/15 14:03, Vlad Leberstein via Digitalmars-d-learn wrote: > Hi! My use case requires interaction with C API which in turn implies storing > object instance reference as void *. I'm using gdc 4.9.2 and everything > worked fine with "object -> void * -> object" conversion, but "object -> vo

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

2015-07-04 Thread Artur Skawina via Digitalmars-d-learn
On 07/03/15 12:52, Laeeth Isharc via Digitalmars-d-learn wrote: > I have an array of structs eg > > struct PriceBar > { > DateTime date; > double open; > double high; > double low; > double close; > } > > (which fields are present in this particular struct will depend on template > arg

Re: Call-ie return on behalf of caller?

2015-06-04 Thread Artur Skawina via Digitalmars-d-learn
On 06/04/15 00:37, Tofu Ninja via Digitalmars-d-learn wrote: > Is there a way other than exceptions for a called function to force the > caller to return? > > Specifically, I know the return type of the caller(its always bool) and under > certain circumstances I would like the caller to just giv

Re: Destructured Tuple Assignment

2015-05-15 Thread Artur Skawina via Digitalmars-d-learn
import std.algorithm; template magicassign(A...) { void magicassign(B)(B b) @property { foreach(I, ref a; A) static if (!is(typeof(A[I]):typeof(null))) a = b[I]; } } template let(string D) { mixin({ enum sdsl = D.findSplit

Re: Multiple template alias parameters

2015-05-09 Thread Artur Skawina via Digitalmars-d-learn
On 05/08/15 23:56, Brian Schott via Digitalmars-d-learn wrote: > On Friday, 8 May 2015 at 12:44:31 UTC, Artur Skawina wrote: >> On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: >>> The problem occurs when I want to register multiple modules to scan for >>

Re: Multiple template alias parameters

2015-05-08 Thread Artur Skawina via Digitalmars-d-learn
On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: > The problem occurs when I want to register multiple modules to scan for > functions. The grammar does not allow this syntax: > > ``` > template (alias Modules ...) { > ... > ``` The grammar allows omitting the 'alias' keyword. art

Re: Reducing source code: weak+alias values in array

2015-05-02 Thread Artur Skawina via Digitalmars-d-learn
On 05/02/15 05:28, Jens Bauer via Digitalmars-d-learn wrote: > On Saturday, 2 May 2015 at 03:21:38 UTC, Jens Bauer wrote: >> For some reason, my build time has increased dramatically... >> >> Building with 1 vector takes 0.6 seconds. >> Building with 2 vector takes 0.7 seconds. >> Building with 4 v

Re: Reducing source code: weak+alias values in array

2015-05-01 Thread Artur Skawina via Digitalmars-d-learn
On 05/01/15 22:29, Jens Bauer via Digitalmars-d-learn wrote: > On Wednesday, 29 April 2015 at 13:58:14 UTC, Artur Skawina wrote: >> On 04/27/15 19:49, Jens Bauer via Digitalmars-d-learn wrote: >>> I was wondering if there's a way to reduce my bulky startup files a bit. >

Re: Reducing source code: weak+alias values in array

2015-04-29 Thread Artur Skawina via Digitalmars-d-learn
On 04/27/15 19:49, Jens Bauer via Digitalmars-d-learn wrote: > I was wondering if there's a way to reduce my bulky startup files a bit. > > If using the GNU Assembler (GAS), then one can reduce the code using a macro > like this: > > > /* The EXC macro makes a weak+alias for the > * symbol 'va

Re: Make a type tuple from an array

2015-04-11 Thread Artur Skawina via Digitalmars-d-learn
On 04/10/15 17:36, John Colvin via Digitalmars-d-learn wrote: > On Friday, 10 April 2015 at 15:13:54 UTC, Marc Schütz wrote: >> Is there a way to turn an array (known at compile time) into a TypeTuple? > For input ranges in general: > > import std.range : isInputRange; > > template TypeTupleOf(

Re: Creating a microcontroller startup file

2015-04-09 Thread Artur Skawina via Digitalmars-d-learn
On 04/08/15 18:10, Jens Bauer via Digitalmars-d-learn wrote: > On Wednesday, 8 April 2015 at 11:17:12 UTC, Mike wrote: >> On Tuesday, 7 April 2015 at 20:33:26 UTC, Jens Bauer wrote: >> >> enum weak = gcc.attribute.attribute("weak"); >> enum isrDefault = gcc.attribute.attribute("alias", "defaultHand

Re: enum and static if

2015-03-11 Thread Artur Skawina via Digitalmars-d-learn
On 03/11/15 15:41, ketmar via Digitalmars-d-learn wrote: > On Wed, 11 Mar 2015 14:36:07 +, wobbles wrote: > >> On Wednesday, 11 March 2015 at 14:34:32 UTC, ketmar wrote: >>> On Wed, 11 Mar 2015 13:48:45 +, Namespace wrote: >>> This code does not work: enum Test { >

Re: Initializing defaults based on type.

2015-03-06 Thread Artur Skawina via Digitalmars-d-learn
On 03/06/15 22:29, Artur Skawina wrote: > No, you implement it using CTFE magic, and then that code becomes: >#foreach (N; 0..PairInitValues.length/2) { > enum PairInitValue(T:PairInitValues[$N*2]) = PairInitValues[$N*2+1]; >} > Seriously though, avoid using `

Re: Initializing defaults based on type.

2015-03-06 Thread Artur Skawina via Digitalmars-d-learn
On 03/06/15 19:27, Kagamin via Digitalmars-d-learn wrote: > On Friday, 6 March 2015 at 16:39:56 UTC, Ali Çehreli wrote: >> mixin (makePairInitValueDefinitions()); > > Oh, so that's how you do static foreach. No, you implement it using CTFE magic, and then that code becomes: import std.typetup

Re: Labels in struct

2015-01-31 Thread Artur Skawina via Digitalmars-d-learn
On 01/31/15 17:04, tcak via Digitalmars-d-learn wrote: > > struct CommunicationMessage{ [...] > content: > } > > > Example I defined something like above. I am using it as a base structure, > and don't know how long the content of message will be. But I know that it > will be at the end. I cou

Re: How to copy object of class A to another object of class B?

2015-01-28 Thread Artur Skawina via Digitalmars-d-learn
On 01/28/15 10:44, zhmt via Digitalmars-d-learn wrote: > I have a struct created by thrift: > > struct Card { > long id; > string pwd; > long agentId; > bool valid; > long rmb; > long createDate; > long soldDate; > long chargeDate; > > mixin TStructHelpers!([ > TFieldMeta(`i

Re: static class vs. static struct

2015-01-27 Thread Artur Skawina via Digitalmars-d-learn
On 01/27/15 10:40, Daniel Kozak via Digitalmars-d-learn wrote: > On Tuesday, 27 January 2015 at 09:36:49 UTC, Daniel Kozak wrote: >> On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: >>> For several times I've met struct(or static struct) usage in Phobos for >>> singleton pattern impleme

Re: reinterpret array

2015-01-13 Thread Artur Skawina via Digitalmars-d-learn
On 01/13/15 21:52, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: > On Tuesday, 13 January 2015 at 20:11:45 UTC, anonymous wrote: >> On Tuesday, 13 January 2015 at 20:00:57 UTC, Dominikus Dittes Scherkl wrote: >>> So if I have a function that allowes to do this: >>> >>> uint a; >>> a.bit[1

Re: Copy only frame pointer between objects of nested struct

2015-01-06 Thread Artur Skawina via Digitalmars-d-learn
On 01/06/15 23:14, Peter Alexander via Digitalmars-d-learn wrote: > auto foo(T)(T a) { > T b; // Error: cannot access frame pointer of main.X > b.data[] = 1; > return b; > } > > void main() { > struct X { > this(int) {} > int[4096] data; > } > foo(X());

Re: `shared Mutex`?

2014-12-28 Thread Artur Skawina via Digitalmars-d-learn
On 12/28/14 10:24, Aiden via Digitalmars-d-learn wrote: > Is `shared` in a workable state? No. > Shouldn't Mutex, Condition, etc be shared since they are basically only ever > useful when used in multiple threads? Yes, but there are so many problems with 'shared' that using it that way (even on

Re: transversal sum

2014-11-06 Thread Artur Skawina via Digitalmars-d-learn
On 11/06/14 18:32, bearophile via Digitalmars-d-learn wrote: > Marc Schütz: > >> We'd need something taking and returning a RoR that "mirrors" them >> diagonally. Then we could simply apply `map!(r => r.sum)` on the result. > > A simple solution is to create a row of values, and then sum them co

Re: Error with constraints on a templated fuction

2014-08-25 Thread Artur Skawina via Digitalmars-d-learn
On 08/25/14 18:52, Jonathan M Davis via Digitalmars-d-learn wrote: > Another commonly used one is is(typeof(foo)). typeof(foo) gets the type of foo > and will result in void if foo doesn't exist, and is(void) is false, whereas D is not quite that simple. ;) static assert(is(void)==true); (a)

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

2014-08-16 Thread Artur Skawina via Digitalmars-d-learn
On 08/16/14 13:58, Philippe Sigaud via Digitalmars-d-learn wrote: > On Sat, Aug 16, 2014 at 1:30 PM, Artur Skawina via Digitalmars-d-learn >> http://forum.dlang.org/post/mailman.125.1397731134.2763.digitalmar...@puremagic.com > > Okay... > > So @safe includes child scope

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

2014-08-16 Thread Artur Skawina via Digitalmars-d-learn
On 08/16/14 13:18, Philippe Sigaud via Digitalmars-d-learn wrote: > We indeed need to put annotations inside aggregates to > affect their innards. > > If that's true, I have a lot of annotation sprinkling to do. It's not true for @safe, but true for some other attributes. http://forum.dlang.org/

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

2014-08-09 Thread Artur Skawina via Digitalmars-d-learn
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-style (without > swizzling... for now). > > Here's the relevant code: > > struct Ve

Re: Inner struct accessing host member

2014-08-05 Thread Artur Skawina via Digitalmars-d-learn
On 08/05/14 22:32, Philippe Sigaud via Digitalmars-d-learn wrote: > I'd have thought that this would work: > > struct A > { > int[] i; > B b; > > struct B > { > void foo() { i ~= 1;} > } > } > > void main() > { > A a; > a.b.foo(); > } > > But the compiler tel

Re: auto ref function parameters in a free function

2014-08-03 Thread Artur Skawina via Digitalmars-d-learn
On 08/03/14 23:19, Vlad Levenfeld via Digitalmars-d-learn wrote: > > I made less_than to serve as a default sorting predicate, so in a few places > there is something like this: > > void sort (R, T = ElementType!R, alias compare = less_than!T)(R range, T item) > {...} void sort (R, T = Element

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

2014-07-29 Thread Artur Skawina via Digitalmars-d-learn
On 07/29/14 17:45, H. S. Teoh via Digitalmars-d-learn wrote: > You're right, opDispatch behaves like SFINAE. I've had trouble debugging > it before, because when it works, it works very well, but when you > accidentally make a typo, it just "disappears" -- you get an error that > the property is mi

Re: Compile time regex matching

2014-07-14 Thread Artur Skawina via Digitalmars-d-learn
On 07/14/14 13:42, Philippe Sigaud via Digitalmars-d-learn wrote: > asserts get an entire copy of the parse tree. It's a bit wasteful, but > using 'immutable' directly does not work here, but this is OK: > > enum res = MyRegex("abcabcdefFOOBAR"); // compile-time parsing > immutable result

Re: template mixins for boilerplate

2014-06-21 Thread Artur Skawina via Digitalmars-d-learn
On 06/21/14 18:01, Philippe Sigaud via Digitalmars-d-learn wrote: > In what way is a template more reliable than the equivalent function? > mixin template Function(string name) { > mixin("public static int " ~ name ~ "() { return other.module." ~ > name ~"; }"); > } > > struct S { > mix

Re: template mixins for boilerplate

2014-06-21 Thread Artur Skawina via Digitalmars-d-learn
On 06/21/14 05:32, Paul D Anderson via Digitalmars-d-learn wrote: > I can't use a template mixin: > > mixin template Function(string name) > { > const char[] Function = > "public static int " ~ name ~ "() { return other.module." ~ name ~"; }"; > } > > Error: mixin templates are not regular

Re: C structs

2014-06-21 Thread Artur Skawina via Digitalmars-d-learn
On 06/20/14 14:42, Dicebot via Digitalmars-d-learn wrote: > On Friday, 20 June 2014 at 12:17:22 UTC, Johann Lermer wrote: >> So, why is there no init routine for the rectangle? There's only one for the >> matrix. > > That needs actually building deimos cairo and checking symbols in object > file

Re: C++'s "defaulted comparison operators" proposal

2014-06-18 Thread Artur Skawina via Digitalmars-d-learn
On 06/18/14 07:49, Ali Çehreli via Digitalmars-d-learn wrote: > The idea is to be able to have standard comparison behavior for structs > without boilerplate. For example, if the ordering should consider all members > of the following struct one after the other (first 'i', then 'l', and finally

Re: Splitting Ranges using Lambda Predicates

2014-06-11 Thread Artur Skawina via Digitalmars-d-learn
On 06/11/14 16:05, monarch_dodra via Digitalmars-d-learn wrote: > Well, (IMO) it's a problem with no real solution. But for what it's worth, > most (if not all) of the algorithms in the standard lib know how to handle > strings efficiently and correctly (split, find, etc...). Things only start >

Re: Splitting Ranges using Lambda Predicates

2014-06-11 Thread Artur Skawina via Digitalmars-d-learn
On 06/11/14 15:44, Artur Skawina wrote: > If, instead, you create a string-specific 'countUntil' that returns > a type that holds both the byte and code-point counts and implicitly > converts to the latter, then you can have a 'takeExactly' overload > that

Re: Splitting Ranges using Lambda Predicates

2014-06-11 Thread Artur Skawina via Digitalmars-d-learn
On 06/11/14 14:40, monarch_dodra via Digitalmars-d-learn wrote: > For example, you should avoid "countUntil" and "takeExactly" when dealing > with strings, since these are not O(1) operations, and don't actually return > string slices. EG: > string s = "someGGGreatVariableName".slicer().front; >

Re: Splitting Ranges using Lambda Predicates

2014-06-11 Thread Artur Skawina via Digitalmars-d-learn
On 06/11/14 00:31, "Nordlöw" via Digitalmars-d-learn wrote: >> Either way, it shouldn't be too hard to implement. Base it off >> "splitter!pred", which is actually quite trivial. AFAIK, your > > What do you mean by basing it off splitter!pred - should I start with some > existing splitter algori

Re: enum template shorthand and short circuit evaluation

2014-06-10 Thread Artur Skawina via Digitalmars-d-learn
On 06/10/14 02:28, Byron via Digitalmars-d-learn wrote: > Should this work? It seems like the short circuit booleans are not > working: > > enum isPrimitive(T) = isBasicType!T || (isArray!T && isBasicType! > (ForeachType!T)); [...] > But this style works: > > template isPrimitive(T) > { >

Re: alias with lambda syntax: alias fun2=a=>fun(a);

2014-06-05 Thread Artur Skawina via Digitalmars-d-learn
> On 06/05/14 08:58, Timothee Cour via Digitalmars-d-learn wrote: >> //none of those work: >> //alias fun2=a=>fun(a); alias fun2=ALIAS!(a=>fun(a)); That 'ALIAS' template will need to be in module scope. alias ALIAS(alias A) = A; artur

Re: alias with lambda syntax: alias fun2=a=>fun(a);

2014-06-05 Thread Artur Skawina via Digitalmars-d-learn
On 06/05/14 08:58, Timothee Cour via Digitalmars-d-learn wrote: > Is there a way to do this? > > auto fun(T)(T a){return a;} > > template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and > cannot be nested inside test() alias fun2(T) = fun!T; But this will prevent IFTI, so

Re: [Rosettacode] Growable slices

2014-05-16 Thread Artur Skawina via Digitalmars-d-learn
On 05/16/14 17:20, bearophile via Digitalmars-d-learn wrote: > Artur Skawina: > >> Ugh. So how does it perform wrt the D version that I wrote for >> you last time? [1] > > I have done a benchmark with the various version (the first 3 are the ones on > the Rosettacod

Re: [Rosettacode] Growable slices

2014-05-16 Thread Artur Skawina via Digitalmars-d-learn
On 05/16/14 11:47, bearophile via Digitalmars-d-learn wrote: >> There are of course ways to implement a really efficient ZLW compressor in >> D, and such implementation could be added as third D entry if it manages to >> be not too much long, > > Third version added: > http://rosettacode.org/wik

Re: Temporary silence output (stdout)

2014-05-10 Thread Artur Skawina via Digitalmars-d-learn
On 05/10/14 22:24, MarisaLovesUsAll via Digitalmars-d-learn wrote: > I sometimes got a useless messages in stdout from SDL_Image > library, and I want to temporary silence it. How do I do? One way would be something like: import std.stdio; void writeOutput () { static c = 1; pr

Re: Need help with movement from C to D

2014-05-06 Thread Artur Skawina via Digitalmars-d-learn
On 05/06/14 16:45, via Digitalmars-d-learn wrote: > On Tuesday, 6 May 2014 at 14:25:01 UTC, Artur Skawina via Digitalmars-d-learn > wrote: >> I'm not sure why you'd want to wrap the .offsetof expression in >> a template, but it can easily be done like this: >> &

Re: Need help with movement from C to D

2014-05-06 Thread Artur Skawina via Digitalmars-d-learn
I'm not sure why you'd want to wrap the .offsetof expression in a template, but it can easily be done like this: enum offsetOf(alias A, string S) = mixin("A."~S~".offsetof"); Keep in mind that D's offsetof is flawed - if the object does not contain the requested member, but implicitly convert

Re: Postblit not invokable with MyStruct(MyStruct()); ?

2014-05-03 Thread Artur Skawina via Digitalmars-d-learn
On 05/03/14 01:05, Mark Isaacson via Digitalmars-d-learn wrote: > 2) I ran into this issue while attempting to leverage the postblit for > code-reuse. In particular, I have a setup that is similar to: > > struct A { > this(B b) { /* Stuff */ } > } > > struct B { > } > > void foo(T)(T param) {

Re: Making enum join variadic

2014-05-02 Thread Artur Skawina via Digitalmars-d-learn
On 05/02/14 17:27, Meta via Digitalmars-d-learn wrote: > On Friday, 2 May 2014 at 15:18:06 UTC, Artur Skawina via Digitalmars-d-learn > wrote: >> On 05/02/14 15:38, "Nordlöw" via Digitalmars-d-learn wrote: >>> >>> template MemberNamesUnion(E...) if (al

Re: Making enum join variadic

2014-05-02 Thread Artur Skawina via Digitalmars-d-learn
On 05/02/14 15:38, "Nordlöw" via Digitalmars-d-learn wrote: > > template MemberNamesUnion(E...) if (allSatisfy!(isEnum, E)) > { > bool[string] allMembers; // used to detect member collisions > mixin({ > string r = "enum MemberNamesUnion { "; > foreach (T; E) { >

Re: Making enum join variadic

2014-05-01 Thread Artur Skawina via Digitalmars-d-learn
On 05/02/14 00:24, "Nordlöw" via Digitalmars-d-learn wrote: > How can I make `join` variadic (by filling in njoin) in the following code? import std.array, std.range, std.algorithm; import std.stdio; template Njoin(ES...) { mixin({ string r = "enum Njoin { "; fore

Re: import with renaming and public import inside module

2014-04-29 Thread Artur Skawina via Digitalmars-d-learn
On 04/29/14 11:57, ketmar via Digitalmars-d-learn 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. It certainly works here; if it didn't it would be a frontend problem. >> I don't think so. The point of the re

Re: Extern Keyword for Function Type

2014-04-15 Thread Artur Skawina
On 04/15/14 22:15, Jeroen Bollen wrote: > exten(C) { > testFunction(int function(int)); > } > > testFunction now requires an external function as parameter. It can't be > called with a pointer to a D function. > > Logical Solution: > > extern(C) { > testFunction(extern(D) int function(i

Re: Iterate over symbols in tupleof without instance

2014-04-15 Thread Artur Skawina
On 04/15/14 13:33, Dicebot wrote: > On Tuesday, 15 April 2014 at 11:25:14 UTC, Artur Skawina wrote: >>void iterate(T)() >>{ >>foreach (index, member; typeof(T.tupleof)) >>{ >>pragma(msg, __traits(identifier, T.tupleof[inde

Re: Converting function pointers to delegates

2014-04-15 Thread Artur Skawina
On 04/15/14 13:30, Andrej Mitrovic wrote: > On 4/15/14, Artur Skawina wrote: >> It *is* true. Classes are /reference types/, not references to classes. > > I meant the part where he said you can't cast a reference to a pointer. You > can. He obviously meant that you can

Re: Converting function pointers to delegates

2014-04-15 Thread Artur Skawina
On 04/14/14 19:51, Andrej Mitrovic wrote: > On Monday, 14 April 2014 at 17:48:31 UTC, Adam D. Ruppe wrote: >> On Monday, 14 April 2014 at 17:45:52 UTC, Ryan Voots wrote: >>> src/yage/core/misc.d(164): Error: e2ir: cannot cast this of type S to type >>> void* >> >> >> Try taking the address of this

Re: Iterate over symbols in tupleof without instance

2014-04-15 Thread Artur Skawina
On 04/15/14 12:45, Dicebot wrote: > void iterate(T)() > { > foreach (index, member; T.init.tupleof) > { > pragma(msg, __traits(identifier, T.tupleof[index])); > } > } > > struct A > { > int a, b, c; > } > > void main() > { > iterate!A(); > } > > Reason why you can't n

Re: copying memory in phobos

2014-04-08 Thread Artur Skawina
On 04/08/14 14:35, Mike wrote: > On Tuesday, 8 April 2014 at 11:56:43 UTC, ketmar wrote: >>> I understand that. But why is dest[] = src[] not good enough for run-time? >> 'cause some compilers (gcc, for example) has memcpy() as 'intrinsic' and >> generates better inline code for it sometimes. it'

Re: Manually-allocated memory and maximum array capacity

2014-04-08 Thread Artur Skawina
On 04/07/14 22:58, Joseph Rushton Wakeling wrote: > On 05/04/14 02:18, Artur Skawina wrote: >> Not portably, as it will be libc and/or allocator specific. > > I think that's fine. I would be using it in circumstances where it's nice to > have if I can get it, not a

Re: They are not the same

2014-04-05 Thread Artur Skawina
On 04/05/14 21:51, Timon Gehr wrote: > On 04/05/2014 11:53 AM, bearophile wrote: >> John Colvin: >> >>> I think there's an argument that this should work, on the grounds that >>> the context pointer is just another argument and therefore the lambda >>> can be weakly pure. >> >> Was this discussed i

Re: Manually-allocated memory and maximum array capacity

2014-04-04 Thread Artur Skawina
On 04/05/14 00:54, Joseph Rushton Wakeling wrote: > Hello all, > > If we change the length of a dynamic array using the normal GC-based methods, > e.g. by setting the array's .length property, we find that the array's > capacity typically does not simply equal the length, but some greater value;

Re: Template magic exercise

2014-03-30 Thread Artur Skawina
On 03/30/14 15:36, Jack Applegame wrote: > Wraper structure again. Is there solution without it? No. D only allows op overloading in structs/unions/classes, so one of those will be necessary. The simpliest solution would be something like: class C { int elementsAccessor(size_t index) { .

Re: Wrapping C code?

2014-03-29 Thread Artur Skawina
On 03/29/14 20:01, CJS wrote: > I've been using a medium-sized C library. Most of the library calls look > something like > > action(context, arg1, arg2) > > Where is the name of the library, action is the action to take, and > context is an opaque pointer defined by the library to kee

Re: Choice ranges?

2014-03-29 Thread Artur Skawina
On 03/29/14 18:30, Timon Gehr wrote: > > I'm stuck with 2.060 myself, but there's always http://dpaste.dzfl.pl/. For the examples, I used a gdc that claims __VERSION__==2062L. (for /real/ code I'm still using a 2.057 based one...) artur

Re: Choice ranges?

2014-03-29 Thread Artur Skawina
On 03/29/14 16:31, Timon Gehr wrote: > On 03/29/2014 01:37 AM, Artur Skawina wrote: >> You can wrap the range in a common one. When the above approach isn't >> enough, there's always the next level: > > (Note that your code does not actually compile.) Of course i

Re: Choice ranges?

2014-03-28 Thread Artur Skawina
On 03/28/14 23:10, H. S. Teoh wrote: > On Fri, Mar 28, 2014 at 10:44:11PM +0100, Artur Skawina wrote: >> On 03/28/14 20:00, H. S. Teoh wrote: >>> Today I ran into an interesting situation where I have a function f >>> that needs to return ranges of different types (but

Re: Choice ranges?

2014-03-28 Thread Artur Skawina
On 03/28/14 20:00, H. S. Teoh wrote: > Today I ran into an interesting situation where I have a function f that > needs to return ranges of different types (but identical element types): > > auto f(A...)(A args) { > ... > if (someCondition) >

Re: Bug with references (no casting used)

2014-02-22 Thread Artur Skawina
On 02/22/14 18:22, andrea9940 wrote: > I was trying to get my vector struct to use extensively references for > passing parameters and I found a subtle bug which make me lose a few hour. > > A sample code that shows the bug is here http://pastebin.com/rvcNdjAE (fails > with dmd 2.064 on linux) >

Re: Is there kind of "associative tuple" - like syntax in D?

2014-02-22 Thread Artur Skawina
On 02/21/14 18:57, Uranuz wrote: > In my template functions, classes it's necessary to write variadic template > parameter list, where elements are options to this class/function changing > it's behaviour. But they are optional and may be not set at all. These > options may be folowed by variad

Re: Generating an enum from a tuple of Types?

2014-01-25 Thread Artur Skawina
On 01/25/14 16:38, Johannes Pfau wrote: > Is it possible to generate a enum from a tuple of types without string > mixins? > > struct S(Types...) > { > enum Tag > { > //? > } > } > > > where the tag enum should have Types.length members. The exact name

Re: Is it possible to handle 'magic' property assignments a'la PHP?

2014-01-05 Thread Artur Skawina
On 01/05/14 15:36, TheFlyingFiddle wrote: > Another simple example that have helped me tremendously when debugging OpenGL > calls. A simple dispatcher that checks glGetError after every call. > > struct GL > { > auto opDispatch(string name, Args...)(Args args) > { > enum glName =

Re: inotify and recursion

2013-12-27 Thread Artur Skawina
On 12/27/13 15:13, Artur Skawina wrote: >struct MyInotifyEvent(size_t BS) { > inotify_event event; > char[BS] buffer; > alias event this; >} >[...] >enum bufsiz = inotify_event.sizeof + PATH_MAX + 1; >auto event = cast(MyInotifyEve

Re: inotify and recursion

2013-12-27 Thread Artur Skawina
On 12/27/13 14:28, David Eagen wrote: > I had trouble getting the file name from the event. I think it's because the > inotify module has name defined as char[0]. So I did this, which prints the > name by using the extra data beyond the inotify_event struct itself: > > > void* buf = GC.mall

Re: inotify and recursion

2013-12-27 Thread Artur Skawina
On 12/27/13 04:23, David Eagen wrote: > void main() > { > string filename="aaa"; > > int inotfd = inotify_init(); > int watch_desc = inotify_add_watch(inotfd, toStringz(filename), > IN_MODIFY); > > size_t bufsiz = inotify_event.sizeof + PATH_MAX + 1; > inotify_event* event =

Re: My first D module - Critiques welcome.

2013-12-25 Thread Artur Skawina
On 12/25/13 15:07, Dejan Lekic wrote: >> You could also do some neat stuff with opDispatch. Someone >> actually >> wrote an article about using it with roman numerals: >> http://idorobots.org/2012/03/04/romans-rubies-and-the-d/ > > The idea is actually brilliant. :) > I think I may use it in the

Re: Dub and GtkD

2013-12-24 Thread Artur Skawina
On 12/23/13 19:30, Mike Wey wrote: > On 12/22/2013 10:00 PM, Artur Skawina wrote: >> On 12/22/13 20:21, Mike Wey wrote: >>> On 12/22/2013 03:36 PM, Russel Winder wrote: >>>> >>>> Python now uses the reflection approach to providing a Python binding to >

Re: Dub and GtkD

2013-12-22 Thread Artur Skawina
On 12/22/13 20:21, Mike Wey wrote: > On 12/22/2013 03:36 PM, Russel Winder wrote: >> >> Python now uses the reflection approach to providing a Python binding to >> the API: PyGTK has given way to PyGobject. Has the PyGobject approach >> been rejected for GtkD staying with the PyGtk approach? > > I

Re: Problem: Cannot create class out of nothing using witchcraft

2013-10-15 Thread Artur Skawina
On 10/15/13 10:03, DoctorCaptain wrote: > If what I am asking is unclear, I will be more than happy to > explain in a different way. I tried to be simultaneously as > succinct and as comprehensive as possible with what the issue is. I'm not sure what exactly you're trying to do, but... The issue

Re: Call a function with a function pointer

2013-10-13 Thread Artur Skawina
On 10/13/13 16:43, Benjamin Thaut wrote: > Am 10.10.2013 17:45, schrieb Namespace: >> On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: >>> Namespace: >>> You mean like this? void foo(T)(extern(C) void function(T*) func) { } That print

Re: Traits

2013-10-13 Thread Artur Skawina
On 10/13/13 02:25, luminousone wrote: > On Saturday, 12 October 2013 at 23:48:56 UTC, Artur Skawina wrote: >>template isBaseOf(BASE, C) { >> enum isBaseOf = { >> static if (is(C S == super)) >> foreach (A; S) >>

  1   2   3   >