extended characterset output

2022-04-07 Thread anonymous via Digitalmars-d-learn
What's the proper way to output all characters in the extended character set? ```d void main() { foreach(char c; 0 .. 256) { write(isControl(c) ? '.' : c); } } ``` Expected output: ``` !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX

Re: extended characterset output

2022-04-08 Thread anonymous via Digitalmars-d-learn
On Friday, 8 April 2022 at 08:36:33 UTC, Ali Çehreli wrote: On 4/7/22 23:13, anonymous wrote: > What's the proper way to output all characters in the extended character > set? It is not easy to answer because there are a number of concepts here that may make it trivial or complicated. The con

Re: extended characterset output

2022-04-08 Thread anonymous via Digitalmars-d-learn
On Friday, 8 April 2022 at 08:36:33 UTC, Ali Çehreli wrote: [snip] However, isControl() below won't work because isControl() only knows about the ASCII table. It would miss the unprintable characters above 127. [snip] This actuall works because I'm using std.uni.isControl() instead of std.asc

Re: extended characterset output

2022-04-08 Thread anonymous via Digitalmars-d-learn
On Friday, 8 April 2022 at 15:06:41 UTC, Ali Çehreli wrote: On 4/8/22 02:51, anonymous wrote: > Weird, I got this strange feeling that this problem stemmed from the > compiler I'm using (GDC) Some distribution install an old gdc. What version is yours? Ali Not sure actually. I just did "apt

Re: Get pointer or reference of an element in Array(struct)

2017-12-08 Thread anonymous via Digitalmars-d-learn
On Saturday, 9 December 2017 at 06:15:16 UTC, Arun Chandrasekaran wrote: Is there a way to get the pointer or reference of an element in Array(T)? [...] auto d2 = gallery[0]; auto d2 = &gallery[0];

Re: Ternary if and ~ does not work quite well

2015-10-11 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 07:23, Rikki Cattermole wrote: > On 12/10/15 6:19 PM, Andre wrote: [...] >> // assert("foo "~ true ? "bar" : "baz" == "foo bar"); does not compile [...] > I read it as: > > assert("foo "~ (true ? ("bar") : ("baz" == "foo bar"))); > > Oh hey look: > /d434/f138.d(6)

Re: Class, constructor and inherance.

2015-10-11 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 07:28, Ali Çehreli wrote: > For example, you cannot get current time at run time. I think you mean compile time here.

Re: Ternary if and ~ does not work quite well

2015-10-12 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 17:39, TheFlyingFiddle wrote: > "foo" ~ true > > How does this compile? All i can see is a user trying to append a > boolean to a string which is obvously a type error. Or are they > converted to ints and then ~ would be a complement operator? In > that case.. horror.

Re: DMD Compiler 'switches'

2015-10-12 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 17:38, ric maicle wrote: > I'm wondering if this small irregularity should be made consistent or > maybe I misunderstood something. As far as I know, the difference just happened, and there is point to it. The style without "=" is older and wasn't followed when new swi

Re: DMD Compiler 'switches'

2015-10-12 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 19:46, anonymous wrote: > and there is point to it Ugh, should have been: and there is *no* point to it.

Re: Regarding std.array.Appender

2015-10-13 Thread anonymous via Digitalmars-d-learn
On Tuesday 13 October 2015 15:42, Suliman wrote: > map!(a=> a~=" +") work fine, but how to add before > at same time? Use ~ instead of ~=, like so: map!(a => "+" ~ a ~ "+")

Re: Regarding std.array.Appender

2015-10-13 Thread anonymous via Digitalmars-d-learn
On Tuesday 13 October 2015 15:47, Suliman wrote: > something like: auto content = file.byLine.map!("start " ~ a=>a ~ > " end"); That's not how it works at all. Maybe stick to the examples of whatever resource you're learning from, for now.

Re: Struct toString works but not std.conv.to!string

2015-10-13 Thread anonymous via Digitalmars-d-learn
On Tuesday, 13 October 2015 at 22:21:43 UTC, Ali Çehreli wrote: Reduced with a workaround: struct UTCOffset { import std.conv : to;// Move to module scope to compile This introduces UTCOffset.to as an alias to std.conv.to. string toString() const { return "hello";

Re: Builtin array and AA efficiency questions

2015-10-15 Thread anonymous via Digitalmars-d-learn
On Thursday, October 15, 2015 11:48 PM, Random D user wrote: > Should array have clear() as well? > Basically wrap array.length = 0; array.assumeSafeAppend(); > At least it would then be symmetric (and more intuitive) with > built-in containers. No. "clear" is too harmless a name for it to invol

Re: Why can't function expecting immutable arg take mutable input?

2015-10-16 Thread anonymous via Digitalmars-d-learn
On Friday, October 16, 2015 12:35 PM, Shriramana Sharma wrote: > Why can't a function that takes an immutable argument be called with a > mutable input at the call site? > > IOW, why isn't mutable implicitly convertible to immutable? immutable says that the data won't ever change. If references

Re: Idiomatic adjacent_difference

2015-10-16 Thread anonymous via Digitalmars-d-learn
On Friday, October 16, 2015 02:03 PM, Per Nordlöw wrote: > zip(r, r.dropOne).map!((t) => t[1]-t[0]); You should r.save one or both of those. The dropOne may affect both instances if you don't .save. By the way, what's the point of `dropOne` over `drop(1)`? It's not shorter. Does it do anything

Re: what is wrong with this code??

2015-10-17 Thread anonymous via Digitalmars-d-learn
On Saturday, October 17, 2015 04:17 PM, steven kladitis wrote: > // it thows a range exception On which line?

Re: what is wrong with this code??

2015-10-17 Thread anonymous via Digitalmars-d-learn
On Saturday, October 17, 2015 04:50 PM, steven kladitis wrote: > core.exception.RangeError@sokuban.d(84): Range violation Line 84 being this: sDataBuild ~= sMap[ch]; Where sMap is: /*static*/ immutable sMap = [' ':' ', '.':'.', '@':' ', '#':'#', '$':' '];

Re: Compiling a .d file both as library and executable

2015-10-17 Thread anonymous via Digitalmars-d-learn
On Saturday, October 17, 2015 05:36 PM, Shriramana Sharma wrote: > In Python there is: > > if __name__ == "__main__": > > to allow the same source file to be treated as both an importable library > and as an executable script. In D is there any such mechanism to make a > main() compiled selectiv

Re: Enough introspection to report variable name of calling argument

2015-10-19 Thread anonymous via Digitalmars-d-learn
On Monday, October 19, 2015 04:14 PM, Handyman wrote: > Is the following possible in D? To call a (unary) function f > with variable a, and let f print: > >> Called with argument named 'a'. > > I am of course asking for a generic solution, independent of the > actual variable name (in this case

Re: Check Instance of Template for Parameter Type/Value

2015-10-19 Thread anonymous via Digitalmars-d-learn
On Monday, October 19, 2015 04:51 PM, Stewart Moth wrote: > struct Vector(type, int dimension_){ ... } > > Where type is going to be an int/float/etc and dimension_ is > 2/3/4. > > I could write a bunch of functions for each case, but I'd rather > not... I'd like to use something like the follow

Re: Overloading an imported function

2015-10-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, October 21, 2015 02:05 PM, Shriramana Sharma wrote: > When I've imported std.math which contains round(real), why is the > compiler complaining about not being able to call the overload function > defined in *this* module? The functions don't form an overload set. You need to bring

Re: can't zip a char[5], string[5], real[5]

2015-10-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, 21 October 2015 at 14:06:54 UTC, Shriramana Sharma wrote: import std.stdio, std.range; void mywrite(char [5] chars, real[5] vals) { static string [5] fmts = ["%9.4f, ", "%9.4f; ", "%3d, ", "%3d, ", "%3d\n"]; foreach (e; zip(chars, fmts, vals)) write(e[0], " = ", e[1].forma

Re: Implicit conversion rules

2015-10-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, October 21, 2015 07:53 PM, Sigg wrote: > void func() { > int a = -10; > ulong b = 0; > ulong c = a + b; > writefln("%s", c); > } > > out: 18446744073709551574 > > But shouldn't declaring c as auto force compiler to go extra step >

Re: Overloading an imported function

2015-10-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, October 21, 2015 08:28 PM, Shriramana Sharma wrote: > Kagamin wrote: > >> http://dlang.org/hijack.html > > Thanks people, but even as per the rules: > > 1. Perform overload resolution independently on each overload set > 2. If there is no match in any overload set, then error > 3.

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On Thursday, October 22, 2015 08:10 PM, Nordlöw wrote: > How do I convert a `string` containing Unicode escape sequences > such as "\u" into UTF-8? Ali explained that "\u" is already UTF-8. But if you actually want to interpret such escape sequences from user input or some such, then fi

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On 22.10.2015 21:13, Nordlöw wrote: Hmm, why isn't this already in Phobos? I think parsing only Unicode escape sequences is not a common task. You usually need to parse some larger language of which escape sequences are only a part. For example, parsing JSON or XML are common tasks, and we h

Re: Overloading an imported function

2015-10-22 Thread anonymous via Digitalmars-d-learn
On 22.10.2015 06:14, Shriramana Sharma wrote: anonymous wrote: Huh. I can't find any specification on this, but apparently the local overload set shadows any imported overload sets completely. Should I file a bug on this then? I'm not sure. Maybe make a thread on the main group first. It's

Re: `clear`ing a dynamic array

2015-10-24 Thread anonymous via Digitalmars-d-learn
On 24.10.2015 15:18, Shriramana Sharma wrote: int a[] = [1,2,3,4,5]; Aside: `int[] a;` is the preferred style for array declarations. How to make it so that after clearing `a`, `b` will also point to the same empty array? IOW the desired output is: [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [] [] .

Re: `clear`ing a dynamic array

2015-10-25 Thread anonymous via Digitalmars-d-learn
On Sunday, 25 October 2015 at 11:45:53 UTC, Shriramana Sharma wrote: http://dlang.org/arrays.html#resize says: """Also, you may wish to utilize the phobos reserve function to pre-allocate array data to use with the append operator.""" I presume this means http://dlang.org/phobos/std_array.htm

Re: Merging two named Tuples

2015-10-29 Thread anonymous via Digitalmars-d-learn
On 29.10.2015 19:59, Edwin van Leeuwen wrote: On Saturday, 24 October 2015 at 11:04:14 UTC, Edwin van Leeuwen wrote: I am trying to write a function to merge two named structs, but am completely stuck on how to do that and was wondering if anyone good provide any help. I know I can access the di

Re: Static constructors in structs.

2015-10-30 Thread anonymous via Digitalmars-d-learn
On 30.10.2015 21:23, TheFlyingFiddle wrote: Is this intended to work? struct A { __gshared static this() { //Add some reflection info to some global stuff. addReflectionInfo!(typeof(this)); } } I just noticed this works in 2.069, is this intended? static constructors

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-01 Thread anonymous via Digitalmars-d-learn
On 01.11.2015 23:49, Adam D. Ruppe wrote: Yeah, just make the other args normal runtime instead of template: Or make it two nested templates: template show(T ...) { void show(string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__)() { ... } }

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:30, Handyman wrote: Seems that 4 cores go all out on first 4 dishes, then 1 core deals with the last dish. With 4 cores I expect diner is ready after 5/4 = 1.25 secs though. What did I do wrong? You describe the situation correctly. The unit of work is a dish. That is, the w

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:43, Handyman wrote: foreach (i; 0..50) Thread.sleep(20.msecs); But then my program still says: '2 secs'. Please enlighten me. Let's look at the line that does the `parallel` call: foreach (dish; parallel(dishes, 1)) dish.prepare(); This means that `dishes` is proce

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:52, Handyman wrote: On Thursday, 5 November 2015 at 20:45:25 UTC, Ali Çehreli wrote: That's still 1 second per task. The function prepare() cannot be executed by more than one core. Thanks. OK. So 'prepare' is atomic? Then let's turn it around: how can I make the cores prep

Re: struct constructor co nfusion

2015-11-06 Thread anonymous via Digitalmars-d-learn
On 06.11.2015 20:05, Spacen Jasset wrote: Also, I had to add a dummy private constructor to make my structs 'createable', or is there another way? e.g. struct Texture { @disable this(); static Texture create() { return Texture(0); } ... private: this(int) {

Re: opCmp with structs

2015-11-07 Thread anonymous via Digitalmars-d-learn
On 07.11.2015 15:36, Mike Parker wrote: It's actually possible to use move one instance into another, though: void main() { import std.algorithm : move; ku k1 = ku(1); ku k2 = ku(2); k2.move(k1); assert(k1.id == 2); } Wat. It even compiles with @safe. That's not good.

Re: Error not callable with argument types but types matches

2015-11-08 Thread anonymous via Digitalmars-d-learn
On 08.11.2015 08:17, Sliya wrote: I am on Mac OS, but I still don't get it. If the import was not case-sensitive, I would not have any error since the good file would have been loaded... Here I have no error saying file not found yet the file is not loaded. I'd love to know what really happens.

Re: opCmp with structs

2015-11-10 Thread anonymous via Digitalmars-d-learn
On 07.11.2015 16:59, anonymous wrote: Wat. It even compiles with @safe. That's not good. Filed an issue: https://issues.dlang.org/show_bug.cgi?id=15315

Re: Compiler doesn't complain with multiple definitions

2015-11-12 Thread anonymous via Digitalmars-d-learn
On 12.11.2015 06:27, ric maicle wrote: I was playing with __traits and tried the code below. Shouldn't the compiler emit a warning that I'm defining isPOD multiple times and/or I'm defining something that is built-in like isPOD? // DMD64 D Compiler v2.069 import std.stdio; struct isPOD { bool s

Re: A new instance of a variable?

2015-11-13 Thread anonymous via Digitalmars-d-learn
On 13.11.2015 18:44, Ish wrote: immutable int* j = new immutable int(i); gives error: locks1.d:27: error: no constructor for immutable(int); Looks like your D version is rather old. I had to go back to dmd 2.065 to see that error. 2.065 is from February 2014. We're at 2.069 now. I'd recommend

Bug? Bad file name?

2015-11-13 Thread Anonymous via Digitalmars-d-learn
I was playing with some code someone posted on the forum that involved opDispatch and compile time parameters. I pasted it in a file named templOpDispatch.d, ran it, and got an error. Then I noticed if I renamed the file it worked. The source didn't matter; same thing happens with an empty mai

Re: I can't believe this !!

2015-11-13 Thread anonymous via Digitalmars-d-learn
On 14.11.2015 07:30, MesmerizedInTheMorning wrote: https://issues.dlang.org/show_bug.cgi?id=15331 but it's true ! There's **nothing** to check the availability of a Key. At least I would expect opIndex[string key] to return a JSONValue with .type == JSON_TYPE.NULL, but no... Also If it was ret

Re: std.conv.to!string(array), strange compile error

2015-11-14 Thread anonymous via Digitalmars-d-learn
On 14.11.2015 15:17, Relja wrote: - std.conv.to!string() works on a static array, when called directly on the array object, but gives the compile error when called on the returning object from a function. [...] void main() { getFloat3().to!string; // does not compile (new float[3]).to

Re: std.conv.to!string(array), strange compile error

2015-11-14 Thread anonymous via Digitalmars-d-learn
On 14.11.2015 15:40, Relja wrote: float[3] array; array.to!string; // compiles Alright, full test case: import std.conv; float[3] getFloat3() { return [1, 2, 3]; } void main() { getFloat3().to!string; // does not compile float[3] a; a.to!string; // compiles } Yeah,

Re: Am I using std.encoding correctly?

2015-11-14 Thread anonymous via Digitalmars-d-learn
On 14.11.2015 15:55, Charles wrote: I know there's safeDecode, but I'm also fairly confident that all strings can decode safely, already, and if it isn't I'd want an exception thrown from it. Documentation [1] says "The input to this function MUST be validly encoded." It says nothing about an

Re: Filtering a tuple of containers with indices

2015-11-17 Thread anonymous via Digitalmars-d-learn
On 17.11.2015 15:32, maik klein wrote: template tupIndexToRange(alias Tup, Indices...){ [snip] I don't quite understand how that code is supposed to work. Maybe there's just some detail missing, but it could also be that your approach can't work. This is roughly what I want to achieve

Re: Filtering a tuple of containers with indices

2015-11-17 Thread anonymous via Digitalmars-d-learn
On 17.11.2015 20:46, maik klein wrote: .selectFromTuple!(0, 1).expand Does this result in a copy? I avoided doing it like this because I was worried that I would copy every array. But I also don't fully understand when D will copy. Yes and no. It copies the Array structs, but it does not copy

Re: char[] == null

2015-11-18 Thread anonymous via Digitalmars-d-learn
On 18.11.2015 22:02, rsw0x wrote: slices aren't arrays http://dlang.org/d-array-article.html The language reference/specification [1] uses the term "dynamic array" for T[] types. Let's not enforce a slang that's different from that. [1] http://dlang.org/arrays.html

Re: char[] == null

2015-11-18 Thread anonymous via Digitalmars-d-learn
On 19.11.2015 06:18, Chris Wright wrote: Just for fun, is an array ever not equal to itself? Yes, when it contains an element that's not equal to itself, e.g. NaN.

Re: RAII trouble

2015-11-20 Thread anonymous via Digitalmars-d-learn
On 20.11.2015 23:56, Spacen Jasset wrote: The ideal would be to have a struct that can be placed inside a function scope, or perhaps as a module global variable. Why does Ft_Init_FreeType have to be read at compile time? text.d(143,15): Error: static variable FT_Init_FreeType cannot be read at

Re: How to use D parallel functions/library

2015-11-24 Thread anonymous via Digitalmars-d-learn
On 24.11.2015 19:49, Bishop120 wrote: I figured this would be a simple parallel foreach function with an iota range of sizeX and just making int X declared inside the function so that I didnt have to worry about shared variable but I cant get around the alive++ reduction and I dont understand eno

Re: switch with enum

2015-11-25 Thread anonymous via Digitalmars-d-learn
On 25.11.2015 21:06, Meta wrote: ...Which doesn't work because it won't compile without a default case. Is this a recent change? I don't remember D doing this before. Use `final switch`. Ordinary `switch`es need an explicit default case. `final switch`es have to cover all possibilities individ

Re: EnumMemberNames

2015-11-27 Thread anonymous via Digitalmars-d-learn
On 27.11.2015 15:05, drug wrote: I need to get names of enum members, is it possible? EnumMembers returns the members itself, i.e. ``` enum Sqrts : real { one = 1, two = 1.41421, three = 1.73205, } pragma(msg, [EnumMembers!Sqrts]); ``` returns [1.0L,

Re: Can't understand how to do server response with vibed

2015-11-28 Thread anonymous via Digitalmars-d-learn
On 28.11.2015 19:46, Suliman wrote: And the second question. Why I am getting next error after attempt to write to console JSON request: Error: cannot resolve type for res.writeJsonBody(T)(T data int status = HTTPStatus.OK, string content_type = "application/json; charset=UF-8", bool allow_chunk

Re: Can't understand how to do server response with vibed

2015-11-28 Thread anonymous via Digitalmars-d-learn
On 28.11.2015 19:51, Suliman wrote: Eghm, sorry. Not req, but res, but again errr: void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(req.writeJsonBody); } Error: no property 'writeJsonBody' for type 'vibe.http.server.HTTPServerRequest' But this method are present in doc

Re: DateTime.opBinary

2015-11-29 Thread anonymous via Digitalmars-d-learn
On 30.11.2015 00:25, bachmeier wrote: I was just reading through the documentation for std.datetime. DateTime.opBinary looks pretty interesting: http://dlang.org/phobos/std_datetime.html#.DateTime.opBinary Does anyone know how to use it? You certainly can't learn anything from the documentation

Re: having problem with `std.algorithm.each`

2015-11-30 Thread anonymous via Digitalmars-d-learn
On 30.11.2015 11:50, visitor wrote: though i don"t understand why it fails silently ?? ref2491's original code is valid, but doesn't have the intended meaning. `e => {foo(e);}` is the same as `(e) {return () {foo(e);};}`, i.e. a (unary) function that returns a (nullary) delegate. Calling it d

Re: DDOC adds emphasis on symbols, so how to use $(LINK a) properly?

2015-12-01 Thread anonymous via Digitalmars-d-learn
On 01.12.2015 16:15, kraybit wrote: /** * Also see $(LINK mylib.image.pixel.html) */ module mylib; ... This will generate a link, but the href will be "mylib.image.pixel.html", which won't work in my browser at least (Chromium). This can be fixed with: $(LINK _m

Re: DDOC adds emphasis on symbols, so how to use $(LINK a) properly?

2015-12-01 Thread anonymous via Digitalmars-d-learn
On 01.12.2015 16:52, kraybit wrote: Hm, I see, so it's contextual? Would 'pixel' then be emphasized if I'm in the documentation of void pixel()? Yes and yes. I just get the feeling I need to think before using LINK. I'd like to not think, too much. It's a clever feature for sure. Maybe too

Re: benchmark on binary trees

2015-12-04 Thread anonymous via Digitalmars-d-learn
On 04.12.2015 15:06, Alex wrote: 1. I wrote the C++ inspired version after the C# inspired, hoping it would be faster. This was not the case. Why? [...] Why did you expect the C++ inspired version to be faster? Just because the original was written in C++? From a quick skim the two versions

Re: benchmark on binary trees

2015-12-04 Thread anonymous via Digitalmars-d-learn
On 04.12.2015 21:30, Alex wrote: Yes, I missed this, sorry. The main part of the question was probably about the class and struct difference. I thought handling with structs and pointers would be faster then with classes. When you use a struct directly, without going through a pointer, that ca

Re: benchmark on binary trees

2015-12-04 Thread anonymous via Digitalmars-d-learn
On 04.12.2015 15:06, Alex wrote: 3. The compilation was done by: dmd -O -release -boundscheck=off [filename.d] Is there anything else to improve performance significantly? You forgot -inline. By the way, I'm not a fan of using -boundscheck=off like a general optimization flag. It undermines @

Re: benchmark on binary trees

2015-12-05 Thread anonymous via Digitalmars-d-learn
On 05.12.2015 01:40, Alex wrote: found and tried out the -vgc option... Is there a way to deactivate the GC, if it stands in way? You can call core.memory.GC.disable to disable automatic collections. .enable to turn them on again. http://dlang.org/phobos/core_memory.html#.GC Yes, I thought

Re: using parse with string slice

2015-12-05 Thread anonymous via Digitalmars-d-learn
On 05.12.2015 22:59, Quentin Ladeveze wrote: --- import std.conv; string s = "1B2A"; int value = parse!int(s[0..2], 16); //template std.conv.parse cannot deduce function from argument types !(int)(string, int) --- Does someone have an idea of why it happens ? The version of parse that is used

Re: Comparison operator overloading

2015-12-07 Thread Anonymous via Digitalmars-d-learn
On Monday, 7 December 2015 at 17:18:20 UTC, Dominikus Dittes Scherkl wrote: Hmm. But it works just fine! It overloads also the special floatingpoint operators <> !<> !<= and so on. Those are deprecated: http://dlang.org/deprecate.html#Floating%20point%20NCEG%20operators And how else could I

Re: The @@@BUG@@@ the size of China - std.conv.d - Target parse(Target, Source)(ref Source s, uint radix)

2015-12-07 Thread anonymous via Digitalmars-d-learn
On 07.12.2015 21:56, John Carter wrote: So whilst attempt to convert from a hex string (without the 0x) to int I bumped into the @@@BUG@@@ the size of China https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L2270 Is there a bugzilla issue number tracking this? Search

Re: How to check if result of request to DB is empty?

2015-12-11 Thread anonymous via Digitalmars-d-learn
On 11.12.2015 22:05, Suliman wrote: I am using https://github.com/buggins/ddbc string query_string = (`SELECT user, password FROM otest.myusers where user LIKE ` ~ `'%` ~ request["username"].to!string ~ `%';`); Don't piece queries together without escaping the dynamic parts. Imagine what happ

Re: How to check if result of request to DB is empty?

2015-12-12 Thread anonymous via Digitalmars-d-learn
On 12.12.2015 08:44, Suliman wrote: string query_string = (`SELECT user, password FROM otest.myusers where user LIKE ` ~ `'%` ~ request["username"].to!string ~ `%';`); Don't piece queries together without escaping the dynamic parts. Imagine what happens when the user enters an apostrophe in the

Re: isBidirectionalRange fails for unknown reasons

2015-12-16 Thread anonymous via Digitalmars-d-learn
On 16.12.2015 21:43, Jack Stouffer wrote: I'm trying to add a ReferenceBidirectionalRange range type to std.internal.test.dummyrange so I can test some range code I'm writing, but I've hit a wall and I'm not sure why. For some reason, the isBidirectionalRange check fails even though back and popB

Re: D float types operations vs C++ ones

2015-12-17 Thread anonymous via Digitalmars-d-learn
On 17.12.2015 12:50, drug wrote: I have two implementation of the same algorithm - D and C++ (that is port of D version). I assume that running these implementations on the same data should give the same results from both. But with some data the results differ (5th decimal digit after point). For

Re: Problems with string literals and etc.c.odbc.sql functions

2015-12-18 Thread anonymous via Digitalmars-d-learn
On 18.12.2015 23:14, Fer22f wrote: By the use of this tutorial (http://www.easysoft.com/developer/languages/c/odbc_tutorial.html), I thought it would be very straightforward to use etc.c.odbc.sqlext and etc.c.odbc.sql to create a simple odbc application. But as soon as I started, I noticed a quir

Re: Problems with string literals and etc.c.odbc.sql functions

2015-12-18 Thread anonymous via Digitalmars-d-learn
On 19.12.2015 01:06, Fer22f wrote: Documentation on casts say: Casting a pointer type to and from a class type is done as a type paint (i.e. a reinterpret cast). That sentence doesn't apply. string is not a class, it's an alias for immutable(char)[], i.e. it's an array. Reinterpretation i

Re: Problems with string literals and etc.c.odbc.sql functions

2015-12-19 Thread anonymous via Digitalmars-d-learn
On 19.12.2015 14:20, Marc Schütz wrote: As this is going to be passed to a C function, it would need to be zero-terminated. `.dup` doesn't do this, he'd have to use `std.string.toStringz` instead. However, that function returns a `immutable(char)*`, which would have to be cast again :-( Ouch, I

Re: What other than a pointer can be converted implicitly to const(char)*?

2015-12-21 Thread anonymous via Digitalmars-d-learn
On 21.12.2015 17:02, Shriramana Sharma wrote: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L878 The `static if` condition here says if something is a pointer and if it is implicitly convertible to const(char)*. The isPointer! part seems superfluous. Is there something

Re: What other than a pointer can be converted implicitly to const(char)*?

2015-12-21 Thread anonymous via Digitalmars-d-learn
On 21.12.2015 21:20, Steven Schveighoffer wrote: This seems like an incorrect feature then. Why wouldn't I want S to be treated like any other const(char)*? Seems like it's explicitly saying "treat this like a const(char)*" To my understanding, `alias this` means "is implicitly convertible to

Re: Understand typeof trick

2015-12-25 Thread anonymous via Digitalmars-d-learn
On 25.12.2015 13:10, Joakim Brännström wrote: In http://forum.dlang.org/post/ojawnpggfaxevqpmr...@forum.dlang.org Adam uses findSkip as an example and especially points out the "D idiom with is/typeof". I'm not quite sure I understand it correctly. Please correct me if I have misunderstood anyth

Re: DMD -L Flag, maybe a bug?

2015-12-25 Thread anonymous via Digitalmars-d-learn
On 25.12.2015 15:40, Bubbasaur wrote: But at least on Windows, you need to put a space between -L and the PATH. Which It's weird, since with "-I" flag you don't need any space. I don't think that's right. Unless something awful is going in Windows dmd, that should be processed as two separate

Re: DMD -L Flag, maybe a bug?

2015-12-25 Thread anonymous via Digitalmars-d-learn
On 25.12.2015 19:32, Bubbasaur wrote: On Friday, 25 December 2015 at 15:06:27 UTC, anonymous wrote: In fact it works without the "-L". Which makes me wonder if I was using it wrongly? I'm convinced that putting a space between "-L" and its argument is nonsense. The "-L" part just means "pass t

Re: DMD -L Flag, maybe a bug?

2015-12-26 Thread anonymous via Digitalmars-d-learn
On 26.12.2015 02:04, Bubbasaur wrote: On Friday, 25 December 2015 at 23:45:42 UTC, anonymous wrote: It's almost like the example in the URL you showed: dmd test.d -LC:/gtkd/src/build/GtkD.lib Note that in the docs I linked it's `dmd hello.d -L+gtkd.lib` with a plus sign. I'm not sure if it's

Re: regex - match/matchAll and bmatch - different output

2016-01-01 Thread anonymous via Digitalmars-d-learn
On 30.12.2015 12:06, Ivan Kazmenko wrote: import std.regex, std.stdio; void main () { writeln (bmatch ("abab", r"(..).*\1")); // [["abab", "ab"]] writeln (match("abab", r"(..).*\1")); // [["abab", "ab"]] writeln (matchAll ("abab", r"(..).*\1")); // [["abab", "ab"]]

Re: Deducing a template argument from an aliased parameter

2016-01-01 Thread anonymous via Digitalmars-d-learn
On 31.12.2015 23:37, rcorre wrote: struct Vector(T, int N) { } alias Vector2(T) = Vector!(T, 2); void fun1(T)(Vector!(T, 2) vec) { } void fun2(T)(Vector2!T vec) { } unittest { fun1(Vector!(float, 2).init); fun2(Vector!(float, 2).init); } Why can fun1 deduce `T`, but fun2 can't? Failure:

Re: Call C function - Access violation

2016-01-03 Thread anonymous via Digitalmars-d-learn
On 03.01.2016 13:30, TheDGuy wrote: I get an access violation with this code: extern(C) char* write(char* text); void main(string[] args){ char[] text = "Hello World".dup; //.dup converts string to char[] text ~= '\0'; //append char* result = write(text.ptr); //you need .ptr

Re: Call C function - Access violation

2016-01-03 Thread anonymous via Digitalmars-d-learn
On 03.01.2016 14:01, TheDGuy wrote: Okay, i think this C code should work (checked with cpp.sh): #import char* write(char* text){ return text; } int main(void){ return 0; } Uh, no. 1) In C it's include, not import. 2) Now you have two main functions, that can't work. You shouldn'

Re: Call C function - Access violation

2016-01-03 Thread anonymous via Digitalmars-d-learn
On 03.01.2016 14:12, anonymous wrote: You shouldn't get a segfault, though. You should get some compile/link error. Are you compiling the right files? Can the segfault be from something other than your program? Oh, I see what's probably happening: You compile the D program, but you don't compi

Re: Repeated struct definitions for graph data structures and in/out naming conflict in C library

2016-01-03 Thread anonymous via Digitalmars-d-learn
On 03.01.2016 14:30, data pulverizer wrote: I am trying to access functionality in the glpk C library using extern(C). It has graph structs in its header file that are specified in an odd recurring manner that I cannot reproduce in D: I don't see what's odd about this. What exactly are your str

Re: Call C function - Access violation

2016-01-03 Thread anonymous via Digitalmars-d-learn
On 03.01.2016 21:32, TheDGuy wrote: If i type: gcc -c -otest.c.o the 'test.c.o' file is generated but if i type: dmd main.d test.c.o i get: 'Error: unrecognized file extension o'? You're probably on Windows then? dmd doesn't recognize the .o extension on Windows, use .obj instead.

Re: Call C function - Access violation

2016-01-03 Thread anonymous via Digitalmars-d-learn
On 03.01.2016 22:37, TheDGuy wrote: If i rename "test.o" to "test.obj" i get: 'Error: Module or Dictionary corrupt' My guess is, that means that dmd can't handle the object file format that gcc produces. Disclaimer: I don't know much about object formats, gcc, and Windows. I may be mistake

Re: to!double different from cast(double)

2016-01-04 Thread anonymous via Digitalmars-d-learn
On 04.01.2016 09:22, Ali Çehreli wrote: void main() { const l = long.max; assert(l != l.to!double); // passes assert(l != cast(double)l);// FAILS } Is there a good explanation for this difference? I would expect both expressions to be compiled the same way. (I am aware t

Re: Nothrow front() when not empty()

2016-01-06 Thread anonymous via Digitalmars-d-learn
On 06.01.2016 14:52, Nordlöw wrote: At https://github.com/D-Programming-Language/phobos/pull/3752 it would be nice if return !haystack.empty && haystack.front.unaryFun!pred was made nothrow. Is this possible somehow? try return !haystack.empty && pred(haystack.front); catch (Exce

Re: About Immutable struct members and arrays.

2016-01-06 Thread anonymous via Digitalmars-d-learn
On 06.01.2016 23:04, Jack Applegame wrote: import std.algorithm; struct Bar { const int a; int b; } void main() { Bar[1] arr; Bar bar = Bar(1, 2); bar[0].b = 4; Assuming you meant `arr[0].b = 4;`. Just overwriting the mutable part of bar[0] is ok, of course.

Re: [Dlang] Delegate Syntax Question

2016-01-10 Thread anonymous via Digitalmars-d-learn
On 10.01.2016 15:32, Jack wrote: // class Foo() Those parentheses make this a (zero parameter) class template. I suppose you just want a plain class. Drop them then. { void bar() { writeln("Hello World"); } } class Bar() ditto { void d

Re: How to declare an alias to a function literal type

2016-01-12 Thread anonymous via Digitalmars-d-learn
On 12.01.2016 16:41, ParticlePeter wrote: // alias MF = void function( int i ); // not working // alias void function( int i ) MF; // not working These are both fine. The first one is the preferred style. MF myFunc; myFunc = MF { myCode }; This line doesn't work. Function literals don't

Re: How to declare an alias to a function literal type

2016-01-12 Thread anonymous via Digitalmars-d-learn
On 12.01.2016 17:55, ParticlePeter wrote: When I pass a parameter to otherFunc I use this syntax for an anonymous function parameter: otherFunc( void function( ref int p1, float p2, ubyte p3 ) { myCode; } ); You don't. That's not valid code. You can be using this: otherFunc( function void ( r

Re: Index a parameter tuple with a run-time index

2016-01-15 Thread anonymous via Digitalmars-d-learn
On 15.01.2016 21:42, Nordlöw wrote: How do I index a function parameter tuple with a run-time index? With a switch and a static foreach: void f(A...)(size_t i, A a) { import std.stdio: writeln; switch_: switch (i) { foreach (iT, T; A) { case iT: wri

Re: Functions that return type

2016-01-16 Thread anonymous via Digitalmars-d-learn
On Saturday, 16 January 2016 at 21:22:15 UTC, data pulverizer wrote: Is it possible to create a function that returns Type like typeof() does? Something such as: Type returnInt(){ return int; } No. A function cannot return a type. A template can evaluate to a type, though: templat

copying directories recursively

2016-01-17 Thread anonymous via Digitalmars-d-learn
TL;DR: Is there a simple way to copy directories recursively? My goal is to copy the directories ./src/dlang.org/{css,images,js} and their contents to ./ddo/{css,images,js}. Naively I tried this: void main() { import file = std.file; auto outputPath = "./ddo/"; foreach (dir;

Re: Unions and Structs

2016-01-18 Thread anonymous via Digitalmars-d-learn
On 18.01.2016 18:10, Russel Winder via Digitalmars-d-learn wrote: So this is an error? union flob { ulong data; struct thingy { uint data; uint bits; } thingy burble; }; because you cannot have a union field with a name that is als

Re: writeln wipes contents of variables ?

2016-01-21 Thread anonymous via Digitalmars-d-learn
On 22.01.2016 01:49, W.J. wrote: How can I identify those ranges, or, how can I tell if any particular range has value semantics ? I didn't read any of this in the manual - not that I could remember anyways. Generally you shouldn't. If you care about it either way, use .save or std.range.refRa

  1   2   3   4   5   6   >