Re: recursive definition error

2014-07-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 4 July 2014 at 16:28:48 UTC, Frustrated wrote: On Friday, 4 July 2014 at 15:42:36 UTC, bearophile wrote: Frustrated: I'm not using 2.066 though... I will revert back to the dmd version I was using when it worked... Hopefully someone can make sure this is not a regression in the

Re: Use of "T"

2017-04-12 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 12 April 2017 at 22:56:25 UTC, solidstate1991 wrote: I know the existence of those and I'm frequently using them, however I need a two-way one. (Might be using two hash-tables instead if I can't find a better solution) So, you're looking for a generic way to store objects of

Re: Can't pass data from filter to each

2017-04-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 17 April 2017 at 10:02:22 UTC, Suliman wrote: New question. Can I put result of filtering in itself without creation of new variables like x: auto x = MySQLTablesRange.array.filter!(a=>a[0].coerce!string.canFind("_")); No. filter is simply a wrapper around the source range, it

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?

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: 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: 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: Cleaning up Dub/Dmd builds

2017-04-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 15:07:27 UTC, WhatMeWorry wrote: When I try to upload these files to my new repo, GitHub (rightfully so) complains that I have too many files. Since I'm using sdl and not json, can I safely delete all the files that pertain to json? Can I do this some way at the

Re: The app hanging after reach 1750MB of RAM

2017-04-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 13:28:57 UTC, Suliman wrote: Also I can't understand why app take so much memory? I checked array of structures size with this code: auto mymem = cargpspoints.length * typeof(cargpspoints[0]).sizeof; writeln(mymem); And it's print: 16963440 it's about 16MB...

Re: The app hanging after reach 1750MB of RAM

2017-04-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 14:09:28 UTC, Stanislav Blinov wrote: foreach(row; result) { arr ~= row.toStruct(cargpspoint); } Sorry, this should be foreach(row; result) { row.toStruct(cargpspoint); arr ~= cargpspoint; }

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 13:28:06 UTC, Solomon E wrote: I tried to produce an example of calling a function with variadic template arguments using special tokens __FILE__ and __LINE__. This compiles and runs, producing the output shown, using the default gdc provided by Ubuntu 17.04.

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: 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: refRange with non copyable struct

2017-04-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 17 April 2017 at 19:00:44 UTC, Jonathan M Davis wrote: Because otherwise, it's not acting like a reference to the original range, which is the whole point of RefRange. The correct solution would probably be to @disable opAssign in the case where the original range can't be

Re: if auto and method call

2017-04-17 Thread Stanislav Blinov via Digitalmars-d-learn
Would be prettier as a language feature, but still: template test(alias pred) { import std.functional : unaryFun; alias P = unaryFun!pred; auto test(R)(R r) { struct Test { R v; string toString() { import

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: 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 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 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: 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: 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: 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: 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: 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 a

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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

Re: "if" is not evaluated for fields of Class.tupleof

2017-05-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 06:42:55 UTC, Timoses wrote: The easiest way is probably casting: ``` import std.traits; import std.bitmanip; class Test { byte[4] marray; byte mbyte; } void main() { auto value = [0x12, 0x23, 0x34, 0x45, 0x56]; auto test = cast(Test*) value.ptr; }

Re: templatized delegate

2017-05-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 10:42:54 UTC, Nicholas Wilson wrote: On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate,

Re: Structure of Arrays vs Array of Structures

2017-05-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 16:48:31 UTC, Nordlöw wrote: On Tuesday, 23 May 2017 at 16:46:18 UTC, Nordlöw wrote: http://forum.dlang.org/post/wvulryummkqtskiwr...@forum.dlang.org Correction; should be:

Re: templatized delegate

2017-05-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 11:45:13 UTC, Alex wrote: On Tuesday, 23 May 2017 at 11:05:09 UTC, Stanislav Blinov wrote: void variadic(Args...)(auto ref Args args) { /* ... */ } This infers whether you pass lvalues or rvalues. If passing further down the chain of such calls is needed, one can

Re: The syntax of sort and templates

2017-05-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 26 May 2017 at 11:27:19 UTC, zakk wrote: I have a followup question: my background is C and in Wolfram Mathematica, so my knowledge of templates is limited to trivial examples in C++, like: template const T& min(const T& lhs, const T& rhs) { return lhs < rhs ? lhs : rhs; }

Re: The syntax of sort and templates

2017-05-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 26 May 2017 at 09:59:26 UTC, zakk wrote: Hello everyone, I just started using D and I am a bit puzzled by the syntax of the sort function is std.algorithm.sorting, which is sort!(comparingFunction)(list) where comparingFunction is often a lambda expression. For instance in the

Re: Out of memory error (even when using destroy())

2017-05-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 26 May 2017 at 18:06:42 UTC, Mike B Johnson wrote: On Friday, 26 May 2017 at 14:05:34 UTC, ag0aep6g wrote: On 05/26/2017 10:15 AM, realhet wrote: But hey, the GC knows that is should not search for any pointers in those large blocks. And the buffer is full of 0-s at the start, so

Re: Extern C and Symbol Mangling

2017-05-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 26 May 2017 at 12:49:27 UTC, Oleksii wrote: Hi, I'm trying to link against a DLL which exports a bunch of C functions. The issue is: C symbols do not have underscore prefix in Windows, but DMD sticks underscore in front of the symbol name. For example: `extern(C) void Foo()`

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: 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: Default class template parameter

2017-05-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 27 May 2017 at 19:23:59 UTC, Igor Shirkalin wrote: Hi, I try to make a class template with single template argument defaulted to some type. Is it possible to use the name of class without specification of template argumet (no '!' operator)? Example: class ClassName(T=double) {

Re: Out of memory error (even when using destroy())

2017-05-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 27 May 2017 at 17:57:03 UTC, Mike B Johnson wrote: And what if one isn't interfacing to C? All pointers should be known. You can't access memory by and int or any other non-pointer type! Hence, when pointers are created or ints are cast to pointers, the GC should be informed and

Re: RAII pointers

2017-05-29 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 May 2017 at 23:39:17 UTC, Russel Winder wrote: C++ allows one to create types that are pointer types but wrap a primitive pointer to give RAII handling of resources. For example: class Dvb::FrontendParameters_Ptr { private: dvb_v5_fe_parms * ptr; public:

Re: howto count lines - fast

2017-05-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 23:41:01 UTC, H. S. Teoh wrote: This little challenge piqued my interest. So I decided to take a shot at seeing if I could beat my system's /usr/bin/wc -l. First order of business: whenever it comes to performance, always choose the right compiler for the job...

Re: difference between x = Nullable.init and x.nullify

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 08:01:14 UTC, Jonathan M Davis wrote: On Saturday, June 03, 2017 06:41:44 Stanislav Blinov via Digitalmars-d-learn wrote: On Saturday, 3 June 2017 at 06:19:29 UTC, Jonathan M Davis wrote: > looking at what rt_finalize does, I don't see why it > couldn't be n

Re: difference between x = Nullable.init and x.nullify

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 06:19:29 UTC, Jonathan M Davis wrote: looking at what rt_finalize does, I don't see why it couldn't be nothrow. So, unless I'm missing something, it seems like that would be a good enhancement. - Jonathan M Davis Presently, rt_finalize cannot be made nothrow, or

Re: string to wchar*?

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 23:36:18 UTC, Mike B Johnson wrote: https://dlang.org/phobos/std_utf.html#toUTF16z This didn't work. More errors than the first. Works for me: void main() { import std.conv; import std.stdio; import core.stdc.wchar_; import core.stdc.stdio;

Re: RAII pointers

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 19:55:30 UTC, ag0aep6g wrote: On 06/03/2017 09:37 PM, Moritz Maxeiner wrote: Of course, but AFAIK you'd need to explicitly assign it to an object, so `ptr` won't null by accident, but only by explicit programmer intent (same as overwriting the memory the object

Re: RAII pointers

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 21:39:54 UTC, Moritz Maxeiner wrote: On Saturday, 3 June 2017 at 21:16:08 UTC, Stanislav Blinov wrote: On Saturday, 3 June 2017 at 20:53:05 UTC, Moritz Maxeiner wrote: Quite, but if you backtrack to my initial statement, it was about ptr not being/becoming null

Re: string to wchar*?

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 22:54:22 UTC, Mike B Johnson wrote: How to convert a string to wchar*? C-style null-terminated wchar*? https://dlang.org/phobos/std_utf.html#toUTF16z

Re: RAII pointers

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 20:53:05 UTC, Moritz Maxeiner wrote: On Saturday, 3 June 2017 at 20:25:22 UTC, Stanislav Blinov wrote: On Saturday, 3 June 2017 at 20:13:30 UTC, Moritz Maxeiner wrote: Calling std.algorithm.move is explicit programmer intent, I consider that about as accidental as

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 22:38:31 UTC, Mark wrote: In the future I'll include a compilable example. I was having problems with a class I made which is about 45 lines, that might be a lot of code for a post. You can use external resources such as: https://d.godbolt.org/

Re: difference between x = Nullable.init and x.nullify

2017-06-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 4 June 2017 at 09:04:14 UTC, Jonathan M Davis wrote: if throwing in a destructor is considered a runtime error, perhaps another valid enhancement would be to statically disallow throwing Exceptions in destructors, i.e. *require* them be nothrow?.. My initial reaction would be

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa;

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis wrote: Oh I see, the was error related to iteration, not sorting. Ranges do not support iterating with an index. The workaround if you want to have an index with ranges and foreach, then you should use lockstep:

Re: "Lazy" initialization of structs

2017-06-01 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 1 June 2017 at 12:04:05 UTC, Daniel Tan Fook Hao wrote: Somehow this code works for me: ```D auto error (int status, string description){ struct Error { int status; string description; } Error err = { status, description }; return

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 04:07:22 UTC, Andrew Edwards wrote: On Thursday, 8 June 2017 at 03:40:08 UTC, Jonathan M Davis sort() returns a SortedRange so that other algorithms can know... Yes, I understand that. Again, using "std.range: release" earns me nothing more than I already get

Re: RAII pointers

2017-06-03 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 3 June 2017 at 20:13:30 UTC, Moritz Maxeiner wrote: Calling std.algorithm.move is explicit programmer intent, I consider that about as accidental as calling memcpy with a source full of zeroes. In any case, having that check in the destructor is fairly cheap, so better safe than

Re: byLine(n)?

2017-06-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 11 June 2017 at 05:36:08 UTC, helxi wrote: I was writing a program that reads and prints the first nth lines to the stdout: import std.stdio; void main(string[] args) { import std.algorithm, std.range; import std.conv; stdin.byLine.take(args[1].to!ulong).each!writeln; }

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: 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: 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: 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

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: 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

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: site examples

2017-05-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 25 May 2017 at 15:41:47 UTC, crimaniak wrote: It seems to me that examples on the site require additional work and in the current form are counterproductive in terms of attracting new users. https://github.com/dlang/phobos

Re: Searching strings with indexOf vs countUntil

2017-05-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 25 May 2017 at 18:13:15 UTC, Anonymouse wrote: Part of the strings I'm working with can be assumed to be only ASCII, yes. indexOf only wants strings or char[]s, but interestingly if I use the same benchmark but have countUntil work on raw ubyte[]s, it is faster. See

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: 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 to be

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 the

Re: Details on how aggregates are constructed with `new` and later destroyed by the GC

2018-10-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 8 October 2018 at 11:19:40 UTC, Per Nordlöw wrote: And how this is related to the trait `hasElaborateConstructor` for both `classes` and `structs`. There's no such trait as far as I'm aware. If there were, it'd likely be checking for the presence of a '__ctor' member. Thing is, it

Re: LDC2 -I option results in unresolved externals

2018-10-12 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 12 October 2018 at 07:32:26 UTC, Mike Parker wrote: DMD has the -i option which tells the compiler to automatically compile all imported modules. I don't know if LDC has anything similar. It does, same option.

Re: ported a sortable list from my old C code

2018-10-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 October 2018 at 11:11:41 UTC, Codifies wrote: Does anyone has any ideas on improving this sortable list Yes. Use an array. No, really, use an array. Now, really, use an array. If reallocations while building your paths become a problem, you can write a deque (bucket array)

Re: Why is dynamic array length required here?

2018-10-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 19 October 2018 at 02:04:37 UTC, Samir wrote: I am working my way through the exercises in the "Programming in D" tutorial (http://ddili.org/ders/d.en/arrays.html). Why is the line assigning the length of the dynamic array required? [...] Without the line: myArray.length =

Re: need help about get all public static function name

2018-10-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 October 2018 at 11:42:59 UTC, test wrote: some how when I call "is(typeof(__traits(getMember, BaseType, name))) " in the template, my code report others error like: Error: no property fromPointer for type void Error: template instance TypeTemplate!(BaseType) is used as a type

Re: need help about get all public static function name

2018-10-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 October 2018 at 10:16:22 UTC, test wrote: I try use traits get all public static function of a struct pass to template... how to do this ? void allFunctions(T)() { import std.stdio; foreach (name; __traits(allMembers, T)) { static foreach (overload;

Re: need help about get all public static function name

2018-10-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 October 2018 at 10:49:10 UTC, test wrote: test1.d = alias Fn1 = void function(); struct XX { alias Fn= Fn1; // ... } 'Fn' is not a static function, it's a type. I.e. you can declare a function pointer with it: Fn func;

Re: need help about get all public static function name

2018-10-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 October 2018 at 12:03:22 UTC, test wrote: On Monday, 22 October 2018 at 11:59:21 UTC, test wrote: On Monday, 22 October 2018 at 11:42:59 UTC, test wrote: I try made a simple example but it has no error: I find the way to show the error: https://run.dlang.io/is/f8cULz import

Re: custom sorting of lists ?

2018-10-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 19 October 2018 at 17:40:59 UTC, Carl Sturtivant wrote: If we imagine an Ordered Range being a finite Range of some kind with the additional property that its values are ordered (--- exact definition needed ---)... There's already a SortedRange:

Re: Can Scope Be Used for Anonymous Objects?

2018-10-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 20:53:02 UTC, Vijay Nayar wrote: This particular use of "scope" I overheard at the last DConf, and I believe it has been added to the official documentation here: https://dlang.org/spec/expression.html#new_expressions If a NewExpression is used as an

Re: Access program args outside of main

2018-10-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 22:30:31 UTC, Jordan Wilson wrote: Ideally, I'd check args before I take the time to load up data. https://dlang.org/phobos/core_runtime.html#.Runtime

Re: Can Scope Be Used for Anonymous Objects?

2018-10-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 20:24:56 UTC, Vijay Nayar wrote: I have a snippet of code like this: scope chordAngle = new S1ChordAngle(_center, other._center); return _radius + other._radius >= chordAngle; The reason the "scope" temporary variable exists is to avoid a heap

Re: how to get UDA only for methods

2018-10-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 02:54:26 UTC, test wrote: I need get the Route UDA only for method without (static methods, property, constructor, destructor), dont know how to do it. 1) Note that __traits(allMembers, T) gets you a tuple of names, not actual member aliases. 2) Remember

Re: Error: non-shared method core.sync.condition.Condition.notify is not callable using a shared object

2018-10-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 18 October 2018 at 10:50:18 UTC, Paolo Invernizzi wrote: There's a rational behind the fact that there's not a 'shared' version of notify/wait method in Condition? They were implemented before complete `shared` spec existed, which is any time between it's conception and now.

Re: Dealing with ranges where front and popFront do the same logic / eager ranges

2018-10-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 09:53:22 UTC, Dukc wrote: Whatever iterates through the range could then throw an appopriate exception when it encounters an error token. Exceptions in a parser? Monsieur knows his perversion.

Re: When does GC run?

2018-10-16 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 16 October 2018 at 09:38:44 UTC, John Burton wrote: The information I have found indicates that it runs to free memory when the system runs out of memory to allocate. No, that is incorrect. By default, here's what's happening: 1) At startup (or first 'new' or GC.malloc) the GC

Re: Who can stop it ? Help me,thank you.

2018-10-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 13:48:04 UTC, FrankLike wrote: What can I do? Delete the bloatware that you downloaded.

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:01:21 UTC, DanielG wrote: In my D app I'm declaring it this way: extern (C) { extern __gshared int myIntValue; int myIntFunc (int a, int b); } The function seems to link OK, but the C global will not. Should it be extern(Windows),

Re: how to make '==' safe for classes?

2018-10-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 28 October 2018 at 12:38:12 UTC, ikod wrote: and object.opEquals(a,b) do not inherits safety from class C properties, and also I can't override it. Yep. Since Object is the base class and it defines opEquals as: ``` bool opEquals(Object); ``` the compiler rewrites `a == b` as

Re: expanding variadic into format

2018-10-31 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 31 October 2018 at 12:13:57 UTC, Codifies wrote: On Wednesday, 31 October 2018 at 12:09:04 UTC, Stanislav Blinov wrote: ``` void printValue(Args...)(Font fnt, float x, float y, string frmt, auto ref Args args) { // ... import std.functional : forward; string

  1   2   3   >