How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
I want to return values of the template parameter type, so there doesn't seem to be any way to dup or idup them.  I don't want the returned values to be able to be used to modify the values held in the table.  const out is an illegal parameter type.  dup doesn't work on ints. So I tried to ret

Re: How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
On 1/2/23 15:14, Paul Backus via Digitalmars-d-learn wrote: On Monday, 2 January 2023 at 22:53:13 UTC, Charles Hixson wrote: I want to return values of the template parameter type, so there doesn't seem to be any way to dup or idup them. It's hard to say where exactly you're going wrong if y

Re: How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
On 1/2/23 15:14, Paul Backus via Digitalmars-d-learn wrote: On Monday, 2 January 2023 at 22:53:13 UTC, Charles Hixson wrote: I want to return values of the template parameter type, so there doesn't seem to be any way to dup or idup them. It's hard to say where exactly you're going wrong if y

Re: How should I return multiple const values from a function?

2023-01-02 Thread Charles Hixson via Digitalmars-d-learn
On 1/2/23 17:56, Paul Backus via Digitalmars-d-learn wrote: return Tuple!(const(Key), const(Value))(k, v); Great!  OK, now the code is:     auto    findFirst ()     {    if    (root is null)    {    Key k    =    Key.init;        Val v    =    Val.init;        return Tuple!(co

template parameters

2021-08-29 Thread Charles Hixson via Digitalmars-d-learn
I've set up a class template (so far untested) thus: class    AARL (T, ndx = "ndx")         if (isIntegral(T.init.ndx) ) If I'm correct, this should work for ndx an integer variable of T, but I'd really like T to be able to be anything which can be stored both in an array and in an associative

Re: template parameters

2021-08-29 Thread Charles Hixson via Digitalmars-d-learn
Thanks.  I going to have to study: enum supportsCall = isIntegral!(typeof(T.init.%s())); for awhile to make any sense of that, but it looks like just what I was looking for. On 8/29/21 2:41 PM, Ali Çehreli via Digitalmars-d-learn wrote: On 8/29/21 11:32 AM, Charles H. wrote: I've set up a

Re: template parameters

2021-09-02 Thread Charles Hixson via Digitalmars-d-learn
Thanks.  See below for what I did. On 8/29/21 5:05 PM, Ali Çehreli via Digitalmars-d-learn wrote: On 8/29/21 3:31 PM, Charles Hixson wrote: > Thanks.  I going to have to study: > > enum supportsCall = isIntegral!(typeof(T.init.%s())); > > > for awhile to make any sense of that, but it looks like

Re: template parameters :: fix

2021-09-03 Thread Charles Hixson via Digitalmars-d-learn
change:             {    rl.remove(i); to:            {    rl  =  rl.remove(i); -- Javascript is what you use to allow third party programs you don't know anything about and doing you know not what to run on your computer.

Unexpected path of execution

2021-10-19 Thread Charles Hixson via Digitalmars-d-learn
given this code fragment:             if    (i < (line.length - 3) )             {    writeln ("in c4: i = ", i, ", line.length = ", line.length);                   add2 (c4, line [i..i+4]); I get this result: in c4: i = 0, line.length = 2 core.exception.RangeError@source/freqs.d(32): Range vi

Re: Unexpected path of execution

2021-10-19 Thread Charles Hixson via Digitalmars-d-learn
Thank you.  That seems to have solved the problem (bar additional testing).  And also thanks for your recommendation to add to the index rather than casting the length.  It wasn't as "nice" to my eyes at first, but it's a cleaner answer. On 10/19/21 9:38 AM, Adam D Ruppe via Digitalmars-d-lear

std.uni general character category

2015-10-20 Thread Charles Hixson via Digitalmars-d-learn
In std.uni (D Lib 2.068.2) I can no longer see how to get the general category code for a character. Does anyone know what the currently supported way to do that is?

Re: std.uni general character category

2015-10-21 Thread Charles Hixson via Digitalmars-d-learn
On 10/20/2015 10:38 AM, Charles Hixson via Digitalmars-d-learn wrote: In std.uni (D Lib 2.068.2) I can no longer see how to get the general category code for a character. Does anyone know what the currently supported way to do that is? I thought I remembered that I used to be able to

error detected at """ ch in unicode.C """ Library error?

2015-10-21 Thread Charles Hixson via Digitalmars-d-learn
To me this looks like a library error, but I'm not sure. Any suggestions importstd.uni; chargcCat1(dchar ch) { if(ch in unicode.L)return'L';//Letter if(ch in unicode.M)return'M';//Mask if(ch in unicode.C)ret

Re: error detected at """ ch in unicode.C """ Library error?

2015-10-22 Thread Charles Hixson via Digitalmars-d-learn
On 10/21/2015 06:21 PM, Charles Hixson via Digitalmars-d-learn wrote: To me this looks like a library error, but I'm not sure. Any suggestions importstd.uni; chargcCat1(dchar ch) { if(ch in unicode.L)return'L';// Letter if(

Re: error detected at """ ch in unicode.C """ Library error?

2015-10-23 Thread Charles Hixson via Digitalmars-d-learn
On 10/23/2015 04:33 AM, rumbu via Digitalmars-d-learn wrote: My opinion is to use the Tango's unicodedata.d module to obtain the unicode category, std.uni does not provide such functionality. This module does not have any dependency, therefore you can just use it directly: https://github.c

is increment on shared ulong atomic operation?

2016-02-07 Thread Charles Hixson via Digitalmars-d-learn
If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems as if it ought to be, but it could be split into read, increment, store. I started off defining a shared struct, but that seems silly, as if the operations defined within a shared

Re: is increment on shared ulong atomic operation?

2016-02-07 Thread Charles Hixson via Digitalmars-d-learn
Thanks, that's what I needed to know. I'm still going to do it as a class, but now only the inc routine needs to be handled specially. (The class is so that other places where the value is used don't even need to know that it's special. And so that instances are easy to share between threads.

rawWrite of a struct suggestions

2016-03-25 Thread Charles Hixson via Digitalmars-d-learn
I've got a simple struct: structChnk { ulongid; char[20]wrd; ubytelength; ...<--various utility functions and constructors } That I'm trying to write to a file. I want to use an unformatted read/write because I want this to be a random access file. But

Re: rawWrite of a struct suggestions

2016-03-25 Thread Charles Hixson via Digitalmars-d-learn
On 03/25/2016 11:32 AM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Friday, 25 March 2016 at 18:25:28 UTC, Charles Hixson wrote: But when I try to cast a Chnk to a ubyte[], I get an error, and rawWrite takes a generic array of anything... you should be able to rawWrite((&your_object)[0 .

Re: rawWrite of a struct suggestions

2016-03-26 Thread Charles Hixson via Digitalmars-d-learn
OK, after removing a few bugs, preliminary checks say that this works perfectly. Thanks again, as I never would have even considered that approach. On 03/25/2016 12:24 PM, Charles Hixson via Digitalmars-d-learn wrote: On 03/25/2016 11:32 AM, Adam D. Ruppe via Digitalmars-d-learn wrote: On

unicode confusion

2016-04-04 Thread Charles Hixson via Digitalmars-d-learn
Well, at least I think that it's unicode confusion. When a store values into a string (in an array of structs) and then compare it against itself, it compares fine, and if I write it out at that point it writes out fine. And validate says it's good unicode. But later... valid = true, len = 1

Re: unicode confusion--An answer

2016-04-04 Thread Charles Hixson via Digitalmars-d-learn
I was writing my output to two different files. Only one of them was set to utf-8, the other must have been some other encoding, because when I set the encoding to utf-8 everything cleared up. On 04/04/2016 04:04 PM, Charles Hixson via Digitalmars-d-learn wrote: Well, at least I think that

Re: Decompressing bzip2

2016-04-05 Thread Charles Hixson via Digitalmars-d-learn
On 04/04/2016 04:38 PM, Mike Parker via Digitalmars-d-learn wrote: On Monday, 4 April 2016 at 21:32:10 UTC, stunaep wrote: Can you please explain what the scope keyword does and if there scope was originally intended to be used primarily with classes in order to get deterministic destructi

Re: Decompressing bzip2

2016-04-05 Thread Charles Hixson via Digitalmars-d-learn
On 04/05/2016 03:33 PM, Mike Parker via Digitalmars-d-learn wrote: On Tuesday, 5 April 2016 at 19:27:20 UTC, Charles Hixson wrote: ... Are you asserting that scope is soon to be officially deprecated? I'm finding "shouldn't really be used at all anymore" a bit of a worrying statement, as I

More binary I/O problems

2016-04-08 Thread Charles Hixson via Digitalmars-d-learn
On 03/25/2016 11:32 AM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Friday, 25 March 2016 at 18:25:28 UTC, Charles Hixson wrote: But when I try to cast a Chnk to a ubyte[], I get an error, and rawWrite takes a generic array of anything... you should be able to rawWrite((&your_object)[0 .

Re: More binary I/O problems

2016-04-08 Thread Charles Hixson via Digitalmars-d-learn
On 04/08/2016 07:42 PM, Basile B. via Digitalmars-d-learn wrote: On Friday, 8 April 2016 at 20:58:06 UTC, Charles Hixson wrote: [...] And that worked, but suddenly (after a compiler upgrade, did that matter? I'd also changed the program, though in ways that shouldn't have affected this.) it

Re: More binary I/O problems

2016-04-09 Thread Charles Hixson via Digitalmars-d-learn
On 04/08/2016 09:25 PM, Basile B. via Digitalmars-d-learn wrote: On Saturday, 9 April 2016 at 03:15:58 UTC, Charles Hixson wrote: On 04/08/2016 07:42 PM, Basile B. via Digitalmars-d-learn wrote: On Friday, 8 April 2016 at 20:58:06 UTC, Charles Hixson wrote: [...] And that worked, but sudde

stdout.flush

2016-05-25 Thread Charles Hixson via Digitalmars-d-learn
Using: dmd --version DMD64 D Compiler v2.071.0 on debian Linux, and importing: importstd.stdio; the line: flush(); causes: nt.d(29): Error: undefined identifier 'flush', did you mean function 'fflush'? This appears solved by doing stdout.flush; (compiles, but I'm still writing the c

How to get current time as long or ulong?

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn
I've been reading std.datetime documentation backwards and forwards, but if the information is there, I've been missing it. How do I get the current time as a long? Clock.currTime() returns a SysTime, and while currently I can convert that to a long, this is because I looked into the code. Wha

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

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn
On 07/05/2016 11:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tuesday, July 05, 2016 11:16:31 Charles Hixson via Digitalmars-d-learn wrote: What I'm looking for is the opposite of the "FromUnixTime" function. SysTime has toUnixTime, which is right above from

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

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn
I guess I was expressing myself poorly, probably due to muddled thinking about the representation of time. Based on various hints from you and others my current guess is that I should use: longnow() { returnClock.currTime().stdTime;} IIUC this should return the current system clo

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

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn
e different entities is going to be important. For the second use I could use a much lower precision timer, but that would mean using two separate times for each item. On 07/05/2016 05:10 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tuesday, July 05, 2016 16:18:19 Charles Hixson via

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

2016-07-06 Thread Charles Hixson via Digitalmars-d-learn
On 07/05/2016 05:23 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tuesday, July 05, 2016 12:51:54 Charles Hixson via Digitalmars-d-learn wrote: On 07/05/2016 11:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tuesday, July 05, 2016 11:16:31 Charles Hixson via Digitalmars-d

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

2016-07-06 Thread Charles Hixson via Digitalmars-d-learn
On 07/06/2016 10:32 AM, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Jul 06, 2016 at 10:19:19AM -0700, Charles Hixson via Digitalmars-d-learn wrote: [...] The same time needs to be used for two different purposes (or I have to keep two separate times). One time is used during a

How to open file with exclusive lock?

2016-07-12 Thread Charles Hixson via Digitalmars-d-learn
I want to open a file with an exclusive lock. It would be important that no other thread be able to access the file in write mode, and desirable that no other thread be able to access the file in read mode. (Ditto for other processes.) stdio.file.lock (or is it stdio.file.File.lock?) seems t

Re: How to open file with exclusive lock?

2016-07-12 Thread Charles Hixson via Digitalmars-d-learn
On 07/12/2016 12:05 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Jul 12, 2016 at 11:54:18AM -0700, Charles Hixson via Digitalmars-d-learn wrote: I want to open a file with an exclusive lock. It would be important that no other thread be able to access the file in write mode, and

Re: How to open file with exclusive lock?

2016-07-12 Thread Charles Hixson via Digitalmars-d-learn
On 07/12/2016 03:54 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Jul 12, 2016 at 03:40:36PM -0700, Charles Hixson via Digitalmars-d-learn wrote: [...] OK. It's not possible without OS support. Agreed. And I don't want to get into C calls, but rather to use the mechani

core.sync.rwmutex example

2014-05-09 Thread Charles Hixson via Digitalmars-d-learn
The example code from core.sync.rwmutex seems bugged. After copying it I added an import for core.sync.rwmutex, and moved the executions of runTest into...well: void main() {runTest(ReadWriteMutex.Policy.PREFER_READERS); runTest(ReadWriteMutex.Policy.PREFER_WRITERS); } Then I tried to

Re: core.sync.rwmutex example

2014-05-09 Thread Charles Hixson via Digitalmars-d-learn
On 05/09/2014 02:51 PM, Joshua Niehus via Digitalmars-d-learn wrote: Hi Charles, would the following work (just a shot in the dark) ? //--- module test; import std.stdio; import std.concurrency; void spawnedFuncFoo(Tid tid, Tid tidBar) { receive( (int i) { writeln("

Re: core.sync.rwmutex example

2014-05-12 Thread Charles Hixson via Digitalmars-d-learn
On 05/10/2014 06:28 PM, TheFlyingFiddle via Digitalmars-d-learn wrote: On Friday, 9 May 2014 at 23:12:44 UTC, Charles Hixson via Digitalmars-d-learn wrote: But I'm worried about the receiving end. It needs, somehow, to ensure that the message it receives is the appropriate message, and

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread Charles Hixson via Digitalmars-d-learn
On 05/12/2014 09:29 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Mon, 12 May 2014 14:49:52 + hane via Digitalmars-d-learn wrote: and is there any way to sort char array with algorithm.sort? --- import std.algorithm; import std.range; void main() { int[] arr = [5, 3, 7];

receiveTimeout minimum reasonable timeout value?

2014-05-15 Thread Charles Hixson via Digitalmars-d-learn
Duration can be specified in nanoseconds, but does it make any sense to have a value of 1 nanosecond? 0? My desire is to check whether a message is in the queue, and then either move it local to the thread, or continue, depending. Secondarily, is there much overhead in calling receiveTimeout

Re: receiveTimeout minimum reasonable timeout value?

2014-05-15 Thread Charles Hixson via Digitalmars-d-learn
On Thursday, May 15, 2014 08:21:41 PM JR via Digitalmars-d-learn wrote: > On Thursday, 15 May 2014 at 18:15:46 UTC, Charles Hixson via > > Digitalmars-d-learn wrote: > > Duration can be specified in nanoseconds, but does it make any > > sense > > to have a value of 1

std.concurrency thread communication problem

2014-05-17 Thread Charles Hixson via Digitalmars-d-learn
I'm building a program which I intend to have many threads that can each send messages to (and receive messages from) each other. The obvious way to do this would be to have a shared array of Tids, but this seems to not work. I'm continually fighting the system to get it to compile, and this m

Re: std.concurrency thread communication problem

2014-05-17 Thread Charles Hixson via Digitalmars-d-learn
On Saturday, May 17, 2014 12:59:22 PM Ali Çehreli via Digitalmars-d-learn wrote: > On 05/17/2014 12:33 PM, John Colvin wrote: > > On Saturday, 17 May 2014 at 18:43:25 UTC, Charles Hixson via > > > > Digitalmars-d-learn wrote: > >> I'm building a program which

std.concurrency bug?

2014-05-20 Thread Charles Hixson via Digitalmars-d-learn
Is it a bug that an immutable struct cannot be sent to a thread? (It compiles without problem if I make all elements mutable.)

Re: std.concurrency bug?

2014-05-20 Thread Charles Hixson via Digitalmars-d-learn
On Tuesday, May 20, 2014 11:42:48 AM Ali Çehreli via Digitalmars-d-learn wrote: > On 05/20/2014 11:38 AM, Charles Hixson via Digitalmars-d-learn wrote: > > Is it a bug that an immutable struct cannot be sent to a thread? (It > > compiles without problem if I make all elements muta

Re: std.concurrency bug?

2014-05-20 Thread Charles Hixson via Digitalmars-d-learn
On Tuesday, May 20, 2014 11:42:48 AM Ali Çehreli via Digitalmars-d-learn wrote: > On 05/20/2014 11:38 AM, Charles Hixson via Digitalmars-d-learn wrote: > > Is it a bug that an immutable struct cannot be sent to a thread? (It > > compiles without problem if I make all elements muta

Re: std.concurrency bug?

2014-05-21 Thread Charles Hixson via Digitalmars-d-learn
On Wednesday, May 21, 2014 01:19:32 PM Ali Çehreli via Digitalmars-d-learn wrote: > On 05/20/2014 05:24 PM, Charles Hixson via Digitalmars-d-learn wrote: > > On Tuesday, May 20, 2014 11:42:48 AM Ali Çehreli via Digitalmars-d-learn > > > > wrote: > >> On 05/20

How to convert from ubyte[] to and from float?

2014-10-18 Thread Charles Hixson via Digitalmars-d-learn
What is the best way to convert from a part of a ubyte[] to a float? I've tried converting the ubyte[] into a uint, but neither casting the uint to a float nor to!float work. I suppose I could use a "trick record" union, but that seems inelegant. If I use pointers, the alignment may (unpredi

parser bug?

2014-10-23 Thread Charles Hixson via Digitalmars-d-learn
The code: voidgo(ulongrecNum) {assert (buf[0] == (fh.sizeof + recNo * buf.length) & 0x7f); if(dirty) yields the error message: ells$ dmd test.d test.d(78): Error: buf[0] == fh.sizeof + recNo * buf.length must be parenthesized when next to operator & And I'll

repack ubyte[] to use only 7 bits

2014-12-06 Thread Charles Hixson via Digitalmars-d-learn
Is there a standard way to do this? The code below is untested, as I haven't yet written the x7to8 routine, and came up with a better way to do what this was to accomplish, but it feels as if this should be somewhere in the standard library, if I could only find it. /** Repack the data from a

Re: repack ubyte[] to use only 7 bits

2014-12-06 Thread Charles Hixson via Digitalmars-d-learn
Your comments would be reasonable if this were destined for a library, but I haven't even finished checking it (and probably won't since I've switched to a simple zero elimination scheme). But this is a bit specialized for a library...a library should probably deal with arbitrary ints from 8 t

repack ubyte[] to use only 7 bits

2014-12-13 Thread Charles Hixson via Digitalmars-d-learn
Is there a standard way to do this? The code below is untested, as I haven't yet written the x7to8 routine, and came up with a better way to do what this was to accomplish, but it feels as if this should be somewhere in the standard library, if I could only find it. /** Repack the data from a

Re: repack ubyte[] to use only 7 bits

2014-12-13 Thread Charles Hixson via Digitalmars-d-learn
On 12/13/2014 03:20 AM, Manolo via Digitalmars-d-learn wrote: On Saturday, 13 December 2014 at 10:09:27 UTC, Charles Hixson via Digitalmars-d-learn wrote: Is there a standard way to do this? The code below is untested, as I haven't yet written the x7to8 routine, and came up with a bette

What is: Orphan format arguments: args[0..1]

2015-03-15 Thread Charles Hixson via Digitalmars-d-learn
What is: Orphan format arguments: args[0..1] It appears to come from within unittest at the line: strings="{0}".format(cast(int)d2[i]); d2 is: ubyted2[]; It should be 512 bytes long, but that hasn't been checked at the point of the error. The compilation used was: rdmd --ma

Re: What is: Orphan format arguments: args[0..1]

2015-03-15 Thread Charles Hixson via Digitalmars-d-learn
On 03/15/2015 12:27 PM, anonymous via Digitalmars-d-learn wrote: On Sunday, 15 March 2015 at 18:46:52 UTC, Charles Hixson wrote: What is: Orphan format arguments: args[0..1] It appears to come from within unittest at the line: strings="{0}".format(cast(int)d2[i]); It means you ga

struct / cast / ? design problem

2015-03-15 Thread Charles Hixson via Digitalmars-d-learn
I've got, say, a file header in a routine that looks like: structBlockHead { uintmagic=20150312;//block magic uintmagic2;//magic for use by the using routine uintblockSize; uintunused1; ulongunused2; ulo

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/15/2015 04:51 PM, ketmar via Digitalmars-d-learn wrote: On Sun, 15 Mar 2015 16:34:14 -0700, Charles Hixson via Digitalmars-d-learn wrote: if you know the exact layouts of `spare`, you can use union for that: struct S { // ... union { ulong[61] spare; struct { int vala

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/16/2015 09:16 AM, Charles Hixson via Digitalmars-d-learn wrote: On 03/15/2015 04:51 PM, ketmar via Digitalmars-d-learn wrote: On Sun, 15 Mar 2015 16:34:14 -0700, Charles Hixson via Digitalmars-d-learn wrote: if you know the exact layouts of `spare`, you can use union for that: struct

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/16/2015 11:55 AM, ketmar via Digitalmars-d-learn wrote: On Mon, 16 Mar 2015 11:18:16 -0700, Charles Hixson via Digitalmars-d-learn wrote: My current best answer is to turn the "unused" into a vector of bytes, and then pass that to the using routines as a ref. This still is wi

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/16/2015 01:24 PM, via Digitalmars-d-learn wrote: The problem in your example is that your making a copy of the returned data. Of course any changes to that copy won't affect the original. You need to return a pointer to it (`ref` won't do if you want to store it in a local variable, beca

How to test for type without refs?

2015-03-17 Thread Charles Hixson via Digitalmars-d-learn
I thought that in: T* user(T)() {static assert (T.sizeof < bfHdr.user_.length); static assert (__traits(isPOD, T) ); returncast(T*) bfHdr.user_.ptr; } the line: static assert (__traits(isPOD, T) ); would test for there not being any embedded refs, pointers,

Re: How to test for type without refs?

2015-03-17 Thread Charles Hixson via Digitalmars-d-learn
On 03/17/2015 07:27 AM, anonymous via Digitalmars-d-learn wrote: On Tuesday, 17 March 2015 at 14:06:19 UTC, Charles Hixson wrote: I thought that in: T* user(T)() {static assert (T.sizeof < bfHdr.user_.length); static assert (__traits(isPOD, T) ); returncast(T

buffer to struct type conversion...TArrayStream?

2015-03-19 Thread Charles Hixson via Digitalmars-d-learn
I've read a chunk of data into a buffer and want to convert it into a struct. The reading routine is in a class that doesn't know about the struct, but the size should be exactly the same. (I.e., I want to use the converse procedure to write it.) Is there a better way to do this than using T

Re: buffer to struct type conversion...TArrayStream?

2015-03-19 Thread Charles Hixson via Digitalmars-d-learn
On 03/19/2015 11:18 AM, ketmar via Digitalmars-d-learn wrote: On Thu, 19 Mar 2015 10:47:05 -0700, Charles Hixson via Digitalmars-d-learn wrote: turn it 90 degrees. ;-) auto cvt = cast(Node_*)buf.ptr; n = cvt[0]; Whee! Thanks, I don't think I *ever* would have thought of that. I go

Re: buffer to struct type conversion...TArrayStream?

2015-03-19 Thread Charles Hixson via Digitalmars-d-learn
On 03/19/2015 12:05 PM, via Digitalmars-d-learn wrote: On Thursday, 19 March 2015 at 18:42:03 UTC, Marc Schütz wrote: 3) Using std.bitmap.peek(), which also supports conversion between big- and little-endian: import std.bitmap; n.self = buf.peek!(Node.Node_, Endian.bigEndian); (The exam

Accessing a field of a containing class from within a nested class

2015-04-01 Thread Charles Hixson via Digitalmars-d-learn
The class Node is contained within the struct BTree. The field btFile is contained within the struct BTree. The statement is within a function within the Node class. I've tried many variations, here are a few: btFile.write(self.nodeId, cast(void*)&(self)); results in: need 'this' for 'btFile'

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread Charles Hixson via Digitalmars-d-learn
On 04/01/2015 11:39 AM, anonymous via Digitalmars-d-learn wrote: On Wednesday, 1 April 2015 at 18:26:49 UTC, Charles Hixson wrote: Perhaps BTree needs to be a class? yes Thanks. Sigh. I was hoping to preserve the determinate closing that one gets with a struct.

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread Charles Hixson via Digitalmars-d-learn
y and the Data will be required to pass !hasIndirections!(T). I'm not planning a truly general BTree. In my test version the Key is a ulong and the Data is a struct containing only ulongs and ints.) On 04/01/2015 03:03 PM, Ali Çehreli via Digitalmars-d-learn wrote: On 04/01/2015 11:25 AM,

Re: Efficiently passing structs

2015-05-06 Thread Charles Hixson via Digitalmars-d-learn
On 05/05/2015 11:49 AM, Ali Çehreli via Digitalmars-d-learn wrote: On 05/05/2015 07:14 AM, bitwise wrote: > I don't see how someone could arrive at the above > solution without showing up here and asking first. It was the same with me. :) Then I wrote a short section about it: http://ddili.

How to simulate a new type

2015-05-14 Thread Charles Hixson via Digitalmars-d-learn
What are the downsides to simulating a new type with a struct. What I have in mind is something along the lines of: struct myType { uint64_t value; } The goal of this type is to prevent accidental conversions from myType into ints, uint64_ts, etc.

Re: How to simulate a new type

2015-05-14 Thread Charles Hixson via Digitalmars-d-learn
On 05/14/2015 01:42 PM, Laeeth Isharc via Digitalmars-d-learn wrote: On Thursday, 14 May 2015 at 18:42:56 UTC, Charles Hixson wrote: What are the downsides to simulating a new type with a struct. What I have in mind is something along the lines of: struct myType { uint64_t value; } The go

Re: How to simulate a new type

2015-05-14 Thread Charles Hixson via Digitalmars-d-learn
On 05/14/2015 06:38 PM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Friday, 15 May 2015 at 01:03:32 UTC, Charles Hixson wrote: Yes, that looks as if it would do the job, but what are its advantages over a simple struct? None really, except perhaps automatic forwarding of operators which

Re: Ada-Style Sub-Typing

2015-06-06 Thread Charles Hixson via Digitalmars-d-learn
It's not totally convenient, but what I'm currently using is a slightly less elaborate struct: structA {intv;} Since all I'm creating is an isolated type, the private stuff isn't needed. If I wanted to get fancy I could start implementing operations. Comparison is free, as st

std.concurrent Tid vector initialization problem

2015-06-27 Thread Charles Hixson via Digitalmars-d-learn
I'm planning an application where a series of threads each need to be aware of the Tids of all the others. The number won't be known at compile time, but that doesn't seem to change the design. All I've been able to come up with is a pair of loops, one to spawn the threads, and collect their

std.concurrent Tid vector initialization problem

2015-06-30 Thread Charles Hixson via Digitalmars-d-learn
I'm planning an application where a series of threads each need to be aware of the Tids of all the others. The number won't be known at compile time, but that doesn't seem to change the design. All I've been able to come up with is a pair of loops, one to spawn the threads, and collect their

Re: std.concurrent Tid vector initialization problem

2015-06-30 Thread Charles Hixson via Digitalmars-d-learn
On Sunday, 28 June 2015 at 09:59:29 UTC, Marc Schütz wrote: On Sunday, 28 June 2015 at 01:02:02 UTC, Charles Hixson wrote: I'm planning an application where a series of threads each ...gn. Does anyone have a better idea? (The rough estimate of the number of Tids is six, but that's likely to

What is the std.stream replacement?

2015-07-19 Thread Charles Hixson via Digitalmars-d-learn
I have DMD64 D Compiler v2.067.1 installed, and in the documentation of phobos what it says about std.stream is "don't use it on new code". It doesn't, however, appear to offer any replacement. Certainly std.file, std.stdio, and std.path aren't replacements. So what *is* the appropriate repla

Re: Replacement of std.stream

2015-07-19 Thread Charles Hixson via Digitalmars-d-learn
On Monday, 29 June 2015 at 12:00:14 UTC, Jonathan M Davis wrote: On Sunday, June 28, 2015 11:14:57 Baz via Digitalmars-d-learn wrote: On Sunday, 28 June 2015 at 05:04:48 UTC, DlangLearner wrote: > I will convert a Java program into D. The original Java code > is based on the class RandomeAccess

randomIO, std.file, core.stdc.stdio

2016-07-25 Thread Charles Hixson via Digitalmars-d-learn
Are there reasons why one would use rawRead and rawWrite rather than fread and fwrite when doiing binary random io? What are the advantages? In particular, if one is reading and writing structs rather than arrays or ranges, are there any advantages?

Re: randomIO, std.file, core.stdc.stdio

2016-07-25 Thread Charles Hixson via Digitalmars-d-learn
On 07/25/2016 05:18 PM, ketmar via Digitalmars-d-learn wrote: On Monday, 25 July 2016 at 18:54:27 UTC, Charles Hixson wrote: Are there reasons why one would use rawRead and rawWrite rather than fread and fwrite when doiing binary random io? What are the advantages? In particular, if one is re

Re: randomIO, std.file, core.stdc.stdio

2016-07-25 Thread Charles Hixson via Digitalmars-d-learn
On 07/25/2016 07:11 PM, ketmar via Digitalmars-d-learn wrote: On Tuesday, 26 July 2016 at 01:19:49 UTC, Charles Hixson wrote: then I will prefer the core.stdc.stdio approach. I find it's appearance extremely much cleaner... only if you are really used to write C code. when you see pointer, or

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/25/2016 09:22 PM, ketmar via Digitalmars-d-learn wrote: On Tuesday, 26 July 2016 at 04:05:22 UTC, Charles Hixson wrote: Yes, but I really despise the syntax they came up with. It's probably good if most of your I/O is ranges, but mine hasn't yet ever been. (Combining ranges with random

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 05:31 AM, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/25/16 9:19 PM, Charles Hixson via Digitalmars-d-learn wrote: On 07/25/2016 05:18 PM, ketmar via Digitalmars-d-learn wrote: On Monday, 25 July 2016 at 18:54:27 UTC, Charles Hixson wrote: Are there reasons why one

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 10:18 AM, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/26/16 12:58 PM, Charles Hixson via Digitalmars-d-learn wrote: Ranges aren't free, are they? If so then I should probably use stdfile, because that is probably less likely to change than core.stdc.stdio. D

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 11:31 AM, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/26/16 1:57 PM, Charles Hixson via Digitalmars-d-learn wrote: Thanks. Since there isn't any excess overhead I guess I'll use stdio. Buffering, however, isn't going to help at all since I'm doi

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Charles Hixson via Digitalmars-d-learn
On 07/26/2016 12:53 PM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Tuesday, 26 July 2016 at 19:30:35 UTC, Charles Hixson wrote: It looks as if the entire file is stored in memory, which is not at all what I want, but I also can't really believe that's what's going on. It is just mapped t

Re: randomIO, std.file, core.stdc.stdio

2016-07-27 Thread Charles Hixson via Digitalmars-d-learn
On 07/27/2016 06:46 AM, Rene Zwanenburg via Digitalmars-d-learn wrote: On Wednesday, 27 July 2016 at 02:20:57 UTC, Charles Hixson wrote: O, dear. It was sounding like such an excellent approach until this last paragraph, but growing the file is going to be one of the common operations. (Certai

arrays, mmu, addressing choices

2016-08-08 Thread Charles Hixson via Digitalmars-d-learn
I have a rather large array that I intend to build. but much of it will only occasionally be used. Will the unused sections automatically be paged out? If it matters my system is Debian Linux. This array will be indexed by a ulong. Is there any reasonable maximum size? I've considered segm

how to declare an immutable class?

2016-08-11 Thread Charles Hixson via Digitalmars-d-learn
I want to declare a class all instances of which will be immutable, and all references to which will be inherently immutable (so that I don't need to slip a huge number of "immutable" statements in my code). This is surely possible, because string acts just that way, but I can't figure out how

Re: how to declare an immutable class?

2016-08-11 Thread Charles Hixson via Digitalmars-d-learn
before this solution On 08/11/2016 10:56 AM, Charles Hixson via Digitalmars-d-learn wrote: I want to declare a class all instances of which will be immutable, and all references to which will be inherently immutable (so that I don't need to slip a huge number of "immutable" statem

Re: how to declare an immutable class?

2016-08-11 Thread Charles Hixson via Digitalmars-d-learn
On 08/11/2016 06:33 PM, Mike Parker via Digitalmars-d-learn wrote: On Friday, 12 August 2016 at 00:44:31 UTC, Charles Hixson wrote: A way around this, which may be the same as the approach used by string was: alias immutable(Msg_)Msg; classMsg_ { ... This is exactly what Jonathan s

Re: how to declare an immutable class?

2016-08-12 Thread Charles Hixson via Digitalmars-d-learn
Thank you both. On 08/12/2016 01:35 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Friday, August 12, 2016 05:25:45 Mike Parker via Digitalmars-d-learn wrote: immutable class Foo { ... } is the same as declaring every member of Foo as immutable, just as final class Foo { ... } makes ev

Multi-Thread message passing approach

2016-08-14 Thread Charles Hixson via Digitalmars-d-learn
This is an approach to n x n thread message passing. The idea is that each thread should be able to pass messages to any other thread. The only alternative I've come up with involves the main thread handling each message. Is that a better approach? Is there a better way to pass lists of Tid

Re: Multi-Thread message passing approach

2016-08-14 Thread Charles Hixson via Digitalmars-d-learn
On 08/14/2016 07:44 AM, Charles Hixson via Digitalmars-d-learn wrote: This is an approach to n x n thread message passing. The idea is that each thread should be able to pass messages to any other thread. The only alternative I've come up with involves the main thread handling each me

Re: Multi-Thread message passing approach

2016-08-14 Thread Charles Hixson via Digitalmars-d-learn
doesn't happen to be detected by the library. On 08/14/2016 07:44 AM, Charles Hixson via Digitalmars-d-learn wrote: This is an approach to n x n thread message passing. The idea is that each thread should be able to pass messages to any other thread. The only alternative I've come up

Re: Multi-Thread message passing approach

2016-08-15 Thread Charles Hixson via Digitalmars-d-learn
I misunderstood the problem. The problem was that a dynamically sized array cannot be sent as a message. So this works: import std.concurrency; import std.stdio; import core.thread; enum tidMax = 10; struct Start { int tidCnt = 0; Tid[tidMax] tids; } struct Msg { int

Re: Multi-Thread message passing approach

2016-08-16 Thread Charles Hixson via Digitalmars-d-learn
On 08/16/2016 07:21 AM, Kagamin via Digitalmars-d-learn wrote: On Monday, 15 August 2016 at 01:53:33 UTC, Charles Hixson wrote: If I modify the code to attempt to pass a Tid[] as a member of struct Start I get: /usr/include/dmd/phobos/std/concurrency.d(603): Error: static assert "Aliases t

strange -fPIC compilation error

2016-10-30 Thread Charles Hixson via Digitalmars-d-learn
dmd --version DMD64 D Compiler v2.071.2 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright on debian testing. dub is installed via apt-get. Should I revert to an earlier version? Or what? The program: importstd.stdio; voidmain() {//int[]t1; //t1~=

  1   2   >