Re: version(StdDoc)

2018-11-24 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 25 November 2018 at 05:41:56 UTC, H. S. Teoh wrote: On Sat, Nov 24, 2018 at 05:48:16PM +, Stanislav Blinov via Digitalmars-d-learn wrote: Yup. UDAs did get in there eventually, and version should too. I think this would be a trivial DIP, by making it such that a version

Re: version(StdDoc)

2018-11-24 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 25 November 2018 at 07:19:50 UTC, Stanislav Blinov wrote: Granted, it may require some special syntax, i.e. enum E { a, b if version(Windows), c if version(Windows), d if version(Posix), } or something to that effect. Come to think of it, since UDAs are now allowe

Re: dip1000 rule 5

2018-11-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 25 November 2018 at 19:22:36 UTC, sclytrack wrote: There are 4 rules listed. ... What is rule 5? ... Wouldn't you call it D3 because of the name mangling of DIP1000 once activated by default? That "rule 5" looks like a straight up mistake. As for D3... IMHO, no, not by a long shot.

Re: Convert multibyte `string` to `dstring`

2018-11-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 25 November 2018 at 21:23:31 UTC, Vladimirs Nordholm wrote: Is there a proper way to convert a string with multibyte characters into a dstring? void main() { import std.conv : to; import std.stdio : writeln; string a = "abc😃123"; auto b = to!dstring(a); asse

Re: dip1000 rule 5

2018-11-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 25 November 2018 at 21:22:09 UTC, sclytrack wrote: Did DIP1000 go through any review process? I'm seeing it is a draft. Review links are at the very end. https://github.com/dlang/DIPs/blob/master/PROCEDURE.md Keeps talking about a Drafts subdirectory. I don't see any directory n

Re: version(StdDoc)

2018-11-25 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 25 November 2018 at 21:38:43 UTC, H. S. Teoh wrote: Actually, I just thought of a way to do this with the existing language: use a struct to simulate an enum: struct E { alias Basetype = int; Basetype impl; alias impl this;

Re: int[] as constructor

2018-12-05 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 4 December 2018 at 23:28:42 UTC, H. S. Teoh wrote: Well OK, for int[] it's kinda silly 'cos that's the default, but in my code I've often had to write things like: auto z = cast(float[]) [ 1.0, 2.0, 3.0 ]; Err, auto z = [ 1.0f, 2, 3 ]; ?

Re: How to get a function name (string) @ compile time

2018-12-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 9 December 2018 at 03:29:27 UTC, Andrew Pennebaker wrote: Er, when I try to use either foo.stringof, or __trait(identifier, foo), I always get that binding name, rather than the original function name, sad panda. I can only print out the current variable name, but I want to print

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 13 December 2018 at 13:17:05 UTC, aliak wrote: Ah. Is there any case where you would not want to do that when you have a T value as parameter? Hypothetically, yes, e.g. an object that contains references to itself. However, D operates on the assumption that you don't have such o

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-16 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 16 December 2018 at 04:02:57 UTC, Q. Schroll wrote: On Thursday, 13 December 2018 at 23:33:39 UTC, Stanislav Blinov wrote: On Thursday, 13 December 2018 at 13:17:05 UTC, aliak wrote: Ah. Is there any case where you would not want to do that when you have a T value as parameter? Hy

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 ar

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 doe

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 overwritt

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 std.co

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. Thi

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

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

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 wa

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 numeric(Flag!"unsigne

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

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 ownersh

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

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

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-28 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 use

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

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

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 m

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 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, the

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

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 assert(S.init.x

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 Andrei's

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 Lifetim

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 https://github.com/nordlow/p

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

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 u

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 n

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 ma

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

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 prett

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 just

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. Use

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 std.array.uninit

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)? http://dlang.org/spec/pragma.html#in

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. As

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 ha

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, A

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 destr

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, i.

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 use

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: https://github.com/nordlow/phobos-next/blob/a324f16515bd1c3c1185ba0482dae2886d811bb1/src/soa.

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 https://dpast

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 Wo

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; } wh

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()` become

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 the

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 t

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: 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: "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: difference between x = Nullable.init and x.nullify

2017-06-02 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: 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&#

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 live

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 s

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

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/ https://dpaste.dzfl

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

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 that

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: http://dlang.org/phob

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 fro

Re: byLine(n)?

2017-06-10 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; }

<    1   2   3