Re: trait detecting anonymous union?

2017-05-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 May 2017 at 21:03:42 UTC, Bastiaan Veelo wrote: ` void main() { import std.stdio; struct S { int i; union { int a; double b; } } S

Destructor attribute inheritance, yea or nay?

2017-05-22 Thread Stanislav Blinov via Digitalmars-d
I'd like to hear what you guys think about this issue: https://issues.dlang.org/show_bug.cgi?id=15246 Marco argues that because "it currently doesn't work that way" (i.e. destructors are not inherited), the bug is invalid. However, what this means in practice is: - destroy()/rt_finalize()

Re: Value closures (no GC allocation)

2017-05-22 Thread Stanislav Blinov via Digitalmars-d
On Monday, 22 May 2017 at 14:06:54 UTC, Vittorio Romeo wrote: On Sunday, 21 May 2017 at 20:25:14 UTC, Adam D. Ruppe wrote: Blah. Well, let's go ahead and formally propose the C++ syntax, our library solutions are all fat. Are you going to create a DIP for this? I would be happy to

Re: The dlang-tour translations need you

2017-05-22 Thread Stanislav Blinov via Digitalmars-d
On Monday, 22 May 2017 at 14:52:43 UTC, Seb wrote: Russian --- - Welcome & Basic chapter completely translated - https://tour.dlang.org/tour/ru/welcome/welcome-to-d - Huge thanks to @El-Lin, @dmi7ry, @9il, @Dicebot, @DmitryOlshansky If nobody's working on that already, I'll take the

Re: Why would an initialised struct pointer field be null in the struct's destructor?

2017-05-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 May 2017 at 00:45:27 UTC, Adam D. Ruppe wrote: On Monday, 22 May 2017 at 00:36:24 UTC, Stanislav Blinov wrote: I can't think of any case where you'd want preconditions on destructor when the object is in .init state. I think we're actually saying the same thing: I mean

Re: Why would an initialised struct pointer field be null in the struct's destructor?

2017-05-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 May 2017 at 00:23:26 UTC, Adam D. Ruppe wrote: On Sunday, 21 May 2017 at 14:13:20 UTC, Stanislav Blinov wrote: Not if you either emplace() or blit Foo.init into all of the array elements. You especially need to be safe calling ~this on Foo.init. How so? .init is supposed

Re: Why would an initialised struct pointer field be null in the struct's destructor?

2017-05-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 21 May 2017 at 23:59:08 UTC, Guillaume Piolat wrote: On Sunday, 21 May 2017 at 12:48:10 UTC, Adam D. Ruppe wrote: Any struct should be able to have its destructor called Does this rule also applies to class objects? Yes. If your destructor does modify the state, you should expect

Re: Value closures (no GC allocation)

2017-05-21 Thread Stanislav Blinov via Digitalmars-d
On Sunday, 21 May 2017 at 20:25:14 UTC, Adam D. Ruppe wrote: Blah. Well, let's go ahead and formally propose the C++ syntax, our library solutions are all fat. :)

Re: Value closures (no GC allocation)

2017-05-21 Thread Stanislav Blinov via Digitalmars-d
On Sunday, 21 May 2017 at 19:43:32 UTC, Adam D. Ruppe wrote: On Sunday, 21 May 2017 at 19:11:46 UTC, Stanislav Blinov wrote: Looks cool, but it'd still want a GC closure, won't it? No, it just generates the same struct you'd write manually. That should work fine with @nogc now. auto create

Re: Value closures (no GC allocation)

2017-05-21 Thread Stanislav Blinov via Digitalmars-d
On Sunday, 21 May 2017 at 18:17:57 UTC, Adam D. Ruppe wrote: But, using the struct stuff, we can add some artificial sweetener now: return bar(lambda!(x, q{ (int y) => x + y })); You pass the captures first, then a q{} string literal of the lambda. Here's the implementation of that lambda

Re: Multiple template variadic list not working

2017-05-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 21 May 2017 at 15:13:55 UTC, bastien penavayre wrote: I've been trying to translate the following idea expressed here in c++: template void func(Arguments... args) {} so I tried void func(UserArgs..., Arguments...)(Arguments args) {} and then void func(Args...)(Filter!(isType,

Re: Why: error("multiple ! arguments are not allowed");

2017-05-21 Thread Stanislav Blinov via Digitalmars-d
On Sunday, 21 May 2017 at 13:42:50 UTC, Vladimir Panteleev wrote: On Sunday, 21 May 2017 at 13:08:18 UTC, Adam D. Ruppe wrote: foo!(x)!y I think it's the same as foo!x!y. As for the reason - I think because the order is possibly ambiguous or something? You could interpret it as either

Re: Why would an initialised struct pointer field be null in the struct's destructor?

2017-05-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 21 May 2017 at 12:48:10 UTC, Adam D. Ruppe wrote: On Saturday, 20 May 2017 at 10:48:54 UTC, Gary Willoughby wrote: // Why is this._foo null here??? The others have answered why and what to do, but note that according to the spec, that any struct should be able to

Re: Value closures (no GC allocation)

2017-05-20 Thread Stanislav Blinov via Digitalmars-d
On Sunday, 21 May 2017 at 00:43:58 UTC, Adam D. Ruppe wrote: What are your thoughts? Has something similar been proposed before? It has, and I actually don't hate it, but I also don't think it is necessary because of the `scope` storage class being one option and just manually writing out

Re: DIP 1008 Preliminary Review Round 1

2017-05-20 Thread Stanislav Blinov via Digitalmars-d
On Friday, 19 May 2017 at 15:45:28 UTC, Mike Parker wrote: Destroy! In catch blocks, e is regarded as scope so that it cannot escape the catch block. ... Code that needs to leak the thrown exception object can clone the object. There's a contradiction here. Generic cloning cannot be

Re: Why would an initialised struct pointer field be null in the struct's destructor?

2017-05-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 20 May 2017 at 10:48:54 UTC, Gary Willoughby wrote: In the following code, the `_foo` pointer (of the Foo struct) is null in the first call to the destructor. Why is this? I think it's got something to do with the foreach loop but I'm not sure. Any ideas? Oof. Dangerous stuff.

Re: how to disable inlining of ldc2 when 'dub build --build=release'?

2017-05-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote: so, what should i do to disable inlining of ldc2 in release build? As Stefan mentioned, a test case would be nice. But have you tried annotating the offending function with pragma(inline, false)?

Re: DIP 1008 Preliminary Review Round 1

2017-05-20 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 20 May 2017 at 03:54:43 UTC, Jonathan M Davis wrote: Because of the issue of lifetimes, some language features simply cannot be implemented without the GC, and I think don't see any point in trying to make it so that you can use all features of D without the GC. That simply won't

Re: DIP 1008 Preliminary Review Round 1

2017-05-20 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 20 May 2017 at 02:25:45 UTC, Walter Bright wrote: We'll be doing more invisible special casing in the future. For example, void foo(scope string s); ... string s; ... foo(s ~ "abc"); This array concatenation does not need to be done with the GC. It's not fundamentally

Re: DIP 1008 Preliminary Review Round 1

2017-05-19 Thread Stanislav Blinov via Digitalmars-d
On Friday, 19 May 2017 at 21:24:51 UTC, Adam D. Ruppe wrote: "NewExpressions are used to allocate memory on the garbage collected heap (default) or using a class or struct specific allocator. " "If a NewExpression is used as an initializer for a function local variable with scope storage

Re: DIP 1008 Preliminary Review Round 1

2017-05-19 Thread Stanislav Blinov via Digitalmars-d
On Friday, 19 May 2017 at 18:16:33 UTC, Jack Stouffer wrote: On Friday, 19 May 2017 at 15:45:28 UTC, Mike Parker wrote: ... Secondly, I'm not a fan of special casing syntax, especially when I don't think the given benefits outweigh the above listed costs... You're raising an extremely

Re: DIP 1008 Preliminary Review Round 1

2017-05-19 Thread Stanislav Blinov via Digitalmars-d
On Friday, 19 May 2017 at 18:10:50 UTC, H. S. Teoh wrote: On Fri, May 19, 2017 at 05:48:55PM +, Stanislav Blinov via Digitalmars-d wrote: On Friday, 19 May 2017 at 17:05:09 UTC, H. S. Teoh wrote: [...] > AFAIK, there is no way to clone classes, unless the class > writer imple

Re: DIP 1008 Preliminary Review Round 1

2017-05-19 Thread Stanislav Blinov via Digitalmars-d
On Friday, 19 May 2017 at 17:05:09 UTC, H. S. Teoh wrote: On Fri, May 19, 2017 at 05:13:34PM +0100, rikki cattermole via Digitalmars-d wrote: [...] "Code that needs to leak the thrown exception object can clone the object." Errors: ```D import std.stdio; void main() { auto e = new

Re: Fantastic exchange from DConf

2017-05-18 Thread Stanislav Blinov via Digitalmars-d
On Thursday, 18 May 2017 at 17:53:52 UTC, H. S. Teoh wrote: In the long run, I fear that if there are too many @trusted blocks in a given codebase (not necessarily Phobos), it will become too onerous to review, and could lead to hidden exploits that are overlooked by reviewers. I don't know

Re: [OT] Fast Deterministic Selection

2017-05-18 Thread Stanislav Blinov via Digitalmars-d-announce
On Thursday, 18 May 2017 at 15:14:17 UTC, Andrei Alexandrescu wrote: The implementation is an improved version of what we now have in the D standard library. I'll take up the task of updating phobos at a later time.

Re: On the subject of error messages

2017-05-16 Thread Stanislav Blinov via Digitalmars-d
On Tuesday, 16 May 2017 at 15:47:37 UTC, Steven Schveighoffer wrote: On 5/16/17 9:54 AM, Stanislav Blinov wrote: On Tuesday, 16 May 2017 at 12:27:30 UTC, Steven Schveighoffer wrote: When we have tests using dummy lambdas, are we to expect users to immediately extract the lambda body, parse

Re: On the subject of error messages

2017-05-16 Thread Stanislav Blinov via Digitalmars-d
On Tuesday, 16 May 2017 at 14:00:51 UTC, Nick Treleaven wrote: On Tuesday, 16 May 2017 at 11:20:57 UTC, Stanislav Blinov wrote: On Tuesday, 16 May 2017 at 09:04:32 UTC, Nick Treleaven wrote: The problem with this approach is all the work required to convert existing code to use this style

Re: On the subject of error messages

2017-05-16 Thread Stanislav Blinov via Digitalmars-d
On Tuesday, 16 May 2017 at 12:27:30 UTC, Steven Schveighoffer wrote: When we have tests using dummy lambdas, are we to expect users to immediately extract the lambda body, parse it, and figure out what's wrong? This is what you have to do today. The task has already been tried by the

Re: On the subject of error messages

2017-05-16 Thread Stanislav Blinov via Digitalmars-d
On Tuesday, 16 May 2017 at 09:04:32 UTC, Nick Treleaven wrote: ... foreach(i, T; types!args) { typeof(args) ;-) Thanks :) static if (is(T == string)) { pragma(msg, format!"Argument %d is a string, which is not supported" (i+1)); The problem

Re: How to move append to an array?

2017-05-15 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 16 May 2017 at 01:22:49 UTC, Yuxuan Shui wrote: Can I expand an array with uninitialized object? Or can I rely on the compiler to optimize the initialization away? Built-in arrays always default-initialize their elements. If you need something that unsafe, there's

Re: On the subject of error messages

2017-05-15 Thread Stanislav Blinov via Digitalmars-d
On Monday, 15 May 2017 at 20:55:35 UTC, Steven Schveighoffer wrote: On 5/15/17 4:24 PM, Stanislav Blinov wrote: On Monday, 15 May 2017 at 19:44:11 UTC, Steven Schveighoffer wrote: It has to know. It has to evaluate the boolean to see if it should compile! The current situation would be like

Re: How to move append to an array?

2017-05-15 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 15 May 2017 at 21:38:52 UTC, Yuxuan Shui wrote: Suppose I have a struct A { @disable this(this); } x; How do I append it into an array? Do I have to do array.length++; moveEmplace(x, array[$-1]); ? moveEmplace is for moving an initialized object into an uninitialized one.

Re: On the subject of error messages

2017-05-15 Thread Stanislav Blinov via Digitalmars-d
On Monday, 15 May 2017 at 19:44:11 UTC, Steven Schveighoffer wrote: On 5/15/17 1:16 PM, Stanislav Blinov wrote: On Monday, 15 May 2017 at 15:30:38 UTC, Steven Schveighoffer wrote: Argument 2 is a string, which is not supported file(line): Error: template foo cannot deduce function from

Re: On the subject of error messages

2017-05-15 Thread Stanislav Blinov via Digitalmars-d
On Monday, 15 May 2017 at 15:30:38 UTC, Steven Schveighoffer wrote: Imagine also a constraint like isInputRange!R. This basically attempts to compile a dummy lambda. How would one handle this in user-code? Let's look at something more practical than my initial example, even if less

Re: On the subject of error messages

2017-05-15 Thread Stanislav Blinov via Digitalmars-d
On Monday, 15 May 2017 at 15:30:38 UTC, Steven Schveighoffer wrote: Argument 2 is a string, which is not supported file(line): Error: template foo cannot deduce function from argument types !()(int, string), candidates are: file(line): foo(Args...)(auto ref Args arg) if (noStringArgs!args)

Re: Structure of Arrays vs Array of Structures

2017-05-15 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 15 May 2017 at 06:50:04 UTC, Nicholas Wilson wrote: On Monday, 15 May 2017 at 06:44:53 UTC, Nordlöw wrote: Have anybody done this already? Yes, https://maikklein.github.io/post/soa-d/ The code in that article is overly simplified. Concrete use cases would require more than

Re: On the subject of error messages

2017-05-15 Thread Stanislav Blinov via Digitalmars-d
Nobody read that or is it just *that* bad? :)

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:55:01 UTC, ag0aep6g wrote: On 05/14/2017 11:35 PM, Moritz Maxeiner wrote: On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote: [...] T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } [...] alias _state = ptrCast!(int, state); [...] That's

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Stanislav Blinov via Digitalmars-d-learn
On the point of "not possible...", "only a symbol...", etc: T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } void addInt(void* state, void* data) { alias _state = ptrCast!(int, state); alias _data = ptrCast!(int, data); static assert(!is(typeof(_state) == int*)); static

Re: Do array literals still always allocate?

2017-05-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 May 2017 at 18:32:16 UTC, Lewis wrote: import std.random; import std.stdio; int[4] testfunc(int num) @nogc { return [0, 1, num, 3]; } int main() { int[4] arr = testfunc(uniform(0, 15)); writeln(arr); return 0; } I've read a bunch of stuff that seems to indicate

Re: Move along, folks. Nothing to see here.

2017-05-13 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 13 May 2017 at 15:31:40 UTC, Fool wrote: I apologize for even thinking about the possibility that something could be wrong and might require a fix. Have a good time! A "discussion" 3 hours long, with 62.5% of posts in it being your own. One can understand how you'd give up

Re: Fixing opEquals and opCmp

2017-05-13 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 13 May 2017 at 15:00:27 UTC, Fool wrote: On Saturday, 13 May 2017 at 14:17:24 UTC, H. S. Teoh wrote: Andrei specifically stated before that opCmp may model a partial order, i.e., returning 0 may indicate "not comparable" rather than "equal". Well, that's unsound. Example: 'is

On the subject of error messages

2017-05-13 Thread Stanislav Blinov via Digitalmars-d
Let's suppose I wrote the following template function: import std.meta; enum bool isString(T) = is(T == string); void foo(Args...)(auto ref Args args) if (!anySatisfy!(isString, Args)) { // ... } This one is variadic, but it could as well have been non-variadic. The important aspect is

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 May 2017 at 08:50:20 UTC, k-five wrote: Way arguing when a simple code can clarify the subject? right? If am not clear so consider me as an stupid man, no problem at all. but CAN you please solve it for me? import std.stdio: writeln; import std.conv:to; void

Re: weird empty string

2017-05-12 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 13 May 2017 at 00:36:55 UTC, mogu wrote: ```d if (null) "1".writeln; if ("") "2".writeln; if ("" == null) "3".writeln; ``` Output: 2 3 How to understand this? Boolean conversion on an array works on array's pointer, not it's length. So even though `"".length == 0`,

Re: alias and UDAs

2017-05-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 May 2017 at 10:39:03 UTC, Andre Pany wrote: Hi, in this example, both asserts fails. Is my assumption right, that UDA on alias have no effect? If yes, I would like to see a compiler warning. But anyway, I do not understand why the second assertion fails. Are UDAs on arrays

Re: Error writing file a *.obj

2017-05-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 9 May 2017 at 14:08:48 UTC, bachmeier wrote: On Tuesday, 9 May 2017 at 02:33:06 UTC, dummy wrote: On Monday, 8 May 2017 at 12:29:27 UTC, bachmeier wrote: On Monday, 8 May 2017 at 11:56:10 UTC, dummy wrote: When i build some application with dub, i got this error: I'm not a Dub

Re: dmd: can't build on Arch Linux or latest Ubuntu

2017-05-10 Thread Stanislav Blinov via Digitalmars-d
On Wednesday, 10 May 2017 at 21:03:30 UTC, Marco Leise wrote: Am Wed, 10 May 2017 20:59:33 +0300 schrieb ketmar : > On Wednesday, 10 May 2017 at 11:51:03 UTC, Atila Neves wrote: >> I can't build dmd on Arch Linux anymore. I'm told it's >> because of a binutils update.

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 15:35:24 UTC, k-five wrote: On Wednesday, 10 May 2017 at 14:27:46 UTC, Stanislav Blinov wrote: On Wednesday, 10 May 2017 at 13:27:17 UTC, k-five wrote: Thanks, but I know about what are you saying. The user_apply[4] has so many possibilities and I cannot use

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 13:27:17 UTC, k-five wrote: Thanks, but I know about what are you saying. The user_apply[4] has so many possibilities and I cannot use if-else That doesn't sound right. Either you've already handled all the possible cases and thus expect the to! to not throw (can

Re: "I made a game using Rust"

2017-05-10 Thread Stanislav Blinov via Digitalmars-d
On Wednesday, 10 May 2017 at 12:52:34 UTC, JN wrote: Interesting thread I got from Reddit, someone made a game for PC and mobiles fully in Rust. https://michaelfairley.com/blog/i-made-a-game-in-rust/ "Last week, I released A Snake’s Tale on iOS, Android, Windows, Mac, and Linux.". I

Re: Scope checking on static array struct doesn't kick in

2017-05-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 9 May 2017 at 12:25:29 UTC, Nordlöw wrote: On Tuesday, 9 May 2017 at 11:52:35 UTC, Nordlöw wrote: I've tagged the ref-returning functions (in this case `opSlice`) with `return scope` for my statically allocated array struct at Here's a simpler example

Re: Converting a string[] to char**

2017-05-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 9 May 2017 at 07:50:33 UTC, David Zhang wrote: If indeed there is no way to avoid allocation, do the allocations have to remain 'alive' for the duration of the instance? Or can I deallocate immediately afterwards? I can't seem to find it in the Vulkan spec. 2.3.1. Object

Re: DCOnf 2017 videos online

2017-05-08 Thread Stanislav Blinov via Digitalmars-d-announce
On Monday, 8 May 2017 at 15:10:37 UTC, Jack Stouffer wrote: On Sunday, 7 May 2017 at 18:11:47 UTC, Patrick Schluter wrote: It looks like the good people of Sociomantic have already posted videos of the Dconf2017 on youtube. https://www.youtube.com/channel/UC54uUlXuGhigMsdaNtP6THQ Enjoy.

Re: Working code in an upcoming PR by Timon Gehr

2017-05-07 Thread Stanislav Blinov via Digitalmars-d-announce
On Sunday, 7 May 2017 at 16:57:58 UTC, Andrei Alexandrescu wrote: Zoom in on the screen for a nice surprise! http://imgur.com/a/qjI4l -- Andrei I see only unsurprising Jpeg artifacts and not much more :) It's too low resolution to make anything out.

Re: Looking for an equivalent to C++ std::getline in D

2017-05-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 7 May 2017 at 10:33:25 UTC, k-five wrote: On Sunday, 7 May 2017 at 09:46:22 UTC, Patrick Schluter wrote: On Saturday, 6 May 2017 at 10:15:03 UTC, k-five wrote: If you want to learn the basis of the range concept and their link to C++ Iterators, you should definitively read

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-05-07 Thread Stanislav Blinov via Digitalmars-d
On Sunday, 7 May 2017 at 11:46:33 UTC, Andrei Alexandrescu wrote: On 5/7/17 1:30 PM, Stanislav Blinov wrote: To follow this discussion up, and in light of yesterday's Collections presentation at DConf, I though I'd go ahead and make a basic implementation of traits-based IAllocator. You

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-05-07 Thread Stanislav Blinov via Digitalmars-d
On Monday, 1 May 2017 at 13:00:27 UTC, Andrei Alexandrescu wrote: On 05/01/2017 08:12 AM, Guillaume Piolat wrote: On Sunday, 30 April 2017 at 21:43:26 UTC, Andrei Alexandrescu wrote: A pass through the root allocators (Mallocator, GCAllocator etc) figuring out what attributes could be

Re: How to get field default value at CT

2017-05-06 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 6 May 2017 at 21:40:24 UTC, Mike B Johnson wrote: I'd like to get the value assign to a field at CT. struct { int x = 3434; } I'd like to get the assigned "value" 3434 for x at CT. Use the .init property: struct S { int x = 3434; } unittest { static

Thank You DConf 2017

2017-05-06 Thread Stanislav Blinov via Digitalmars-d
Fantastic three days of presentations. A big Thank You to all presenters, organizers and sponsors, and a special Thank You to the team that made the livestream possible, so even those of us who couldn't make it to Berlin could not only learn from the conference but actually participate. An

Re: Looking for an equivalent to C++ std::getline in D

2017-05-06 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 6 May 2017 at 10:15:03 UTC, k-five wrote: On Saturday, 6 May 2017 at 08:53:12 UTC, Jonathan M Davis wrote: On Saturday, May 6, 2017 8:34:11 AM CEST k-five via Digitalmars-d-learn wrote: On Friday, 5 May 2017 at 17:07:25 UTC, Stanislav Blinov wrote: > On Friday, 5 May 2017 at 09

Re: Looking for an equivalent to C++ std::getline in D

2017-05-06 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 6 May 2017 at 08:34:11 UTC, k-five wrote: Also what is the parameter "a.empty" for template filter Jonathan covered the type part. As for that last bit, the filter template takes a predicate as parameter. This predicate is called for each input element, and if returns false,

Re: Looking for an equivalent to C++ std::getline in D

2017-05-05 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 5 May 2017 at 09:54:03 UTC, k-five wrote: Hi all. I have a simple command-line program utility in C++ that can rename or remove files, based on regular expression. After finding D that is more fun than C++ is, I want to port the code, but I have problem with this part of it:

Re: Equivalent to nullptr

2017-05-03 Thread Stanislav Blinov via Digitalmars-d-learn
In the meantime, you can get around the issue by redeclaring the function with another name and loading it manually just after calling DerelictSDL2.load(): import derelict.sdl2.sdl; __gshared SDL_bool function (const(SDL_Point)*, int, const(SDL_Rect)*, SDL_Rect*) SDL_EnclosePoints_; void

Re: Equivalent to nullptr

2017-05-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 4 May 2017 at 03:59:36 UTC, Leonardo wrote: On Thursday, 4 May 2017 at 02:45:30 UTC, Adam D. Ruppe wrote: On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote: nullptr word. How I use this? Does it work if you just use `null` ? No. First I got: source/app.d(45,69): Error:

Re: The .obj file, what is it?

2017-05-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 10:55:44 UTC, I Lindström wrote: So, a question from a beginner. What is the .obj file that appears after the source is compiled into the executable? I can't find a good explanation on the Net for it. I take it the file has to accompany the executable for the

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-05-01 Thread Stanislav Blinov via Digitalmars-d
On Tuesday, 2 May 2017 at 02:51:02 UTC, Stanislav Blinov wrote: Lost one else. Should be static if (traits & (AllocatorTraits.sharedInstance | AllocatorTraits.noGC)) @nogc shared { mixin AllocatorInterface!(); } else static if (tr

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-05-01 Thread Stanislav Blinov via Digitalmars-d
On Monday, 1 May 2017 at 16:31:10 UTC, Nick Sabalausky (Abscissa) wrote: If we had a type similar to TaggedAlgebraic... Destroy? It's too strict: you have to specify concrete types beforehand. This spills over into user code and makes it far less versatile that can be achieved. Currently

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-05-01 Thread Stanislav Blinov via Digitalmars-d
On Monday, 1 May 2017 at 04:54:28 UTC, Andrei Alexandrescu wrote: On 4/30/17 8:43 PM, Stanislav Blinov wrote: On Sunday, 30 April 2017 at 21:43:26 UTC, Andrei Alexandrescu wrote: On 04/27/2017 07:35 PM, Stanislav Blinov wrote: IAllocator is too high level an interface, it doesn't carry any

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-04-30 Thread Stanislav Blinov via Digitalmars-d
On Monday, 1 May 2017 at 00:43:22 UTC, Stanislav Blinov wrote: block_ = allocator_.allocate(T.sizeof); Obviously, should be Block.sizeof, and AllocatorInterface!AllocTraits allocator_; should be AllocatorInterface!traits allocator_

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-04-30 Thread Stanislav Blinov via Digitalmars-d
On Sunday, 30 April 2017 at 21:43:26 UTC, Andrei Alexandrescu wrote: On 04/27/2017 07:35 PM, Stanislav Blinov wrote: IAllocator is too high level an interface, it doesn't carry any information as to what type of memory it can allocate (so we can only assume unshared), and does or does

Re: get parameters of a function

2017-04-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 29 April 2017 at 06:18:34 UTC, Alex wrote: The problem is another one: say I have something like this: import std.traits; struct A(alias T) if(isCallable!T) { auto opCall(U...)(U args) if(is(Parameters!T == U)) //if(__traits(compiles, T(args))) {

Re: get parameters of a function

2017-04-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 28 April 2017 at 20:43:50 UTC, Alex wrote: Hi all, I have a question about the Parameters trait from https://dlang.org/phobos/std_traits.html#Parameters The following code does not compile. Why? Is it mainly assumed to use it with functions without overloads? Rather, it is to be

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-04-27 Thread Stanislav Blinov via Digitalmars-d
On Thursday, 27 April 2017 at 23:12:48 UTC, Moritz Maxeiner wrote: On Thursday, 27 April 2017 at 20:04:32 UTC, Stanislav Blinov wrote: On Thursday, 27 April 2017 at 19:57:52 UTC, Andrei Alexandrescu wrote: https://github.com/dlang/phobos/pull/5355 Andrei And then we'd probably need

Re: Interesting PRs: bringing type system legitimacy to shared allocators

2017-04-27 Thread Stanislav Blinov via Digitalmars-d
On Thursday, 27 April 2017 at 19:57:52 UTC, Andrei Alexandrescu wrote: https://github.com/dlang/phobos/pull/5355 Andrei And then we'd probably need INoGCAllocator and ISharedNOGCAllocator...

Re: scoped classes

2017-04-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 27 April 2017 at 18:36:08 UTC, Alex wrote: * I'm pretty sure that the code is going to be invalid when you're dealing with const/immutable data. Ok... this is important... I tried this out, and the value of the immutable data even remains the same. But for safety reasons, I would

Re: scoped classes

2017-04-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 27 April 2017 at 17:07:05 UTC, Ali Çehreli wrote: I haven't used it yet but it's worth noting that there is EMSI's container library as well: http://code.dlang.org/packages/emsi_containers A brief glance at the source of dynamicarray there suggests that it won't help with

Re: scoped classes

2017-04-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 27 April 2017 at 15:47:38 UTC, Alex wrote: struct S { @disable this(); @disable this(this); this(size_t dummy){} } Given a struct with an explicit constructor and a postblit. How to make an array of it? You mean with a disabled default ctor and postblit?

Re: scoped classes

2017-04-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 27 April 2017 at 06:40:49 UTC, Alex wrote: Hi all, a short question about an example. having read this: https://dlang.org/library/std/typecons/scoped.html There is a struct B defined in the middle of the example, with a scoped class member. How to define an array of such members

Re: Move construction from !is(T == typeof(this))

2017-04-26 Thread Stanislav Blinov via Digitalmars-d
On Wednesday, 26 April 2017 at 13:38:59 UTC, Steven Schveighoffer wrote: ~this() { data.destroy(); } Don't do this. It's not a good idea, since data could be invalid at this point. In this case, destroy does nothing (it just sets the array to null), so I would just

Re: Move construction from !is(T == typeof(this))

2017-04-26 Thread Stanislav Blinov via Digitalmars-d
On Wednesday, 26 April 2017 at 02:19:03 UTC, Manu wrote: Right, yeah I see. So, basically, you admit that it is required to have 3 overloads; foo(X), foo(ref X) and foo(ref const X), in the event that I want to avoid needlessly copying X prior to constructing from it in the non-const case...

Re: Move construction from !is(T == typeof(this))

2017-04-25 Thread Stanislav Blinov via Digitalmars-d
On Tuesday, 25 April 2017 at 07:58:43 UTC, Jack Applegame wrote: On Monday, 24 April 2017 at 18:48:00 UTC, Stanislav Blinov wrote: Suddenly, we can't copy the pointer, or at least make a shallow copy of it, without violating const, and the latter is UB. Because transitive const/immutable

Re: Move construction from !is(T == typeof(this))

2017-04-24 Thread Stanislav Blinov via Digitalmars-d
On Tuesday, 25 April 2017 at 01:59:55 UTC, Manu wrote: Ah crap, I somehow missed the single-argument move() function. Okay, so this pattern is definitely reliable? I haven't seen it clearly documented anywhere that this is the prescribed pattern, and it's come up on stack overflow a few

Re: Move construction from !is(T == typeof(this))

2017-04-24 Thread Stanislav Blinov via Digitalmars-d
On Monday, 24 April 2017 at 22:46:18 UTC, Andrei Alexandrescu wrote: On 04/24/2017 04:23 PM, ag0aep6g wrote: On 04/24/2017 08:48 PM, Stanislav Blinov wrote: Speaking of const violation and UB, std.algorithm.mutation.move seems to violate const without remorse: Yup. Even in @safe code, which

Re: Move construction from !is(T == typeof(this))

2017-04-24 Thread Stanislav Blinov via Digitalmars-d
On Monday, 24 April 2017 at 15:19:29 UTC, Manu wrote: If you're going to pinch the guts of rvalue arguments, then this needs to be 100% reliable. This needs to be aggressively unit-tested, and probably documented that this is the official pattern for rvalue construction/assignment

Re: Move construction from !is(T == typeof(this))

2017-04-24 Thread Stanislav Blinov via Digitalmars-d
On Monday, 24 April 2017 at 04:21:36 UTC, Manu wrote: struct X {} struct Y { this(auto ref X x) { static if (__traits(isRef, x)) { // x is lvalue, copy construct } else { // x MUST be rvalue(?), move construct // does this pattern require that I

Re: using shared effectively in a producer/consumer situation.

2017-04-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 23 April 2017 at 20:33:48 UTC, Kevin Balbas wrote: I guess the follow up here is: Is this the correct way to do it? cast to shared, send to main thread, cast away shared? At the moment, pretty much yes. Either that or make the (unnecessary) immutable copies. There are no

Re: Get name of current function

2017-04-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 23 April 2017 at 20:34:12 UTC, Mike B Johnson wrote: I'd like to get the symbolic name of the current function I'm in void foo() { writeln(thisFunc.stringof()); // prints foo } I need something short, elegant and doesn't require modifying preexisting code... I'm sure D has

Re: Default-valued nothrow @nogc std.conv:to

2017-04-22 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 22 April 2017 at 12:16:19 UTC, Nordlöw wrote: On Saturday, 22 April 2017 at 12:14:26 UTC, Nordlöw wrote: If I get this to work, I'm gonna try pushing it into std.conv. Another bit to pick on is the return value. auto x = toWithDefault!int("1", 0.0f); typeof(x) will be float even

Re: Default-valued nothrow @nogc std.conv:to

2017-04-22 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 22 April 2017 at 18:26:56 UTC, Dmitry Olshansky wrote: On 4/22/17 6:57 PM, Stanislav Blinov wrote: On Saturday, 22 April 2017 at 16:41:00 UTC, Nordlöw wrote: If defaultValue is not lazy, it's potentially wasteful. What do you mean with "potentially wasteful"? Ex

Re: Default-valued nothrow @nogc std.conv:to

2017-04-22 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 22 April 2017 at 16:41:00 UTC, Nordlöw wrote: If defaultValue is not lazy, it's potentially wasteful. What do you mean with "potentially wasteful"? Excess calls to copy constructors? Evaluation of an expression the result of which might not be used. defaultValue could be

Re: Default-valued nothrow @nogc std.conv:to

2017-04-22 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 22 April 2017 at 12:16:19 UTC, Nordlöw wrote: On Saturday, 22 April 2017 at 12:14:26 UTC, Nordlöw wrote: Is there any way I can make it `@nogc` without having to modify the code in `std.conv`? If I get this to work, I'm gonna try pushing it into std.conv. If defaultValue is not

Re: Python : Pythonista / Ruby: Rubyist : / D : ?

2017-04-21 Thread Stanislav Blinov via Digitalmars-d
On Friday, 21 April 2017 at 18:16:55 UTC, Meta wrote: I prefer the term Deity. Talk about D'lusions of granD're ;)

Re: Can we disallow appending integer to string?

2017-04-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 20 April 2017 at 19:20:28 UTC, H. S. Teoh wrote: Another pernicious thing I encountered recently, related to implicit conversions, is this: https://issues.dlang.org/show_bug.cgi?id=17336 It drew a very enunciated "WAT?!" from me. Yeah, that one is annoying. I've dealt

Re: Exact arithmetic with quadratic irrationals

2017-04-19 Thread Stanislav Blinov via Digitalmars-d
Awesome! Congrats and thanks for sharing. On Wednesday, 19 April 2017 at 19:32:14 UTC, H. S. Teoh wrote: Haha, it seems that the only roadblocks were related to the implementation quality of std.numeric.gcd... nothing that a few relatively-simple PRs couldn't fix. So overall, D is still

Re: Can we disallow appending integer to string?

2017-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 18:40:23 UTC, H. S. Teoh wrote: A few extra keystrokes to type cast(int) or cast(char) ain't gonna kill nobody. In fact, it might even save a few people by preventing certain kinds of bugs. Yup. Not to mention one could have @property auto

Re: Can we disallow appending integer to string?

2017-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 17:34:01 UTC, Jonathan M Davis wrote: Personally, I think that we should have taken the stricter approach and not had integral types implicit convert to character types, but from what I recall, Walter feels pretty strongly about the conversion rules being the

Re: The app hanging after reach 1750MB of RAM

2017-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 07:28:32 UTC, Suliman wrote: 1. You're measuring it wrong. Array length is already measured in terms of type size. So should I do: cargpspoints.length * cargpspoints[0].sizeof ? No. .sizeof is the statically known size of a type, it can't take into account

Re: Immovable types

2017-04-19 Thread Stanislav Blinov via Digitalmars-d
On Wednesday, 19 April 2017 at 14:45:59 UTC, Meta wrote: On Wednesday, 19 April 2017 at 02:53:18 UTC, Stanislav Blinov wrote: Non-copyable and immovable types will have to be explicitly initialized, as if they had @disable this(), as they can't even be initialized with .init: It's

Re: Can we disallow appending integer to string?

2017-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 14:36:13 UTC, Nick Treleaven wrote: This bug is fixed as the code no longer segfaults but throws instead: https://issues.dlang.org/show_bug.cgi?id=5995 void main(){ string ret; int i = -1; ret ~= i; } Why is it legal to append an integer?

<    1   2   3   4   5   6   7   8   9   >