Re: D casting broke?

2016-06-20 Thread ag0aep6g via Digitalmars-d-learn
On 06/20/2016 11:33 PM, Joerg Joergonson wrote: On Monday, 20 June 2016 at 10:38:12 UTC, ag0aep6g wrote: [...] Is your position that Button!SliderItem should derive/inherit from Button!ButtonItem, enabling the cast, or do you suppose the cast should succeed because the fields are compatible? I

Re: opDispatch and @property setters

2016-06-21 Thread ag0aep6g via Digitalmars-d-learn
On 06/21/2016 10:48 PM, Lodovico Giaretta wrote: struct Wrapper(T) { private T wrapped; template hasAssignableProperty(string name, Arg) { enum bool hasAssignableProperty = is(typeof( (ref T val, ref Arg arg) {

Re: executeShell doesn't work but system does

2016-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 06/26/2016 05:37 PM, Smoke Adams wrote: system("cls") works but executeShell doesn't. system is depreciated. Unsolicited spelling correction: no 'i' in "deprecated". What's going on? The docs say that it creates a new process. I simply want to clear the console! `system` directly prints

Re: What's the secret to static class members

2016-06-29 Thread ag0aep6g via Digitalmars-d-learn
On 06/29/2016 07:00 PM, Guido wrote: On another topic, tuples seem to have a major problem as well. Tuple!(float, float, float) test; Tuple!(float, float, float) [] array_data; test[0] = 1.0; // works array_data[i][0] = 1.0; // doesn't work. Works just fine for me, if I add the missing piece

Re: IFTI in Eponymous Templates

2016-06-29 Thread ag0aep6g via Digitalmars-d-learn
On 06/29/2016 08:59 PM, jmh530 wrote: For instance, in the bar function below, I have to explicitly instantiate the inner function template. [...] template bar(T) { T bar(U)(T x, U y) { return x + cast(T)y; } } void main() { int a = 1; long b = 2; auto

Re: EnumToFlags

2016-06-30 Thread ag0aep6g via Digitalmars-d-learn
On 06/30/2016 04:39 AM, JS wrote: struct EnumToFlags(alias E) { import std.traits, std.conv, std.string, std.algorithm, std.array; static if (E.max < 8) alias vtype = ubyte; Convention says: Capitalize user-defined type names. So it should be "Vtype" or maybe "VType" instea

Re: Range non-emptyness assertions and opIndex

2016-07-01 Thread ag0aep6g via Digitalmars-d-learn
On 07/01/2016 12:35 PM, Nordlöw wrote: What's the preferred way of reacting to emptyness in the members front, back, popFront, popBack --- using assert, enforce, throw, or simply relying on range-checking in the _store? I think assert is the most common way of checking. Simply ignoring the pos

Re: Way to use var instead of auto?

2016-07-03 Thread ag0aep6g via Digitalmars-d-learn
On 07/04/2016 12:00 AM, MMJones wrote: I like the term var better than auto. Is there a way to alias auto? no

Re: shared not working!

2016-07-03 Thread ag0aep6g via Digitalmars-d-learn
On 07/04/2016 01:20 AM, Hiemlick Hiemlicker wrote: I have thread. It locks up. If I changed from a bool val it is using from shared to __gshared it works. I checked the address inside and outside of the thread and they are different for shared and same for __gshared. [...] shared bool isPa

Re: shared not working!

2016-07-03 Thread ag0aep6g via Digitalmars-d-learn
On 07/04/2016 07:16 AM, Hiemlick Hiemlicker wrote: But static isn't per instance, is it? Sure isn't. __gshared isn't either. That means every thread created will have the same value of Paused. Calling Pause will pause all threads. That can't be right. I don't know what exactly you're doing

Re: Possible bug

2016-07-05 Thread ag0aep6g via Digitalmars-d-learn
On 07/05/2016 12:47 PM, Jack Applegame wrote: ttt.d import std.string; void main() { lastIndexOf("aa","bb"); } rdmd ttt.d compiles successfully without any errors or warnings rdmd -dw ttt.d compiles successfully without any errors or warnings rdmd -de ttt.d /usr/include/dmd/phobos/std

Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)'

2016-07-05 Thread ag0aep6g via Digitalmars-d-learn
On 07/05/2016 07:25 AM, ketmar wrote: cast `shared` away. yes, this is how you supposed to use it now: cast it away. after having ensured thread safety that is

Re: How to get current time as long or ulong?

2016-07-05 Thread ag0aep6g via Digitalmars-d-learn
On 07/05/2016 08:16 PM, Charles Hixson via Digitalmars-d-learn wrote: What I'm looking for is the opposite of the "FromUnixTime" function. That would be the "toUnixTime" method then, I suppose. https://dlang.org/phobos/std_datetime.html#.SysTime.toUnixTime

Re: local const functions - bug ?

2016-07-07 Thread ag0aep6g via Digitalmars-d-learn
On 07/07/2016 12:33 PM, Basile B. wrote: Do you think it's a bug ? Yes.

Re: Variadic Tuple of Structs with Mixed Types

2016-07-08 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2016 12:33 AM, jmh530 wrote: I'm trying to create a tuple of variadic length containing structs with mixed types. So for instance, given struct Foo(T, U) { T x; U y; } I want to create something like Tuple!(Foo!(type1, type2), Foo!(type1, type3), ..., Foo!(type1, typeN)) x;

Re: Accessing contents of associative arrays in an optimal way

2016-07-09 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2016 10:32 PM, phant0m wrote: As far as I know, AA implemented as a hashtable. So, will there be two searches performed (one search for each line)? records[3].value = 10; records[3].name = "name"; Yup. A good optimizer may be able to eliminate one, but conceptually there are two looku

Re: mutable string

2016-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2016 10:31 PM, Lodovico Giaretta wrote: That said, if you want char[] -> string or wchar[] -> wstring you can use assumeUnique, which casts a mutable array to an immutable one. After having ensured that the array is actually unique. That is, there must not be any other references to i

Re: mutable string

2016-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2016 11:17 PM, Adam Sansier wrote: The problem is things like https://msdn.microsoft.com/en-us/library/windows/desktop/ms724902(v=vs.85).aspx require data buffers to be used. I can't just plug in a wstring to it, can I? You can't. `First-chance exception: core.exception.UnicodeExc

Re: mutable string

2016-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2016 11:26 PM, Adam Sansier wrote: For example, I'm trying to compare a wchar buffer with a wstring using slices: x[0..$] == y[0..$] It fails. I think because x has length 1024. If do x[0..y.length] == str[0..y.length] it fails, also because y has length 1024(since it was generated f

Re: mutable string

2016-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2016 11:38 PM, Adam Sansier wrote: Using this code import core.stdc.wchar_; // For wcslen. Hint: D has special syntax for importing only specific parts of a module: import core.std.wchar_: wcslen; wstring toWstring(wchar[] value) { return value ? cast(wstring) value[0..wc

Re: How to create nogc code?

2016-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/11/2016 02:31 AM, Adam Sansier wrote: idup uses the gc, I am currently just malloc'ing the string and allowing for the memory leak. This is somewhat acceptable given that this code should rarely be called and generally only at startup. It will generally waste only a few KB of memory. If y

Re: How to use `format` to repeat a character

2016-07-11 Thread ag0aep6g via Digitalmars-d-learn
On 07/11/2016 11:31 AM, Ali Çehreli wrote: // Another one that combines multiple range algorithms import std.range : iota; import std.algorithm : map; assert(7.iota.map!(i => i % 2 ? '=' : '-').equal("-=-=-=-")); An alternative without those scary modulo and ternary operator

Re: protected + package attributes

2016-07-11 Thread ag0aep6g via Digitalmars-d-learn
On 07/11/2016 02:28 PM, zodd wrote: Suppose I have a class with a few protected functions. I want to let another class from the same package call these functions. Thus I've added a "package" attribute and got the following: Error: conflicting protection attribute 'package' and 'protected' How ca

Re: Debugging InvalidMemoryOperationError

2016-07-11 Thread ag0aep6g via Digitalmars-d-learn
On 07/11/2016 02:42 PM, Sam wrote: #0 0x00670a50 in onInvalidMemoryOperationError () #1 0x0068657b in gc.gc.GC.malloc() () #2 0x0067a4d2 in _d_newclass () #3 0x00670d53 in _d_assert () #4 0x0053d8e2 in std.typecons.__T10RefCountedTS4cram8wrappers54__T5

Re: @safe fun alayws call @system function?

2016-07-12 Thread ag0aep6g via Digitalmars-d-learn
On 07/12/2016 11:09 AM, Dsby wrote: How can i call @system function in a @safe function? You can't. You can mark the @safe function @trusted [1] instead. @trusted functions are considered memory-safe by the compiler and can be called from @safe code, but they can use @system features and call

Re: Docs for `Group` type

2016-07-12 Thread ag0aep6g via Digitalmars-d-learn
On 07/12/2016 01:40 PM, Bahman Movaqar wrote: Yes. I'm working on Stockman[1] a playground to learn D. In file `etl.d`, line 110 [2], if I change the line to auto refInvoice = group[1].takeOne(); the file will not compile. I have attached the compile error to this message. Do you also ad

[OT] Re: how to mark an extern function @nogc?

2016-07-12 Thread ag0aep6g via Digitalmars-d-learn
On 07/12/2016 04:04 PM, Seb wrote: D is entirely driven by highly motivated volunteers. (this will change soon with the new D foundation) Does the foundation have plans to hire programmers? That's news to me.

Re: Templates args

2016-07-14 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 14 July 2016 at 19:28:23 UTC, Andrey wrote: On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote: [...] struct Sigmoid(T) { [...] } struct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) { [...] pri

Re: Result Types and void usage

2016-07-15 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2016 10:11 AM, nik wrote: One thing I cant figure out/don't know if is possible is to have a type that takes "void" (see last unittest) [...] Result type: struct Result(T, E) { this(inout T result) inout { _result = result; _is_result = true; } t

Re: Bug? somearrayofclassinstances.filter(...).array fails because of .init() method in class

2016-07-15 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2016 12:54 PM, dom wrote: i just had a scenario like the one below. when calling .array on the filterresult dmd goes nuts because of the init() function in Players. Renaming to initialize() solved the problem. Solution: As .init is used for struct initialization and such (https://dlang.

Re: Interior immutability and rvalues

2016-07-15 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2016 10:29 AM, maik klein wrote: There are two things that bothered me for quite some time Interior immutability: Consider a something like this https://dpaste.dzfl.pl/fa5be84d26bc The implementation is totally wrong and it doesn't make sense, but it shows that Rc can not be const/im

Re: Interior immutability and rvalues

2016-07-15 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2016 02:51 PM, maik klein wrote: Thanks I didn't know that you could have type qualifiers inside templates, D still surprises me sometimes. Qualifiers are part of the type. So wherever you can have a type, you can have a qualified type. I don't think it is practical to call move on

Re: returning constant references from class methods

2016-07-19 Thread ag0aep6g via Digitalmars-d-learn
On 07/19/2016 02:30 PM, celavek wrote: Hi, I'm trying the following code: class counter { public: final ulong[char] nucleotide_counts () const { return cached_counts; } private: ulong[char] cached_counts; } void main() { } I get the following error from the comp

Re: Dynamic code generation

2016-07-19 Thread ag0aep6g via Digitalmars-d-learn
On 07/20/2016 06:36 AM, Rufus Smith wrote: Does D offer any solutions to generate code dynamically? I don't think so. I would like to order based on optimal strategies. This requires effectively hard coding the execution path. A simple example, if (x == true) foo(); else bar(); can

Re: shuffle a character array

2016-07-20 Thread ag0aep6g via Digitalmars-d-learn
On 07/20/2016 06:18 PM, Mike Parker wrote: The relevant lines I quoted from the docs above explain quite clearly that it's because they are multi-byte formats. Indexing them is not inefficient, it simply makes no sense. What does it mean to take the value at index i when it is part of a multi-byt

Re: Expression template

2016-07-23 Thread ag0aep6g via Digitalmars-d-learn
On 07/23/2016 01:05 PM, Etranger wrote: 1- Is there a cleaner way to do it ? I had to use struct because I want every thing to happen at compile time and on the stack (without gc). And I had to use string mixins because template mixin does not work the way I tried to use it ( see the error last l

Re: Trouble checking for null-ness

2016-07-25 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:37:18 UTC, Bahman Movaqar wrote: Error: incompatible types for ((r) !is (null)): 'MapResult!(__lambda2, SInvoiceLine[])' and 'typeof(null)' Of course if I remove `r !is null` from the `in` block, everything will work. But I'm curious; how can I check for a `n

Re: question about conditional operator (?:)

2016-07-26 Thread ag0aep6g via Digitalmars-d-learn
On 07/26/2016 03:09 PM, Richard wrote: if(n%p==0) n/=p; else p+=1; [...] However, if I replace the content of the for loop with the ?: operator, the program is not correct anymore (largestPrimeFactor(4) now returns 3): [...] n%p==0 ? n/=p : p+=1

Re: Search elemnt in Compile-time Argument List of strings

2016-07-27 Thread ag0aep6g via Digitalmars-d-learn
On 07/26/2016 09:30 PM, ParticlePeter wrote: So how can I achieve my goal the right way? Here's one with CTFE: void processMember(T, ignore...)() { import std.algorithm: canFind, filter; import std.meta: aliasSeqOf; enum selectedMembers = aliasSeqOf!( [__traits(allMem

Re: Broken TLS?

2016-07-27 Thread ag0aep6g via Digitalmars-d-learn
On 07/27/2016 09:19 PM, Dechcaudron wrote: struct Foo { [...] void ping() shared { [...] } void fire() { spawn(&explode); } void explode() shared { ping(); } } void main() { auto a = Foo(1, 2); a.fire(); thread_joinAll(); }

Re: Broken TLS?

2016-07-27 Thread ag0aep6g via Digitalmars-d-learn
On 07/28/2016 12:38 AM, Dechcaudron wrote: Giving my 20 votes to the issue (are votes even taken into account?). At least now I know the source of attribute-enforcements breakdown is basically delegate management. That should help me out enough so I don't have this issue anymore. Thanks a bunch.

Re: C's void func() vs. void func(void).

2016-07-29 Thread ag0aep6g via Digitalmars-d-learn
On 07/29/2016 02:15 PM, Mike Parker wrote: And if it is a cross-platform library that is stdcall on Windows and cdecl elsewhere: extern(C) void fun(); extern(System), no?

Re: The Mystery of the Misbehaved Malloc

2016-07-29 Thread ag0aep6g via Digitalmars-d-learn
On 07/30/2016 07:00 AM, 岩倉 澪 wrote: auto mem = malloc(2^^31); 2^^31 is negative. 2^^31-1 is the maximum positive value of an int, so 2^^31 wraps around to int.min. Try 2u^^31.

Re: Cannot compare object.opEquals is not nogc

2016-07-31 Thread ag0aep6g via Digitalmars-d-learn
On 07/31/2016 08:43 PM, Rufus Smith wrote: e.g., I have a nogc container and a remove(T obj). I can't search for obj and remove it because opEquals is not marked nogc. So I need an alternative that is somewhat robust. Jonathan M Davis has already mentioned his plans to templatize object.opEqua

Re: Converting int to dchar?

2016-07-31 Thread ag0aep6g via Digitalmars-d-learn
On 07/31/2016 11:31 PM, Darren wrote: If I try and cast it to dchar, I get messed up output, Because it gives you a dchar with the numeric value 5 which is some control character. and I'm not sure how to use toChars (if that can accomplish this). value = i.toChars.front; toChars conv

Re: alias to function literal, call without () not possible

2016-08-04 Thread ag0aep6g via Digitalmars-d-learn
On 08/03/2016 09:40 PM, Andre Pany wrote: Thanks for the info. Yes, I forgot the () for new Object; Adding the () for new Object() still returns the same error. `new Object` without parentheses is perfectly fine.

Re: assert or throw in range members?

2016-08-05 Thread ag0aep6g via Digitalmars-d-learn
On 08/05/2016 12:25 PM, Nordlöw wrote: Should range members front() and back() assert() or throw() on emptyness? If it should assert() doesn't that lead to unsafer code in release mode? What's the consensus here? It's an error in the program when front/back is called on an empty range. Every

Re: I need a @nogc version of hashOf(). What are the options?

2016-08-07 Thread ag0aep6g via Digitalmars-d-learn
On 08/07/2016 06:42 PM, Gary Willoughby wrote: I need a @nogc version of hashOf(). Here's one i'm currently using but it's not marked as @nogc. https://github.com/dlang/druntime/blob/master/src/object.d#L3170 That seems to be an oversight. https://github.com/dlang/druntime/pull/1624

Re: I need a @nogc version of hashOf(). What are the options?

2016-08-07 Thread ag0aep6g via Digitalmars-d-learn
On 08/07/2016 07:10 PM, ag0aep6g wrote: https://github.com/dlang/druntime/pull/1624 Has been merged. Is going to be part of 2.072.

Re: callback craziness

2016-08-07 Thread ag0aep6g via Digitalmars-d-learn
On 08/07/2016 10:01 PM, Engine Machine wrote: @nogc void foo(void delegate(int x) @nogc f); fails with the @nogc. Compiles just fine for me. 2nd, I cannot use a delegate because of the @nogc context, Delegates don't necessarily need a GC allocation. They only need it when they need a clos

Re: callback craziness

2016-08-07 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2016 12:08 AM, Engine Machine wrote: On Sunday, 7 August 2016 at 20:48:29 UTC, ag0aep6g wrote: [...] Delegates don't necessarily need a GC allocation. They only need it when they need a closure. Delegates of methods don't need closures. And when you pass the delegate in a `scope` param

Re: callback craziness

2016-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2016 02:42 AM, Engine Machine wrote: So, what about passing in the lambda verses the temp variable? Nothing. I didn't see a case where it worked one way but not the other. If you have code where adding a variable makes things work, please post a complete test case. [...] My code i

Re: method static-ness has no effect on the type?

2016-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2016 10:30 AM, Cauterite wrote: See: https://dpaste.dzfl.pl/2ec6780d4b25 That code is short enough to post it here directly. For easier reference, this is it: struct S { void f1() { auto x = &this; }; static void f2() {

Re: Cannot distinguish between template function wtih 0 args and 1 arg

2016-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2016 04:36 AM, Engine Machine wrote: This really makes no sense Error: template Mem cannot deduce function from argument types !(cast(eException)1280L, "main.d", 38u, "main.WinMain")(int), candidates are: Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, string func = __FUNCT

Re: method static-ness has no effect on the type?

2016-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2016 12:14 PM, Cauterite wrote: On Monday, 8 August 2016 at 10:05:58 UTC, ag0aep6g wrote: The first assert compares the return types of f1 and f2. They both return `void`, so everything's fine there. I think you're mistaken about this. typeof(S.f1) definitely gives the type of the fun

Re: encoding ISO-8859-1 to UTF-8 in std.net.curl

2016-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2016 09:57 PM, Alexsej wrote: // content in ISO-8859-1 to UTF-8 encoding but I lose //the Cyrillic "отсутствует или неверно задан параметр" // I get it "отсутствует или неверно задан параметр" // How do I change the encoding to UTF-8

Re: encoding ISO-8859-1 to UTF-8 in std.net.curl

2016-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/08/2016 11:11 PM, ag0aep6g wrote: Why on earth does transcode only accept immutable characters for input? https://github.com/dlang/phobos/pull/4722

Re: encoding ISO-8859-1 to UTF-8 in std.net.curl

2016-08-08 Thread ag0aep6g via Digitalmars-d-learn
On 08/09/2016 12:05 AM, Alexsej wrote: //header from server server: nginx date: Mon, 08 Aug 2016 22:02:15 GMT content-type: text/xml; Charset=utf-8 content-length: 204 connection: keep-alive vary: Accept-Encoding cache-control: private expires: Mon, 08 Aug 2016 22:02:15 GMT set-cookie: ASPSESSION

Re: I thought mixins didn't override?

2016-08-09 Thread ag0aep6g via Digitalmars-d-learn
On 08/10/2016 12:10 AM, Engine Machine wrote: I try to use a mixin template and redefine some behaviors but D includes both and then I get ambiguity. I was sure I read somewhere that when one uses mixin template it won't include what is already there? mixin template X { void foo() { } } stru

Re: Unexpected foreach lowering

2016-08-10 Thread ag0aep6g via Digitalmars-d-learn
On 08/10/2016 10:54 PM, Steven Schveighoffer wrote: The issue is that it tries using [] on the item to see if it defines a range-like thing. Since you don't define opSlice(), it automatically goes to the subrange. This breaks for int[] as well as Array. If I add opSlice to your code (and return

Re: How to add nogc to delegate

2016-08-10 Thread ag0aep6g via Digitalmars-d-learn
On 08/11/2016 06:15 AM, Engine Machine wrote: void foo(@nogc void delegate()) doesn't work. Put it after the parameter list, like so: void foo(void delegate() @nogc)

Re: Passing Structs to function like in C

2016-08-12 Thread ag0aep6g via Digitalmars-d-learn
On 08/12/2016 05:23 PM, Cauterite wrote: void main() { [...] }; No semicolon there, please.

Re: Passing Structs to function like in C

2016-08-12 Thread ag0aep6g via Digitalmars-d-learn
On 08/12/2016 07:33 PM, Cauterite wrote: Why would I not terminate a declaration with a semi-colon? Why should a declaration not end in a semi-colon just because the last token is a brace? Why should I not tell the lexer precisely where my declaration ends instead of relying on whatever other tok

Re: Passing Structs to function like in C

2016-08-13 Thread ag0aep6g via Digitalmars-d-learn
On 08/13/2016 09:23 PM, Engine Machine wrote: Then it should error if it doesn't accept ';'. If it accepts it then it is legal. It is legal, yes. It's also pointless and misleading. It should be pointed out for the benefit of the author, as they may have a misconception about D syntax. It sho

Re: static immutable and lambdas inside struct or class. Is that bug or not?

2016-08-14 Thread ag0aep6g via Digitalmars-d-learn
On 08/14/2016 04:27 PM, Uranuz wrote: Greatings! I need help with these lines bellow. I don't understand why it doesn't compile. Is it bug somewhere in Phobos or compiler? Or just I wrote smth wrong? //- struct A { import std.algorithm: map; import std.array: array; import std

Re: When does take modify the underlying iterator?

2016-08-16 Thread ag0aep6g via Digitalmars-d-learn
On 08/16/2016 11:01 PM, cy wrote: auto failhard(T)(T iter) { [...] writeln("We take 1 from it..."); writeln(iter.take(1)); This line may or may not pop the first element of the original iter. That's because copying a range may or may not be same as calling .save on it. For many forw

Re: When does take modify the underlying iterator?

2016-08-16 Thread ag0aep6g via Digitalmars-d-learn
On 08/16/2016 11:34 PM, ag0aep6g wrote: As for the example, you can rewrite it like so: auto failhard(T)(T iter) { import std.stdio; import std.range: take, drop, refRange; writeln("We have some range:"); writeln(typeid(T)); writeln("We take 1 from it..."); writeln(

Re: When does take modify the underlying iterator?

2016-08-16 Thread ag0aep6g via Digitalmars-d-learn
On 08/16/2016 11:41 PM, ag0aep6g wrote: My apologies, that actually prints "[0, 1, 2, 3]" in the array case. I don't what's going on. That should work. Maybe I'm misunderstanding something about refRange. Oh, I see. `take` is being clever. When possible, it slices the given range instead of po

Re: typeof.stringof wrong type

2016-08-17 Thread ag0aep6g via Digitalmars-d-learn
On 08/17/2016 02:08 PM, Eugene Wissner wrote: I have a problem, that .stringof doesn't return what I'm expecting. Consider the following: template A(string T) { enum A : bool { yes = true, } } void main() { A!"asdf" a1; typeof(a1) a2; mixin(typeof(a1).stringof ~

Re: Sequence separation

2016-08-17 Thread ag0aep6g via Digitalmars-d-learn
On 08/17/2016 08:38 PM, Engine Machine wrote: On Wednesday, 17 August 2016 at 08:37:32 UTC, Lodovico Giaretta wrote: [...] You mean something like: struct MySequence(Args...) { enum length = Args.length; alias args = Args; } alias x = MySequence!(a, b, MySequence!(c, d)); static asse

Re: Sequence separation

2016-08-17 Thread ag0aep6g via Digitalmars-d-learn
On 08/17/2016 09:21 PM, Lodovico Giaretta wrote: import std.traits: TemplateOf; static if (__traits(isSame, TemplateOf!(x.args[2]), MySequence)) { ... } std.traits.TemplateOf extracts the symbol representing the uninstantiated template. __traits(isSame, symbol1, symbol2) evaluates at compil

Re: typeof.stringof wrong type

2016-08-19 Thread ag0aep6g via Digitalmars-d-learn
On 08/19/2016 02:42 PM, Eugene Wissner wrote: fullyQualifiedName doesn't work with BitFlags for example: I think that qualifies as a bug, because fullyQualifiedName is supposed to be usable in code generation.

Re: typeof.stringof wrong type

2016-08-19 Thread ag0aep6g via Digitalmars-d-learn
On 08/19/2016 05:36 PM, David Nadlinger wrote: This is a misconception. Neither .stringof nor fullyQualifiedName should *ever* be used in code generation. The spec itself recommends fullyQualifiedName for code generation: Note: Using .stringof for code generation is not recommended, as the in

Re: Rebind template

2016-08-20 Thread ag0aep6g via Digitalmars-d-learn
On 08/21/2016 12:11 AM, Engine Machine wrote: Is there a way to rebind the arguments of a template? template foo(X) { // X is like A!(a,b,c) Y = Rebind!(X,d,e,f); // Y is like A!(d,e,f); } foo(A!(a,b,c)); ? template Rebind(alias instance, newArgs...) { import std.traits: Templat

Re: Rebind template(bug?)

2016-08-21 Thread ag0aep6g via Digitalmars-d-learn
On 08/21/2016 09:29 PM, Engine Machine wrote: I know you like to play the right or wrong game, but did you ever learn that a single example does not prove the truth of something? But you can show in a single example that something doesn't work. You tried to do that, and you did it with a simpl

Re: How to avoid ctRegex (solved)

2016-08-21 Thread ag0aep6g via Digitalmars-d-learn
On 08/21/2016 10:06 PM, cy wrote: in the module scope, you start with: auto pattern = ctRegex!"foobar"; and you substitute with: typeof(regex("")) pattern; static this() { pattern = regex("foobar"); } I may be missing the point here, but just putting `auto pattern = regex("foobar");` at mod

Re: Rebind template(bug?)

2016-08-21 Thread ag0aep6g via Digitalmars-d-learn
On 08/22/2016 12:06 AM, Engine Machine wrote: T!()'s "data" is specified in the class just like all the other derivations. I don't want to have to specify an external base class as in your InstaniateOrBase. Why? Because!!! (There should be no need to, and if one goes this route of creating classe

Re: Rebind template(bug?)

2016-08-22 Thread ag0aep6g via Digitalmars-d-learn
On 08/22/2016 08:04 PM, Engine Machine wrote: How do you seriously think this is cleaner/simpler? You have two classes. Their is no uniformity between them. You have uniformity between all the derived classes then have a special case for the base class. A certain easy to follow pattern is set up

Re: Rebind template(bug?)

2016-08-22 Thread ag0aep6g via Digitalmars-d-learn
On 08/22/2016 08:54 PM, Engine Machine wrote: Yeah, but a name means nothing. Change it if you want ;) Even with a better name it still requires a good amount of thinking by the reader to see what's going on. [...] What it achieves is a uniform way to create a hierarchical relationship with

Re: Rebind template(bug?)

2016-08-22 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 22 August 2016 at 21:46:35 UTC, Engine Machine wrote: I'm sorry if it confuses you... it doesn't confuse me. You needed quite some help to get this thing to work. And you made some mistakes and wrong statements in the process. That's perfectly fine, but please don't act as if Jack

Re: How to avoid ctRegex (solved)

2016-08-22 Thread ag0aep6g via Digitalmars-d-learn
On 08/23/2016 06:06 AM, cy wrote: On Sunday, 21 August 2016 at 21:18:11 UTC, ag0aep6g wrote: I may be missing the point here, but just putting `auto pattern = regex("foobar");` at module level works for me. Really? I thought global variables could only be initialized with static stuff availab

Re: Rebind template(bug?)

2016-08-22 Thread ag0aep6g via Digitalmars-d-learn
On 08/23/2016 03:23 AM, Engine Machine wrote: On Monday, 22 August 2016 at 22:52:28 UTC, ag0aep6g wrote: [...] Simply not replying is an option, too. It may be a bit less polite, but it's better than escalating things. True, but then you should also take your own advice. Yeah, I'm going to

Re: How to avoid ctRegex (solved)

2016-08-23 Thread ag0aep6g via Digitalmars-d-learn
On 08/24/2016 03:07 AM, cy wrote: Then what's ctRegex in there for at all...? Optimization. ctRegex requires that the pattern is available as a compile time constant. It uses that property to "generate optimized native machine code". The plain regex function doesn't have such a requirement.

Re: pow exponent type issue

2016-08-24 Thread ag0aep6g via Digitalmars-d-learn
On Wednesday, 24 August 2016 at 19:16:56 UTC, jmh530 wrote: I'm a little confused on why pow behaves so differently when switching from an int to a uint for the exponent. import std.math : pow; import std.stdio : writeln; void main() { float x = 2; int y1 = 1; uint y2

Re: How to avoid ctRegex (solved)

2016-08-27 Thread ag0aep6g via Digitalmars-d-learn
On 08/27/2016 07:35 PM, cy wrote: When I saw `auto a = b;` at the module level, I thought that b had to be something you could evaluate at compile time. That's right. But I guess it can be a runtime calculated value, acting like it was assigned in a a static this() clause, No, that's not ri

Re: Template not seeming to instantiate a second time with default alias parameter

2016-08-30 Thread ag0aep6g via Digitalmars-d-learn
On 08/30/2016 10:41 PM, wobbles wrote: class Node(T, alias func = (T t => t*t))(){ //whatever } //instantiate Node!(int) intNode; Node!(float) floatNode; // fails as lambda func expects an int. Am I doing something wrong or is this a bug? Proper test case: class Node(T, alias func = (

Re: Template not seeming to instantiate a second time with default alias parameter

2016-08-30 Thread ag0aep6g via Digitalmars-d-learn
On 08/30/2016 11:28 PM, wobbles wrote: I'll have to try find a workaround for now :/ This seems to work and isn't too ugly: class Node(T, alias func) {/*...*/} alias Node(T) = Node!(T, (T t) => t*t);

Re: Template not seeming to instantiate a second time with default alias parameter

2016-08-30 Thread ag0aep6g via Digitalmars-d-learn
On 08/30/2016 11:28 PM, wobbles wrote: I'll have to try find a workaround for now :/ This also seems to work, but has a slightly different meaning: class Node(T, alias func = t => t*t) {/* ... */} The default func is a template here. Equivalent to this: auto square(T)(T t) { r

Re: Debug prints in @nogc

2016-08-31 Thread ag0aep6g via Digitalmars-d-learn
On 08/31/2016 09:23 PM, Yuxuan Shui wrote: Correct me if I'm wrong. But I believe this is only true when the source code of function is not available. Otherwise the compiler should always know if a function is actually @nogc or not. Attributes are only inferred in certain cases where the source

Re: Assign any event kind to a single templatized function ?

2016-09-05 Thread ag0aep6g via Digitalmars-d-learn
On 09/05/2016 03:44 PM, Basile B. wrote: °° module runnable; import std.stdio; struct Foo { void delegate(int) event1; void delegate(int,int) event2; void delegate(int,ref int) event3; } struct Handler { void handle(A...)(A a){writeln(a);} void h

Re: Assign any event kind to a single templatized function ?

2016-09-05 Thread ag0aep6g via Digitalmars-d-learn
On 09/05/2016 04:00 PM, ag0aep6g wrote: You can pass the delegate type itself by alias. [...] void handlef(F)(Parameters!F a){writeln(a);} Don't know why I wrote "by alias". Clearly no alias there.

Re: dependency analysis for makefile construction

2016-09-05 Thread ag0aep6g via Digitalmars-d-learn
On 09/04/2016 12:07 AM, dan wrote: Are there any FOSS tools for doing dependency analysis of (e.g.) all the d files in a directory, to let you know when a .o file needs to be regenerated? This presumably would depend mostly on the import statements (including import of any file to be used in str

Re: inferred vs. annotated attributes

2016-09-10 Thread ag0aep6g via Digitalmars-d-learn
On 09/10/2016 10:23 AM, Q. Schroll wrote: Is there a difference between inferred and annotated attributes? Example: struct X(T) { this(S)(in S[] arr) // inferred pure { } } void main() pure { X!uint mut = [ 1, 2 ]; // proves inference (cf. main is pur

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

2016-09-10 Thread ag0aep6g via Digitalmars-d-learn
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 it gets called: struct S { bool opCast(T : bool)() { retu

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

2016-09-10 Thread ag0aep6g via Digitalmars-d-learn
On 09/10/2016 04:29 PM, pineapple wrote: Was this a recent addition to the language? I don't think so.

Re: cloning arrays

2016-09-12 Thread ag0aep6g via Digitalmars-d-learn
On 09/12/2016 08:56 AM, Russel Winder via Digitalmars-d-learn wrote: Which raises the question of whether: x[] and x.dup have the same result. No. x[] is a nop for dynamic arrays. Only the array struct (pointer and length) gets copied, as it always does. x.dup copies the a

Re: seg fault, now what?

2016-09-17 Thread ag0aep6g via Digitalmars-d-learn
On 09/17/2016 11:58 PM, Ryan wrote: On Saturday, 17 September 2016 at 21:44:22 UTC, Stefan Koch wrote: [...] Post the program somewhere otherwise we cannot help. [... code ...] Reduced and filed: https://issues.dlang.org/show_bug.cgi?id=16506

Re: how to access struct member using [] operator?

2016-09-25 Thread ag0aep6g via Digitalmars-d-learn
On 09/25/2016 06:26 PM, Basile B. wrote: Can we get an explanation from a compiler guy ? It seems the the switch statement is already evaluated at compiled time... Lodovico has already answered this. It's just an ordinary `auto` return type function. The actual return type is the common type

Re: dmd -o- option meaning changed recently? Now not creating OBJ but also not creating EXE

2016-10-02 Thread ag0aep6g via Digitalmars-d-learn
On 10/02/2016 10:33 PM, A D dev wrote: When I compile single-file D programs, I don't want to keep the generated object file (.OBJ, on Windows). I had checked the D compiler options for this (using dmd --help), and IIRC, a few weeks ago, I had used the -o- option (do not write object file) with a

Re: bug, or is this also intended?

2016-10-03 Thread ag0aep6g via Digitalmars-d-learn
On 10/03/2016 01:40 PM, deed wrote: Unexpected auto-concatenation of string elements: string[] arr = ["a", "b" "c"];// ["a", "bc"], length==2 int[] arr2 = [[1], [2] [3]];// Error: array index 3 is out of bounds [2][0 .. 1] // Error: array index 3 is ou

<    1   2   3   4   5   6   7   8   >