Re: How to convert from ubyte[] to and from float?
On Sunday, 19 October 2014 at 03:14:26 UTC, Charles Hixson via Digitalmars-d-learn wrote: 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 (unpredictably) not be proper (whatever that means these days). Is this what you're after? http://dlang.org/phobos/std_bitmanip.html#.peek http://dlang.org/phobos/std_bitmanip.html#.read http://dlang.org/phobos/std_bitmanip.html#.write These accept indices, or you can just slice the ubyte[] to the part you need. --- import std.stdio; import std.bitmanip; import std.system; void main() { // UBYTE[] to FLOAT // // 6.5535000E+004 00-FF-7F-47 ubyte[] ubval = [0, 0xff, 0x7f, 0x47]; auto fval = ubval.peek!(float, Endian.littleEndian); writefln(%s as float: %s, ubval, fval); writefln(%s as float: %s, ubval, ubval.read!(float, Endian.littleEndian)); // 16383.8 00-FF-7F-46 ubval = [0, 0xff, 0x7f, 0x46]; fval = ubval.peek!(float, Endian.littleEndian); writefln(%s as float: %s, ubval, fval); writefln(%s as float: %s, ubval, ubval.read!(float, Endian.littleEndian)); // FLOAT to UBYTE[] ubval = [0, 0, 0, 0]; std.bitmanip.write!(float, Endian.littleEndian)(ubval, 65535.0f, 0); writefln(%s as ubyte[]: %s, fval, ubval); ubval = [0, 0, 0, 0]; std.bitmanip.write!(float, Endian.littleEndian)(ubval, fval, 0); writefln(%s as ubyte[]: %s, fval, ubval); } ---
Re: Base class with member parameterized on type of extending class
On 2014-10-19 13:19, rcor wrote: I'm trying to make a game, and would like to set up the following hierarchy: At any time, the game is in one Scene. Each scene has a state machine that manages States of type T, where T is the type of the scene (e.g. Overworld, Menu). abstract class State!T { void update(T scene, float time, InputManager input); ... } class StateMachine!T { //manages states of type State!T } abstract class Scene { alias T = // type of class extending Scene // methods pushState, popState, currentState access _stateMachine private StateMachine!T _stateMachine; } class MainMenu : Scene { // I want _stateMachine of type StateMachine!MainMenu } class Overworld : Scene { // I want _stateMachine of type StateMachine!Overworld } class MoveToLocation : State!Overworld { override void update(Overworld world, float time, InputManager input) { // access properties of Overworld here } } Within the Scene class, I've tried alias T = typeof(this), but that appears to be resolved within Scene. This means that any Scene, such as Overworld, have a state machine of type StateMachine!Scene rather than StateMachine!Overworld. Since States are particular to a certain scene and are designed to manipulate properties specific to that type of scene, this would involve a lot of casting if States are not parameterized. It feels like I need something like a class version of the (this T) syntax used in templates. This all smells a bit off though, so I wouldn't be surprised if the answer is that I'm approaching this all wrong, but right now I'm not seeing it. You can always make Scene a template class: abstract class Scene (T) { private StateMachine!T _stateMachine; } class MainMenu : Scene!(MainMenu) {} But I'm guessing you like to avoid that if possible. -- /Jacob Carlborg
Re: Benchmark games, Rust, big ints and Pi
John Carter: Your paste has expired / no longer there but the subject has come up again... ... Do you still have your implementation hanging around? I think it was this. *Untested*: void main(string[] args) { import core.stdc.stdio, std.bigint, core.stdc.stdlib; immutable n = (args.length == 2) ? args[1].ptr.atoi : 100; BigInt acc, den = 1, num = 1; for (uint i, k; i n; ) { immutable k2 = ++k * 2U + 1U; acc = (acc + num * 2U) * k2; den *= k2; num *= k; if (num acc) continue; immutable d = ((num * 3 + acc) / den) % 10U; if (d != ((num * 4 + acc) / den) % 10U) continue; putchar('0' + d); if (++i % 10 == 0) printf(\t:%u\n, i); acc = (acc - den * d) * 10U; num *= 10U; } } Bye, bearophile
Re: DDoc module description?
On Monday, 20 October 2014 at 01:58:27 UTC, Jeremy DeHaan wrote: Is there no way to specify one at compile time? Also, if I were to set the DDoc file like you suggest, does it look for one locally to dmd.conf/sc.ini or to the source code? See here for full information: http://dlang.org/ddoc.html The compiler checks in various places for a valid ddoc file.
Re: m_condition.mutex cannot be used in shared method ?
Am Sun, 19 Oct 2014 17:09:22 + schrieb Sean Kelly s...@invisibleduck.org: What really needs to happen is for everything in core.sync to be made shared. I got partway through this at one point and stopped, because it was imposing a terrible design on the classes--I had shared methods that were casting away shared and then calling the non-shared methods to do the work. The reason for this was that the transitivity of shared was preventing me from calling pthread_mutex_lock or whatever because those functions didn't take a shared pthread_mutex_t. And attempting to rewrite core.sys.posix to make the logically shared types explicitly shared had a cascading effect that made me uncomfortable. Because of this, I remain unconvinced that the semantics of the shared attribute are actually correct when applied to user-defined types. I want some kind of an I know what I'm doing label, perhaps equivalent to the mutable attribute in C++, but to exempt contained types from shared. Thank you for that honest response. The situation is really bizarre. I just tried to create a shared worker thread and there is no ctor in Thread that creates a shared instance. Is a shared constructor even meaningful? [1] If yes, what do we need it for? Can't we otherwise just implicitly and safely cast to shared _after_ the constructor ran when we write `new shared(Foo)(...)`? Casting away shared is not @safe. Since this is normal to do in synchronized blocks, I figure the whole core.Thread and core.sync.xxx family are @system functionality ? [1] (Note that I created a PR for DMD that disables shared destruction: https://github.com/D-Programming-Language/dmd/pull/4072) -- Marco
Re: Base class with member parameterized on type of extending class
On Monday, 20 October 2014 at 06:17:42 UTC, Jacob Carlborg wrote: You can always make Scene a template class: abstract class Scene (T) { private StateMachine!T _stateMachine; } class MainMenu : Scene!(MainMenu) {} But I'm guessing you like to avoid that if possible. I would, as I need to keep track of the current scene in a variable somewhere: Scene _currentScene; // problematic if Scene is a template I could just declare the StateMachine separately in every Scene, but that seems like a lot of duplicate code (I then repeat the same code for updating the state machine, ect.)
Re: Really in need of help with std.container.array.d
On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote: https://github.com/nordlow/phobos/commit/ce6b9e9ae600b7c28ecddd1e3af7b1516247fb33 now errors as array.d(927,15): Error: None of the overloads of 'opSlice' are callable using a const object, candidates are: array.d(472,25): std.container.array.Array!int.Array.opSlice() array.d(495,25): std.container.array.Array!int.Array.opSlice(ulong i, ulong j) The error is because of this (lines 470 through 483): static if (isMutable!T) { Range!(Array!T) opSlice() { return typeof(return)(this, 0, length); } } else { Range!(const(Array!T)) opSlice() const { return typeof(return)(this, 0, length); } } You're disabling the const version when T is mutable. Consider const(Array!int): T is int is mutable, so there is no const opSlice. But the Array itself is const, so the non-const version can't be used. Do not disable the const versions of the methods. Only ever disable the non-const ones. Also, the opSlice we're looking at here is Array's, not Array.Range's. You don't need to touch Array's methods at all. Only Array.Range's non-const methods need special treatment, because you need to catch the special case when the Range is mutable, but the referenced Array is not. And it's really `isMutableA!`, not `isMutable!T`. I guess you went for that because `A` is only defined in Array.Range, not in Array itself. But T's mutability isn't of interest. For example, Array.Range.opSlice should look like this: static if (isMutable!A) /* !A, not !T */ { Range!(A) opSlice() {/* ... */} Range!(A) opSlice(size_t i, size_t j) {/* ... */} } /* No `else`, the const versions should always be available. */ Range!(const(A)) opSlice() const {/* ... */} Range!(const(A)) opSlice(size_t i, size_t j) const {/* ... */} Then there are still various methods of Array.Range left to be `static if(isMutable!A)` guarded: * move* * opIndex * opSlice* By the way, since we're in D.learn, I'm assuming you want to do this yourself. But if you'd like, I could make a pull request with my suggestions to your branch.
Re: Really in need of help with std.container.array.d
On Monday, 20 October 2014 at 10:56:43 UTC, anonymous wrote: On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote: By the way, since we're in D.learn, I'm assuming you want to do this yourself. But if you'd like, I could make a pull request with my suggestions to your branch. Yes, please! That would be very kind of you. /Thx
Re: Base class with member parameterized on type of extending class
On 2014-10-20 12:27, rcor wrote: I would, as I need to keep track of the current scene in a variable somewhere: Scene _currentScene; // problematic if Scene is a template If the state machine doesn't need to be exposed you can create base class for Scene which is not templated: abstract class Scene {} // As it is now minus the state machine abstract class ConcreteScene (T) : Scene { private StateMachine!T _stateMachine; // other code that need access to _stateMachine } class MainMenu : ConcreteScene!(MainMenu) {} Scene _currentScene = new MainMenu; ConcreteScene might not be the best name of an abstract class. I could just declare the StateMachine separately in every Scene, but that seems like a lot of duplicate code (I then repeat the same code for updating the state machine, ect.) Or you could use a template mixin: template StateMachineMixin (T) { private StateMachine!T _stateMachine; // other code that need access to _stateMachine } class MainMenu : Scene { mixin StateMachineMixin!(typeof(this)); } -- /Jacob Carlborg
Re: Base class with member parameterized on type of extending class
If the state machine doesn't need to be exposed you can create base class for Scene which is not templated: abstract class Scene {} // As it is now minus the state machine abstract class ConcreteScene (T) : Scene { private StateMachine!T _stateMachine; // other code that need access to _stateMachine } class MainMenu : ConcreteScene!(MainMenu) {} Scene _currentScene = new MainMenu; ConcreteScene might not be the best name of an abstract class. Just came up with something similar before I saw this post: interface IScene { // enter, exit, update, draw } class Scene!T : IScene { private StateMachine!T _stateMachine; void update(float time) { _stateMachine.update(cast(T) this, time); } } The cast is unfortunate but since it only happens once per update cycle I'm not that worried about it. I could just declare the StateMachine separately in every Scene, but that seems like a lot of duplicate code (I then repeat the same code for updating the state machine, ect.) Or you could use a template mixin: template StateMachineMixin (T) { private StateMachine!T _stateMachine; // other code that need access to _stateMachine } class MainMenu : Scene { mixin StateMachineMixin!(typeof(this)); } Interesting idea, I might give this a try but the first suggestion seems fine for now. Thanks!
Re: Beginner ?. Why does D suggest to learn java
On Friday, 17 October 2014 at 23:31:46 UTC, Joakim wrote: Tablets are optimized for basic usage, not saving files and document editing and whatever else you might want to do on a PC. Most people just need a basic appliance that isn't going to catch viruses or require registry hacks. LOL http://wmpoweruser.com/infected-android-phones-now-outnumber-infected-pcs-on-mobile-networks/
Re: Making plugin system with shared libraries. Upcast in shared lib
Do it the COM way: publish IModule2 interface and declare GetInterface method, which will return a prepared pointer, which you would reinterpret cast to IModule2.
Re: Making plugin system with shared libraries. Upcast in shared lib
On Monday, 20 October 2014 at 14:05:29 UTC, Kagamin wrote: Do it the COM way: publish IModule2 interface and declare GetInterface method, which will return a prepared pointer, which you would reinterpret cast to IModule2. Will it work on linux with simple .so libs? I want it to be as simple as possible.
Re: Making plugin system with shared libraries. Upcast in shared lib
On 10/20/2014 12:32 AM, MrSmith wrote: Than any module can search for registered modules and try to cast them to concrete type (upcast). That can't work because the notion of types only exists during compilation. Therefor it's not possible to load new types at runtime and use them in code that was compiled without knowing those types. You should simply use interfaces to achieve your goal.
Re: Error: Undefined identifier when moving import to another module
On Sunday, 19 October 2014 at 22:22:05 UTC, Joakim wrote: On Sunday, 19 October 2014 at 09:39:05 UTC, nrgyzer wrote: Hi guys, when I do the following: module myMain; import example; import std.traits; import my.static.library.binding; static this() { foreach ( m; __traits(allMembers, example) ) { static if ( isCallable!(mixing(m) ) { // ... do something here } } } void main() { /* do something here */ } And my example-module looks like: module example; void exmapleFunction() { // do something here } I can compile my application without any error, BUT when I move the import of my.static.library.binding to the example-module: module example; import my.static.library.binding; void exmapleFunction() { // do something here } ... I'm getting many error messages like these: myMain.d-mixin-11(11): Error: undefined identifier _D12TypeInfo_xAa6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D49TypeInfo_xAS3std8typecons16__T5TupleTkTkTkZ5Tuple6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D75TypeInfo_xAS3std3uni38__T13InversionListTS3std3uni8GcPolicyZ13InversionList6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D55TypeInfo_xAE3std5regex15__T6ParserTAyaZ6Parser8Operator6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D31TypeInfo_xAS3std5regex8Bytecode6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D110TypeInfo_xAS3std3uni152__T4TrieTS3std3uni20__T9BitPackedTbVmi1Z9BitPackedTwVmi1114112TS3std3uni23__T9sliceBitsVmi8Vmi21Z9sliceBitsTS3std3uni22__T9sliceBitsVmi0Vmi8Z9sliceBitsZ4Trie6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D45TypeInfo_xS3std5regex14__T7ShiftOrTaZ7ShiftOr6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D11TypeInfo_xw6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D11TypeInfo_xb6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D13TypeInfo_xAya6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D41TypeInfo_xS3std5regex12__T5StackTkZ5Stack6__initZ I'm having no idea what's going wrong here. I'm simply moving the import from the file where my main() is located in to the example-module. When removing the import of my.static.library.binding in the example-module allows me to successfully compile everything. But I need the import in the example-module. Any suggestions what's going wrong here/how I can solve the error? An import is private by default: http://dlang.org/module.html When you move the import of my.static.library.binding to the example module, its declarations are no longer available in the myMain module. You'd have to make it a public import my.static.library.binding to make it available to other modules. Hm, I made it public and I'm getting the same error. I also imported the same module in my main which also gives me the same error.
Re: Error: Undefined identifier when moving import to another module
On Monday, 20 October 2014 at 16:05:14 UTC, nrgyzer wrote: On Sunday, 19 October 2014 at 22:22:05 UTC, Joakim wrote: On Sunday, 19 October 2014 at 09:39:05 UTC, nrgyzer wrote: Hi guys, when I do the following: module myMain; import example; import std.traits; import my.static.library.binding; static this() { foreach ( m; __traits(allMembers, example) ) { static if ( isCallable!(mixing(m) ) { // ... do something here } } } void main() { /* do something here */ } And my example-module looks like: module example; void exmapleFunction() { // do something here } I can compile my application without any error, BUT when I move the import of my.static.library.binding to the example-module: module example; import my.static.library.binding; void exmapleFunction() { // do something here } ... I'm getting many error messages like these: myMain.d-mixin-11(11): Error: undefined identifier _D12TypeInfo_xAa6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D49TypeInfo_xAS3std8typecons16__T5TupleTkTkTkZ5Tuple6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D75TypeInfo_xAS3std3uni38__T13InversionListTS3std3uni8GcPolicyZ13InversionList6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D55TypeInfo_xAE3std5regex15__T6ParserTAyaZ6Parser8Operator6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D31TypeInfo_xAS3std5regex8Bytecode6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D110TypeInfo_xAS3std3uni152__T4TrieTS3std3uni20__T9BitPackedTbVmi1Z9BitPackedTwVmi1114112TS3std3uni23__T9sliceBitsVmi8Vmi21Z9sliceBitsTS3std3uni22__T9sliceBitsVmi0Vmi8Z9sliceBitsZ4Trie6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D45TypeInfo_xS3std5regex14__T7ShiftOrTaZ7ShiftOr6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D11TypeInfo_xw6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D11TypeInfo_xb6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D13TypeInfo_xAya6__initZ myMain.d-mixin-11(11): Error: undefined identifier _D41TypeInfo_xS3std5regex12__T5StackTkZ5Stack6__initZ I'm having no idea what's going wrong here. I'm simply moving the import from the file where my main() is located in to the example-module. When removing the import of my.static.library.binding in the example-module allows me to successfully compile everything. But I need the import in the example-module. Any suggestions what's going wrong here/how I can solve the error? An import is private by default: http://dlang.org/module.html When you move the import of my.static.library.binding to the example module, its declarations are no longer available in the myMain module. You'd have to make it a public import my.static.library.binding to make it available to other modules. Hm, I made it public and I'm getting the same error. I also imported the same module in my main which also gives me the same error. I temporarely solved the error by making the import in the module where the main()-function is located in public and importing this file into the other module. This solved the error but is not a perfect solution...
Re: Error: Undefined identifier when moving import to another module
This solved the problem for the first time, BUT - I don't know if it's a bug or a feature - I ran into another problem. I'm having the following few lines: module example; private { string[string] myPrivateArray; } static this() { foreach ( m; __traits(allMembers, example) ) { writefln(%s :: %s, m, __traits(getProtection, m)); } } void main() { /* empty */ } Compiling and running the application say's that myPrivateArray is public: myPrivateArray :: public I declared myPrivateArray using the private keyword, but the dmd-trait `getProtection` says public. Why?
Re: m_condition.mutex cannot be used in shared method ?
On Monday, 20 October 2014 at 09:53:23 UTC, Marco Leise wrote: Thank you for that honest response. The situation is really bizarre. I just tried to create a shared worker thread and there is no ctor in Thread that creates a shared instance. Is a shared constructor even meaningful? [1] If we want to try for having thread-local memory pools then yes. If yes, what do we need it for? See above. Though there are other problems that will probably prevent this anyway (immutable being implicitly shared, for one). Can't we otherwise just implicitly and safely cast to shared _after_ the constructor ran when we write `new shared(Foo)(...)`? Yep. Casting away shared is not @safe. Since this is normal to do in synchronized blocks, I figure the whole core.Thread and core.sync.xxx family are @system functionality ? Yes. Though I really don't like feeling that casts are necessary in general. If I have to cast in order to do normal work then there's probably something wrong with the type system. Though I'll note that I also use mutable in C++ for what I feel are completely justifiable reasons (like on a contained Mutex so I can lock/unlock some region of code in a const method), and D has been firmly established in opposition to logical const. Mutexes are actually a special case in D because they bypass normal type checking thanks to the way synchronized blocks work, and I'm sure we could do something similar for shared, but it feels wrong. I kind of hope that someone will show me that casting away shared isn't necessary, kind of like how Monads are a clever response to immutability in Haskell. [1] (Note that I created a PR for DMD that disables shared destruction: https://github.com/D-Programming-Language/dmd/pull/4072) With all the recent work on the GC, we really really need to start tracking which thread owns a given non-shared object so it can be finalized properly. This may mean having the process of casting away shared make the executing thread the new owner of the object.
Re: Error: Undefined identifier when moving import to another module
On Monday, 20 October 2014 at 17:37:34 UTC, nrgyzer wrote: This solved the problem for the first time, BUT - I don't know if it's a bug or a feature - I ran into another problem. I'm having the following few lines: module example; private { string[string] myPrivateArray; } static this() { foreach ( m; __traits(allMembers, example) ) { writefln(%s :: %s, m, __traits(getProtection, m)); } } void main() { /* empty */ } Compiling and running the application say's that myPrivateArray is public: myPrivateArray :: public I declared myPrivateArray using the private keyword, but the dmd-trait `getProtection` says public. Why? Ah, okay, I also need to use mixin(m) to get the protection. But in this case, getProtection only works if I want retrieve the protection for a variable, contained in the same module. I simply can't use getProtection if I'm using the allMembers-trait for another module where the variable is private...
Re: Really in need of help with std.container.array.d
On Monday, 20 October 2014 at 11:20:30 UTC, Nordlöw wrote: On Monday, 20 October 2014 at 10:56:43 UTC, anonymous wrote: On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote: By the way, since we're in D.learn, I'm assuming you want to do this yourself. But if you'd like, I could make a pull request with my suggestions to your branch. Yes, please! That would be very kind of you. Forgot to mention it here, not sure if you noticed it: https://github.com/nordlow/phobos/pull/1
Re: Making plugin system with shared libraries. Upcast in shared lib
On Monday, 20 October 2014 at 15:30:28 UTC, Martin Nowak wrote: On 10/20/2014 12:32 AM, MrSmith wrote: Than any module can search for registered modules and try to cast them to concrete type (upcast). That can't work because the notion of types only exists during compilation. Therefor it's not possible to load new types at runtime and use them in code that was compiled without knowing those types. You should simply use interfaces to achieve your goal. In this case ether shared lib knows actual type. But i've tried it with interfaces, (upcast also), or do you mean something else? 1) I want application to load IModule from .so/.dll 2) Any other module should be able to cast that IModule to actual type (upcast) and test if result is !null. 3) Can i do this using interfaces or without them? I.e. if in first example module2 is interface
Re: Beginner ?. Why does D suggest to learn java
On Monday, 20 October 2014 at 13:52:10 UTC, Kagamin wrote: On Friday, 17 October 2014 at 23:31:46 UTC, Joakim wrote: Tablets are optimized for basic usage, not saving files and document editing and whatever else you might want to do on a PC. Most people just need a basic appliance that isn't going to catch viruses or require registry hacks. LOL http://wmpoweruser.com/infected-android-phones-now-outnumber-infected-pcs-on-mobile-networks/ Are you laughing because of this? :) Android devices accounted for 60% of total mobile network infections, and 40% of mobile malware originated from Windows laptops connected to a phone or connected directly through a mobile USB stick or W-Fi hub. Infections on Windows Phone, iPhone and BlackBerry devices made up less than 1% 'Android smartphones are the easiest malware target,' said Kevin McNamee, security architect and director of Alcatel-Lucent’s Kindsight Security Labs, but noted 'but Windows laptops are still the favourite of hard core professional cybercriminals.'” Note my original reference to not being able to save files and the very low rate of infection on the iPhone. Android is a little different because it's so open, just like Windows, and I bet most of those infected Android devices were rooted or old. If you do the math, there are a lot more Android devices than Windows laptops, so the fact that there are almost as many infected Windows laptops means the infection rate of Windows is much higher.
Re: Beginner ?. Why does D suggest to learn java
On Mon, Oct 20, 2014 at 2:40 PM, Joakim via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 20 October 2014 at 13:52:10 UTC, Kagamin wrote: If you do the math, there are a lot more Android devices than Windows laptops, so the fact that there are almost as many infected Windows laptops means the infection rate of Windows is much higher. All the more, those numbers reflecting infection rates on mobile networks.
Re: Really in need of help with std.container.array.d
On Monday, 20 October 2014 at 18:01:11 UTC, anonymous wrote: Forgot to mention it here, not sure if you noticed it: https://github.com/nordlow/phobos/pull/1 Superb.
Re: Removing whitespace duplicates
On Monday, 20 October 2014 at 20:27:19 UTC, Nordlöw wrote: line.strip.splitter!isWhite.joiner(_).to!string Doh, that was too easy: line.strip.splitter!isWhite.filter!(a = !a.empty).joiner(lineSeparator).to!S; Sorry, for being lazy ;)
Removing whitespace duplicates
How can I extend string line = carwash; line.strip.splitter!isWhite.joiner(_).to!string so that car wash becomes car_wash and not car___wash ? Used at https://github.com/nordlow/justd/blob/master/knet.d#L1142
Re: Removing whitespace duplicates
Nordlöw: How can I extend string line = carwash; line.strip.splitter!isWhite.joiner(_).to!string so that car wash becomes car_wash and not car___wash ? Use std.string.tr. Bye, bearophile
Re: Removing whitespace duplicates
On Mon, 20 Oct 2014 22:21:09 +, bearophile wrote: Use std.string.tr. Bye, bearophile std.string.squeeze might be more appropriate.
Re: Removing whitespace duplicates
Justin Whear: std.string.squeeze might be more appropriate. But with tr you can also replace the spaces with the underscore. Bye, bearophile
Re: Really in need of help with std.container.array.d
Speaking of this module, since I cannot currently login to bugtracker, I'd like to note here that there are two major bugs in one little function: Array.Payload.length setter. One is this https://issues.dlang.org/show_bug.cgi?id=13619 and the other is reallocating without notifying GC of the pointers, which leads to having dangling pointers in the array after a GC cycle.