Re: 3d vector struct

2014-02-07 Thread Stanislav Blinov
On Friday, 7 February 2014 at 21:37:26 UTC, Casper Færgemand wrote: On Friday, 7 February 2014 at 10:50:49 UTC, Stanislav Blinov wrote: I know. I also know that people making games are obsessed with performance :) And, where there's 3d vector, there would also be 4d vector and matrices

Re: Avoiding allocation in broadcast server

2014-02-07 Thread Stanislav Blinov
To me it seems that you have to have at least one allocation per string received. To submit your string to another thread verbatim, you have to be able to guarantee that the buffer is immutable, which you cannot do because you can receive a new string at any given time (which would overwrite

Re: Testing some singleton implementations

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 00:11:58 UTC, Jerry wrote: Here's the best and worst times I get on my linux laptop. These are with 2.064.2 dmd and gdc 4.9 with 2.064.2 On Ubuntu x86_64: ~/dmd2/linux/bin64/dmd -O -release -inline -noboundscheck -unittest singleton.d Test 2 time for

Re: Testing some singleton implementations

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 08:39:08 UTC, Andrej Mitrovic wrote: No difference, but maybe the timing precision isn't proper. It always displays one of 3/3.25/4 msecs. Hmm... It should be as proper as it gets, judging from StopWatch's docs. Anywho what's important is that Atomic is

Re: opAssign and template class

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 10:33:08 UTC, dbjdbj wrote: Please consider this: http://dpaste.dzfl.pl/dc4a3c29e57f What is my mistake ? Thanks ... You cannot overload identity assignment for classes. It's a language construct that rebinds a reference and cannot be overridden. Such

Re: opAssign and template class

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 12:29:11 UTC, dbjdbj wrote: I need to be able to implement = operator so that this works: auto x_ = new X(), x2 = x_ ; objects)alive needs to be 2 after. Thanks ... You can't. Classes are reference types. This just doesn't make sense: x2 = x_; does not

Re: opAssign and template class

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 13:38:08 UTC, dbjdbj wrote: You can't. Classes are reference types. This just doesn't make sense: x2 = x_; does not create any new objects. *object_alive* is what I mentioned, not object_create Yes, but in your implementation you intend to increment both

Re: Testing some singleton implementations

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 21:47:40 UTC, Jerry wrote: I downloaded the test program yesterday. Here's my latest revision: http://dpaste.dzfl.pl/5b54df1c7004 Andrej, I hope you don't mind me fiddling with that code? I've put that atomic fix in there, also switched timing to use hnsecs

Re: scope attribute vs scope keyword vs scope storage class

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 11:01:00 UTC, Mike wrote: Are all these terms (scope attribute, scope keyword, and scope storage class) referring to the same thing? scope keyword and scope storage class stay: http://dlang.org/function.html#parameters Although AFAIK it's not yet

Re: Explicit Class Instance Allocation

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 11:23:57 UTC, Mike wrote: On Wednesday, 5 February 2014 at 11:19:00 UTC, bearophile wrote: Mike: class Foo { new(size_t sz) Also that usage of new() is deprecated. Bye, bearophile Thank you, but can you please point me to your source. It's not listed

Re: Explicit Class Instance Allocation

2014-02-05 Thread Stanislav Blinov
On Wednesday, 5 February 2014 at 12:12:12 UTC, bearophile wrote: https://d.puremagic.com/issues/show_bug.cgi?id=12081 Why do I sense another holy war in the bugzilla coming? :)

Re: Testing some singleton implementations

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 09:44:04 UTC, Andrej Mitrovic wrote: I've finally managed to build LDC2 on Windows (MinGW version), here are the timings between DMD and LDC2: $ dmd -release -inline -O -noboundscheck -unittest singleton_2.d -oftest.exe test.exe Test time for LockSingleton:

Re: Testing some singleton implementations

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 14:23:51 UTC, Andrej Mitrovic wrote: On 2/4/14, Stanislav Blinov stanislav.bli...@gmail.com wrote: Have you also included fixes from http://forum.dlang.org/post/khidcgetalmguhass...@forum.dlang.org ? I haven't figured out exactly what you're trying to swap

Re: Two Questions

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 16:18:24 UTC, Steve Teale wrote: What proportion of the D community develops on Linux of some sort, and what proportion works with a 64 bit OS? Linux 64 bit. And why? Why not? :)

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket) Create a connection to another LAN machine with a known address (e.g.

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 13:31:27 UTC, TheFlyingFiddle wrote: Problem is that i don't know in what local network the server will be running, so this is unfortunatly not an option for me. But if that's the case, the hostname solution may as well just give you your loopback address. :)

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 16:02:33 UTC, Craig Dillabaugh wrote: This computer is on a network with dynamically assigned IP address (DHCP). So shouldn't the 10.1.101.52 address have been reported? Nope. In out-of-the-box simple network setups (i.e. home network in the form PC/laptop -

Re: Templates: generic return null;

2014-02-03 Thread Stanislav Blinov
On Monday, 3 February 2014 at 10:25:19 UTC, Chris wrote: T[T] attributes; // public auto getAttribute(T attr) { if (!(attr in attributes)) { return null; // Doesn't work for numbers! } return attributes[attr]; } } One way would be to use

Re: Templates: generic return null;

2014-02-03 Thread Stanislav Blinov
On Monday, 3 February 2014 at 10:55:23 UTC, Chris wrote: I'm reluctant to (over)use throw, because I think that throw should be the last resort when you cannot easily predict all the things that can go wrong. Simple requests should give simple answers. If the key doesn't exist it returns

Re: 3d vector struct

2014-02-03 Thread Stanislav Blinov
On Monday, 3 February 2014 at 20:10:59 UTC, Brenton wrote: 4) Is it advisable for the cross method to return by value? In C++, I would declare this method as inline and in a header file. Can I trust D to inline away this inefficiency? Perhaps I should pass in the result as a ref or out

Re: std.array.array broken?

2014-02-02 Thread Stanislav Blinov
On Sunday, 2 February 2014 at 01:03:25 UTC, Andrei Alexandrescu wrote: I would have had it my way, I would introduce: byLine - safe, doesn't reuse a buffer byLineBuffer - reuses a buffer No. Too much breakage. How exactly is it breakage? The user code: - will not stop to compile - will

Re: Testing some singleton implementations

2014-02-01 Thread Stanislav Blinov
On Friday, 31 January 2014 at 23:35:25 UTC, Stanislav Blinov wrote: // (2) if (!atomicLoad!(MemoryOrder.raw)(_instantiated)) { // (1) synchronized { // - this is 'acquire' if (_instance is null) { //(3

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
You forgot to make the flag static for AtomicSingleton. I'd also move the timing into the threads themselves, for fairness :) http://codepad.org/gvm3A88k Timings on my machine: ldc2 -unittest -release -O3: Test time for LockSingleton: 537 msecs. Test time for SyncSingleton: 2 msecs. Test

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 10:26:50 UTC, Dejan Lekic wrote: I should have mentioned two things in my previous post. 1) There are no locks involved. No need, because the solution relies on the fact that static member variables are guaranteed to be created the first time they are accessed.

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 10:39:19 UTC, Andrej Mitrovic wrote: On 1/31/14, Stanislav Blinov stanislav.bli...@gmail.com wrote: You forgot to make the flag static for AtomicSingleton. Ah. It was copied verbatim from reddit, I guess we both missed it. Yeah, with D's verbosity

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 10:27:28 UTC, Namespace wrote: Why is someone interested in implementing such an Ani Pattern like Singletons? Why is someone overquoting without reason? ;) In most of all cases Singletons are misused. Any sort of shared (as in, between threads) resource is

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 10:57:53 UTC, Andrej Mitrovic wrote: The atomic implementation probably beats the TLS version when a lot of new threads are being spawned at once and they only retrieve the singleton which has already been initialized. E.g., say a 1000 threads are spawned.

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 11:08:42 UTC, Dejan Lekic wrote: I believe it should have been final instead of const. But D doesn't have final :) In any event, that article by Mike Parker is about D1.

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 11:18:03 UTC, Andrej Mitrovic wrote: On 1/31/14, Stanislav Blinov stanislav.bli...@gmail.com wrote: First, subsequent runs on my machine show interleaving results. It also seems that either there *is* a race in there somewhere, or maybe a bug?.. Some runs just flat

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 11:34:13 UTC, Dejan Lekic wrote: SingletonSimple is a winner, followed by the SyncSingleton and SingletonLazy. Dejan, your singletons are thread-local :)

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 11:31:53 UTC, Benjamin Thaut wrote: For x86 CPUs you don't really need MemoryOrder.acq as reads are atomic by default. Uhm... atomicLoad() itself guarantees that the read is atomic. It's not about atomicity of operation, it's about sequential consistency. Using

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
In fact #2, I think it's even safe to pull that store out of the synchronized block: // (2) if (!atomicLoad!(MemoryOrder.raw)(_instantiated)) { // (1) synchronized { // - this is 'acquire' if (_instance is null) {

Re: Testing some singleton implementations

2014-01-31 Thread Stanislav Blinov
On Friday, 31 January 2014 at 15:18:43 UTC, Dmitry Olshansky wrote: 31-Jan-2014 17:26, Stanislav Blinov пишет: In fact #2, I think it's even safe to pull that store out of the synchronized block: // (2) if (!atomicLoad!(MemoryOrder.raw)(_instantiated

Re: Reference parent type

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 09:03:17 UTC, Frustrated wrote: mixin t!(typeof(this))

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 09:14:43 UTC, Cooler wrote: Please stop explain me how fun3() works. I know that. One of the main idea of D is that things must work as planned, or would not compile at all. First and second variants follow this idea. But fun3() can work not as planned on the

Re: Keywords: How to trick the compiler?

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 10:15:10 UTC, Chris wrote: offspring = document.createElement(div); document.torso.addOffspring(div); Looks great! :D

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 18:05:41 UTC, Stanislav Blinov wrote: Yep, doesn't seem to be simd-related: struct S(T) { T v1, v2; } void main() { alias T = double; // integrals and float are ok :\ version (workaround) { S!T[1] p = void; } else

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
Ok, didn't need to wait for the weekend :) Looks like both dmd and ldc don't optimize slice operations yet, had to revert to loops (shaved off ~1.5 seconds for ldc, ~9 seconds for dmd). Also, my local pull of ldc had some issues with to!int(string), reverted that to atoi :) Here's the code:

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 14:17:16 UTC, Stanislav Blinov wrote: Forgot one slice assignment in toDobule2(). Now the results are more interesting: time ./nbody-cpp 5000: -0.169075164 -0.169059907 0:05.20 real, 5.18 user, 0.00 sys, 532 kb, 99% cpu time ./nbody-ldc 5000

Re: How to call opCall as template?

2014-01-30 Thread Stanislav Blinov
void main() { F f; int i = f(3,4,5); float f_ = f!float(6, 7, 8); } Does not work, it fails with: Error: template instance f!float f is not a template declaration, it is a variable f.opCall!float(6, 7, 8);

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 16:53:22 UTC, bearophile wrote: Yes. The older version of LDC2 doesn't even compile the code. I need to use 0.13.0-alpha1. Hmm. Your D code with small changes: http://codepad.org/xqqScd42 That won't compile with dmd (at least, with 2.064.2): it expects

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 18:29:42 UTC, bearophile wrote: I see you're compiling with ldmd2 -wi -O -release -inline -noboundscheck nbody.d Try ldc2 -release -O3 -disable-boundscheck -vectorize -vectorize-loops

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 18:43:02 UTC, bearophile wrote: It's a very silly problem for a statically typed language. The D type system knows the static length of those arrays, but it doesn't use such information. I agree. Unrolling everything except the loop in energy() seems to have

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 21:04:06 UTC, bearophile wrote: Stanislav Blinov: Unrolling everything except the loop in energy() seems to have squeezed the bits neede to outperform c++, at least on my machine :) That should be impossible, as I remember from my old profilings that energy

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 21:33:38 UTC, bearophile wrote: If a function takes no time to run, and you tweak it, your program is not supposed to go faster. Right. I was going to compare the asm listings, but C++ seems to have unrolled and inlined the outer loop right inside main(), and

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 21:54:17 UTC, bearophile wrote: You seem to have a quite recent CPU, An aging i3? as the G++ code contains instructions like vmovsd. So you can try to do the same with ldc2, and use AVX or AVX2. Hmm... This is getting a bit silly now. I must have some

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 22:45:45 UTC, bearophile wrote: Since my post someone has added a Fortran version based on the algorithm used in the C++11 code. It's a little faster than the C++11 code and it's much nicer looking: Yup, I saw it. They're cheating, they almost don't have to

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 00:08:02 UTC, Meta wrote: On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote: Got any tips? Ranges, templates and structs. ~= CTFE ~ UFCS

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
Gah! G'Kar moment... http://dpaste.dzfl.pl/203d237d7413

Re: How to call opCall as template?

2014-01-30 Thread Stanislav Blinov
Ask yourself this: in regards to overload resolution, when should template instantiation occur?

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 04:53:48 UTC, Matt Soucy wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared ); // Sorry but that was going to cause a slight

Re: Typed variadic template syntax?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 09:50:13 UTC, Timon Gehr wrote: import std.range, std.algorithm; int value(int xs[]...) { return reduce!((a,b)=10*a+b)(0,xs.retro); } Sadly, you can't build a struct (with N int fields) or an enum this way.

Re: Typed variadic template syntax?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 16:39:31 UTC, Andrei Alexandrescu wrote: On 1/29/14 1:53 AM, Stanislav Blinov wrote: Sadly, you can't build a struct (with N int fields) or an enum this way. mixin m|

Re: Reviving YAGE

2014-01-29 Thread Stanislav Blinov
I couldn't find anything that says what YAGE is. I suspect a game engine from some of the commits. http://yage3d.net/

Re: Sorting structs?

2014-01-29 Thread Stanislav Blinov
It's also worth noting that you can avoid passing structs into predicate function by value, and instead pass them by reference: sort!((ref const a, ref const b) = a.grade b.grade)(students); This is useful for heavy structs to save on performance. E.g. in this case, Student.sizeof is 24 bytes

Re: Set global immutables from main/getopt?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 00:28:29 UTC, Meta wrote: You can also use the Github Gist feature for displaying code, can't you? But you'd need a github account for that, won't you? :)

Re: Sorting structs?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 10:30:06 UTC, Boomerang wrote: I'll paste here with comments: import std.algorithm; import std.stdio; import std.array; void main() { struct Student { string name; float grade; } Student[] studs; writeln(Enter student data.

Re: Sorting structs?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 12:44:37 UTC, Tobias Pankrath wrote: On Wednesday, 29 January 2014 at 11:24:54 UTC, Stanislav Blinov wrote: // Or avoid foreach altogether: studs.map!((ref const s) = writeln(s.name)); } Did you test this one? std.algorithm.map is lazy. Ah yes, sorry

Re: Array as an argument, ambiguous behaviour.

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 16:26:05 UTC, Cooler wrote: Where argument has the same length? After function call, or inside function? I don't understand what my intention should be to push me to use fun3()? Gosh. To allow the function to modify the contents, but not the size of the

Re: N-body bench

2014-01-29 Thread Stanislav Blinov
On Friday, 24 January 2014 at 15:56:26 UTC, bearophile wrote: If someone if willing to test LDC2 with a known benchmark, there's this one: http://benchmarksgame.alioth.debian.org/u32/performance.php?test=nbody A reformatted C++11 version good as start point for a D translation:

Re: N-body bench

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 16:43:35 UTC, bearophile wrote: Stanislav Blinov: Hmm.. How would one use core.simd with LDC2? It doesn't seem to define D_SIMD. Or should I go for builtins? I don't know if this is useful for you, but here I wrote a basic usage example of SIMD in ldc2

Re: Array as an argument, ambiguous behaviour.

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 16:54:27 UTC, Cooler wrote: On Wednesday, 29 January 2014 at 16:36:44 UTC, Stanislav Blinov wrote: On Wednesday, 29 January 2014 at 16:26:05 UTC, Cooler wrote: Where argument has the same length? After function call, or inside function? I don't understand what

Re: Keywords: How to trick the compiler?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 17:11:32 UTC, Ary Borenszweig wrote: Yes, as there are other ways for body: _body, _body, Body, HtmlBody, etc. But body is the best one. torso? ;)

Re: N-body bench

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 16:54:54 UTC, bearophile wrote: Stanislav Blinov: I meant how to make it compile with ldc2? I've translated the code, it compiles and works with dmd (although segfaults in -release mode for some reason, probably a bug somewhere). But with ldc2: nbody.d(68

Re: Message passing pattern matching

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 21:50:28 UTC, Casper Færgemand wrote: A small example: while (true) { receive( (Tid tid, AddTid _) {some code} (Tid tid, RemoveTid _) {some other code} (string s) {broadcast stuff} ) } struct AddTid {} struct RemoveTid {} From where I sit

Another question about move()

2014-01-28 Thread Stanislav Blinov
The documentation for std.algorithm.move() says: * If hasAliasing!T is true, then the representation of source is bitwise copied into target and then source = T.init is evaluated. * Otherwise, target = source is evaluated. However, current implementation does not in fact check for aliasing.

Re: Want your DMD to segfault?

2014-01-28 Thread Stanislav Blinov
Well, heh. It happens. lol.

Re: Typed variadic template syntax?

2014-01-28 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 00:14:31 UTC, bearophile wrote: On the other hand I don't know how much common are template instantiations with values all of the same type (like all ints as in this case) in D code. Opinions welcome. Bye, bearophile Well, if you're going for a direct

Re: Keywords: How to trick the compiler?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 12:57:02 UTC, Andrej Mitrovic wrote: body is probably the most frequent issue I run into when porting C/C++ code to D. I really wonder whether the rule could be relaxed a little bit. o_O How?

Re: Set global immutables from main/getopt?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 17:11:43 UTC, Andrew Klaassen wrote: Naturally, initialize them in constructor :) http://dpaste.dzfl.pl/620e8c61

Re: Set global immutables from main/getopt?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 18:30:37 UTC, Steven Schveighoffer wrote: On Tue, 28 Jan 2014 12:27:02 -0500, Stanislav Blinov stanislav.bli...@gmail.com wrote: http://dpaste.dzfl.pl/620e8c61 That being said, it *could* be done, since the runtime has access to the command line args

Re: Keywords: How to trick the compiler?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 22:35:31 UTC, Martin Cejp wrote: I really wonder whether the rule could be relaxed a little bit. o_O How? Not being a keyword except in places where it is used as such. Only if it's not a keyword at all, lest you complicate parsing. You wouldn't want any

Re: It works!

2014-01-27 Thread Stanislav Blinov
It's not dlang.org, it's dlang.org/index.html. I filed a bugreport on this.

Re: It works!

2014-01-27 Thread Stanislav Blinov
On Monday, 27 January 2014 at 16:11:56 UTC, Andrei Alexandrescu wrote: Sure you meant http://issues.dlang.org/ That one is even more desriptive :)

Re: Creating an array of C structs

2014-01-27 Thread Stanislav Blinov
On Monday, 27 January 2014 at 10:13:08 UTC, Colin Grogan wrote: Arrays are enclosed in [] ;) I'm an idiot. Can I delete this thread to save further embarrassment? :) No! Evenryone will see this! :E~

Re: A question about move() and a rant about shared

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 12:01:18 UTC, Stanislav Blinov wrote: then only way to go about it is to return int by ref. s/int/it/

Re: A question about move() and a rant about shared

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 07:21:15 UTC, Stanislav Blinov wrote: On Saturday, 25 January 2014 at 18:47:17 UTC, Andrei Alexandrescu wrote: We plan to disallow taking address of a ref return from a function. What about sneaky cases? E.g. like this: NullableRef!T nref(T)(ref T v

Re: Alternate signs in a range

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 12:50:05 UTC, matovitch wrote: Hello ! I got a problem which I'm sure can be solved by a smart one liner. I would like to obtain the term by term product of a given range by the infinite cyclic range cycle([1,-1]). How can I do that ? dpaste seems to be

Re: Alternate signs in a range

2014-01-26 Thread Stanislav Blinov
But it's easy to avoid the multiplication and replace it with a conditional neg. Bye, bearophile How would you do this ? map!(a = (a.index 1) ? a : -a)([1, 2]) ? (index field isn't available of course) import std.range; import std.algorithm; import std.stdio; void main() { auto

Re: Alternate signs in a range

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 13:24:06 UTC, matovitch wrote: Zipping an index array is uglier in my opinion... ;-) Extract it into a function and stick it into your library, it's extremely useful :) import std.range; import std.algorithm; import std.stdio; auto enumerate(R)(R r) {

Re: Alternate signs in a range

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 13:45:32 UTC, matovitch wrote: Anyway, the proposed solutions use twice much memory than a simple for loop... ??? is the compiler smart enougth to optimize this kind of code ? There are ongoing discussions on what and how current D compilers optimize

Re: Alternate signs in a range

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 13:49:34 UTC, bearophile wrote: Stanislav Blinov: We need generic enumerate() in Phobos :( It will come soon :-) https://github.com/D-Programming-Language/phobos/pull/1866 Cool! This also shows we need a good syntax to unpack tuples: 100% agree

Re: Alternate signs in a range

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 14:29:54 UTC, matovitch wrote: s/immutable/enum/ ? I am a *total* beginner so I am sure my code should look at least strange to experts. How should I write this ? Why ? I am not sure exactly what are you trying to achieve. My comment meant ditch immutable,

Re: Cartesian product of immutable ranges

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 21:49:37 UTC, matovitch wrote: void main() { immutable int[] B = [ 1, 2, 3 ]; immutable int[] C = [ 4, 5, 6 ]; auto BC = zip(B, C); writeln(BC); } Here B and C aren't inputRange thought acording to the template constraint of zip there should be.

Re: Manipulating Bits of Any Value Type

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 20:56:29 UTC, Nordlöw wrote: My idea to make `getBit` work on all types that have value semantics. All of them? Arbitrary structs too? floating point types? Static arrays? Might I ask... why do you need this sort of thing? :) That's why I need the cast (I

Re: Manipulating Bits of Any Value Type

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 23:37:40 UTC, Nordlöw wrote: Might I ask... why do you need this sort of thing? :) For bit-parallel run-length encoding for efficient serialization of sets of std.datetime:SysTime structures (16 bytes). SysTime's representation consists of a long and

Re: Manipulating Bits of Any Value Type

2014-01-26 Thread Stanislav Blinov
On Sunday, 26 January 2014 at 23:54:02 UTC, Stanislav Blinov wrote: On Sunday, 26 January 2014 at 23:37:40 UTC, Nordlöw wrote: The closest would be std.traits.hasIndirections. Does this work recursively on containing types? AFAIK no, it just checks immediate fields (if any). OTOH

Re: Cartesian product of immutable ranges

2014-01-26 Thread Stanislav Blinov
You might want to consider submitting a bug report on account of cartesianProduct() not being able to deal with ranges of immutable elements. The worst that can happen is that you'd get a real expert's explanation on why it's not a bug. But who knows, perhaps it is :)

Re: A question about move() and a rant about shared

2014-01-25 Thread Stanislav Blinov
On Saturday, 25 January 2014 at 10:03:55 UTC, Dmitry Olshansky wrote: In fact, the definition above would even fail to compile in this case, because push should take shared(T) and pop should return shared(T) (since Queue will be dealing with a container of shared Ts, right?) No Queue in

Re: A question about move() and a rant about shared

2014-01-25 Thread Stanislav Blinov
On Saturday, 25 January 2014 at 11:51:04 UTC, Dmitry Olshansky wrote: Escaping... where? By go with ref T you mean return value of e.g. front()? Say front returns a reference to a first element in an array. Say user stores someArray.front as pointer somewhere, and the does

Re: GUI Editors for D

2014-01-25 Thread Stanislav Blinov
On Saturday, 25 January 2014 at 18:00:48 UTC, Steve Teale wrote: I don't have Visual Studio, so the plug-in for that is out. You can download Visual Studio Shell. It's free, it just comes without any compilers or language support whatsoever. VisualD happily installs on that. MonoDevelop +

Re: A question about move() and a rant about shared

2014-01-25 Thread Stanislav Blinov
On Saturday, 25 January 2014 at 18:47:17 UTC, Andrei Alexandrescu wrote: We plan to disallow taking address of a ref return from a function. What about sneaky cases? E.g. like this: NullableRef!T nref(T)(ref T v) { return NullableRef!T(v); } struct Container(T) { //... ref

Re: Generating an enum from a tuple of Types?

2014-01-25 Thread Stanislav Blinov
On Saturday, 25 January 2014 at 15:38:39 UTC, Johannes Pfau wrote: Is it possible to generate a enum from a tuple of types without string mixins? struct S(Types...) { enum Tag { //? } } Without mixins altogether... dunno. But nothing stops you

Re: Dmitry Olshansky is now a github committer

2014-01-24 Thread Stanislav Blinov
On Friday, 24 January 2014 at 10:59:47 UTC, Dmitry Olshansky wrote: Congratulations! P.S. In seriousness I hardly see a problem of tracking handles - one click on a handle and you have the user profile with name/surname in big gray letters. You're willing to let a click stand between

Re: Should this work?

2014-01-24 Thread Stanislav Blinov
On Friday, 24 January 2014 at 08:21:12 UTC, Jacob Carlborg wrote: On 2014-01-23 21:53, Andrei Alexandrescu wrote: I would expect contains to take a element and check if it exists in the range. I think canFind is just a weird name. I agree on the latter point. As for contains... Well, if

A question about move() and a rant about shared

2014-01-24 Thread Stanislav Blinov
Ok, this is going to be a long one, so please bear with me. I'll start with a question. 1. std.algorithm.move() and std.container TDPL describes when a compiler can and cannot perform a move automatically. For cases when it isn't done automatically but we explicitly require a move, we have

Re: A question about move() and a rant about shared

2014-01-24 Thread Stanislav Blinov
Ouch. Please excuse the formatting. I didn't pay attention when pasting this :|

Re: A question about move() and a rant about shared

2014-01-24 Thread Stanislav Blinov
On Friday, 24 January 2014 at 19:54:31 UTC, Dmitry Olshansky wrote: 2 unrelated questions would be better as 2 nice smaller posts. Just saying. I know. Sorry if it got you irritated. I have a feeling I'll be coming back with questions that are based on both move() and shared tied up

Re: TLF = thread local functions

2014-01-24 Thread Stanislav Blinov
On Friday, 24 January 2014 at 06:03:27 UTC, dennis luehring wrote: no - the parameters and local vars of the function are in the stack of the thread - so there is no problem with them, only shared variables can have a need to synchronization your idea tries to solve non existing problems?

<    2   3   4   5   6   7   8   9   >