What is the alternative to the setlocale function of c in D? Thank you.

2019-01-23 Thread FrankLike via Digitalmars-d-learn
Hi,everyone, for example: import std.stdio; import std.process:executeShell; extern(C) int setlocale(int,char*); static this() { import core.stdc.wchar_; import core.stdc.stdio; fwide(core.stdc.stdio.stdout,1); setlocale(0,cast(char*)"china"); } void main() {

Re: How to ensure string compatibility In D?

2019-01-23 Thread FrankLike via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 14:12:09 UTC, Jonathan M Davis wrote: On Wednesday, January 23, 2019 5:42:55 AM MST FrankLike via std.conv.to will allow you to convert between string and wstring, but for calling C functions, you still need the strings to be zero-terminated unless the functio

Re: std.socket.Address not allowed in tuples

2019-01-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 24 Jan 2019 01:35:57 +, Steven O wrote: > Is there any documentation or examples of how to do that? The > RedBlackTree documentation gives trivial examples like You define a function implementing the "less" operation for a pair of Tuple!(Address, int) (or whatever you have). --- alia

Re: opEquals() non-standard return type

2019-01-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 23 Jan 2019 15:19:06 +, Jacob Shtokolov wrote: > I'm wondering, is that possible to declare multiple versions of > opEquals() and evaluate them in the different places depending on return > type? I looked at this a while ago for similar reasons. It didn't pan out. When you override th

Re: std.socket.Address not allowed in tuples

2019-01-23 Thread Steven O via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 16:30:33 UTC, Neia Neutuladh wrote: As always, it helps a lot to post the error message the compiler gave you. Sorry about that. The issue is that Address doesn't have a comparison operator defined, so the resulting tuple type can't be compared with the stand

Re: opEquals() non-standard return type

2019-01-23 Thread Ali Çehreli via Digitalmars-d-learn
On 01/23/2019 07:19 AM, Jacob Shtokolov wrote: > Expressions like `User.id == 10`, `User.age > 18`, etc. should return a > struct instead of a bool (let's call it `struct BinaryExpression`). Have you considered 'alias this'? struct BinaryExpr(T) { T left; T right; Op op; bool value() c

Re: How to disable/hide constructor when using factory method?

2019-01-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 19:26:37 UTC, JN wrote: class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all users of the class to be forced to create instances using the s

How to disable/hide constructor when using factory method?

2019-01-23 Thread JN via Digitalmars-d-learn
class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all users of the class to be forced to create instances using the static method makeFoo. I want to disallow "new Foo()". But

Re: opEquals() non-standard return type

2019-01-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 23, 2019 at 03:19:06PM +, Jacob Shtokolov via Digitalmars-d-learn wrote: > Hi, > > I'm trying to check whether it's possible to implement Python's > SQLAlchemy-like query syntax in D, but I get stuck a bit. > > Here is a simple example of what I want to achieve: > > ``` > auto r

Re: opEquals() non-standard return type

2019-01-23 Thread Jacob Shtokolov via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 15:28:02 UTC, Jonathan M Davis wrote: But regardless of the specifics of operator overloading in D, D does not support overloading _any_ functions on the return type. Thanks!

Re: std.socket.Address not allowed in tuples

2019-01-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 23 Jan 2019 15:56:15 +, Steven O wrote: > Why am I not allowed to put Address types in tuples? As always, it helps a lot to post the error message the compiler gave you. The message is: /usr/include/dmd/phobos/std/functional.d-mixin-215(215): Error: template std.typecons.Tuple!(Addr

std.socket.Address not allowed in tuples

2019-01-23 Thread Steven O via Digitalmars-d-learn
Can anyone please explain to me what's going on here? import std.container; import std.socket; import std.typecons; void main() { /* Doesn't work alias Rec_type = Tuple!(Address, "x", int, "y", int, "z"); RedBlackTree!Rec_type[] records; */ // Works alias Rec_type = Tup

Re: opEquals() non-standard return type

2019-01-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 23, 2019 8:19:06 AM MST Jacob Shtokolov via Digitalmars-d-learn wrote: > Hi, > > I'm trying to check whether it's possible to implement Python's > SQLAlchemy-like query syntax in D, but I get stuck a bit. > > Here is a simple example of what I want to achieve: > > ``` > auto

opEquals() non-standard return type

2019-01-23 Thread Jacob Shtokolov via Digitalmars-d-learn
Hi, I'm trying to check whether it's possible to implement Python's SQLAlchemy-like query syntax in D, but I get stuck a bit. Here is a simple example of what I want to achieve: ``` auto result = User.filter(User.id == 10); result = User.filter(User.name == "John"); result = User.filter(User.

Re: How to ensure string compatibility In D?

2019-01-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 23, 2019 5:42:55 AM MST FrankLike via Digitalmars-d- learn wrote: > On Wednesday, 23 January 2019 at 10:44:51 UTC, Jonathan M Davis > > wrote: > > On Tuesday, January 22, 2019 2:49:00 PM MST bauss via > > Digitalmars-d-learn wrote: > > > > toUTFz is the generic solution. toStr

recursive tagging pointer structure

2019-01-23 Thread Alex via Digitalmars-d-learn
Is there a possibility to create a recursive structure with a tagged pointer? As this does not compile, even without tagging bits. ´´´ import std.experimental.all; void main(){} struct A { size_t dummy; mixin(taggedPointer!( A*, "x" /*, bool, "b1", 1, b

Re: How to ensure string compatibility In D?

2019-01-23 Thread FrankLike via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 10:44:51 UTC, Jonathan M Davis wrote: On Tuesday, January 22, 2019 2:49:00 PM MST bauss via Digitalmars-d-learn wrote: toUTFz is the generic solution. toStringz exists specifically Error: template std.utf.toUTFz cannot deduce function from argument types !()

Re: How to ensure string compatibility In D?

2019-01-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 22, 2019 2:49:00 PM MST bauss via Digitalmars-d-learn wrote: > On Tuesday, 22 January 2019 at 19:14:43 UTC, Jonathan M Davis > > wrote: > > On Tuesday, January 22, 2019 12:05:32 PM MST Stefan Koch via > > > > Digitalmars-d- learn wrote: > >> On Tuesday, 22 January 2019 at 16:47