Re: Get function argument name?

2018-03-04 Thread Timothee Cour via Digitalmars-d-learn
`printName(alias var)()` is not a great solution, eg: doesn't work with expressions, doesn't work with variadics, introduces template bloat. https://github.com/dlang/dmd/pull/7821 introduces __traits(getCallerSource, symbol) which will allow what you want. On Sun, Mar 4, 2018 at 1:53 PM, bauss vi

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-22 Thread Timothee Cour via Digitalmars-d-learn
also related: https://github.com/Syniurge/Calypso/issues/85 (feasibility of extending calypso to do source to source translation (eg C++ => D or C=>D) ) On Thu, Feb 22, 2018 at 12:43 AM, ketmar via Digitalmars-d-learn wrote: > Nick Sabalausky (Abscissa) wrote: > >> Are there any tutorials or art

Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
makes sense to show these (version X11), but that could be done using dmd and a special flag instead of having to rely on a new parser (which would need to be kept updated) On Thu, Feb 8, 2018 at 6:49 AM, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 8 February 2018 at 09:42:08 UT

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
I know that, my question is whether it adds any runtime overhead over naive way (which is to call the "bar" finalizer before each return statement) in the case where no exception is thrown On Thu, Feb 8, 2018 at 2:44 AM, Mike Parker via Digitalmars-d-learn wrote: > On Thursday, 8 February 2018

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
likewise, will scope(exit) add any overhead over naive code in the case where no exception is thrown? ``` void fun(){ ... scope(success) {bar;} ... } vs void fun(){ ... if(foo1){ bar; // add this before each return return; } ... bar; return; } ``` On Thu, Feb 8, 2018

are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
I'm curious whether scope guards add any cost over the naive way, eg: ``` void fun(){ ... scope(success) {bar;} ... } ``` vs: ``` void fun(){ ... if(foo1){ bar; // add this before each return return; } ... bar; return; } ``` For scope(success) and scope(failure), the

Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
2018 at 11:21 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > On Wednesday, February 07, 2018 13:39:55 Timothee Cour via Digitalmars-d- > learn wrote: >> ``` >> void fun_bad3(T)(T a); // declaration [1] >> void fun_bad3(T)(T a){}; // definition [2] >> void tes

what's the point of function template declarations if they can't be defined?

2018-02-07 Thread Timothee Cour via Digitalmars-d-learn
``` void fun_bad3(T)(T a); // declaration [1] void fun_bad3(T)(T a){}; // definition [2] void test(){ fun_bad3(1); } ``` Error: test_all.fun_bad3 called with argument types (int) matches both: main.d(11): test_all.fun_bad3!int.fun_bad3(int a) and: main.d(12): test_all.fun_bad3!int.fun_b

Re: dirEntries returns relative, not absolute paths

2018-02-06 Thread Timothee Cour via Digitalmars-d-learn
https://github.com/dlang/phobos/pull/6133 On Tue, Feb 6, 2018 at 1:40 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, February 06, 2018 18:58:43 number via Digitalmars-d-learn wrote: >> https://dlang.org/phobos/std_file.html#dirEntries >> >> >> The name of each iterated director

Re: Interfacing with C++

2018-02-05 Thread Timothee Cour via Digitalmars-d-learn
https://github.com/opencv/opencv/issues/6585#issuecomment-221842441 snip: > "C-API" is not supported and should be removed totally (but we have a lack of > resources to port this legacy C code to C++, so some of this code still > exists right now). Also huge part of fresh OpenCV functionality is

Re: Interfacing with C++

2018-02-04 Thread Timothee Cour via Digitalmars-d-learn
Calypso (https://github.com/Syniurge/Calypso/) is the most promising way to interface with C++, it requires 0 bindings and understands all of C++ (templates etc); there are some caveats/kinks that are being ironed out (and any help is welcome). On Sun, Feb 4, 2018 at 4:37 AM, rjframe via Digitalm

Re: C++ Interop

2018-01-05 Thread Timothee Cour via Digitalmars-d-learn
see also https://github.com/Syniurge/Calypso/ although I'm having lots of issues using it on OSX On Fri, Jan 5, 2018 at 9:02 AM, qznc via Digitalmars-d-learn wrote: > I'm exploring [0] C++ interop after watching Walter's presentation [1]. > > I hit a block with classes as template parameters. Thi

why does unittest mangled name now contains full file path instead of fully qualified module name?

2018-01-05 Thread Timothee Cour via Digitalmars-d-learn
why does unittest mangled name now contains full file path instead of fully qualified module name? seems like a regression, previous behavior seemed better and not dependent on installation path.

Re: Application settings

2017-07-08 Thread Timothee Cour via Digitalmars-d-learn
I use protocol buffers (using dproto) for this, storing my settings in either text or wire format. Advantages: type-safety with fwd/backward compatibility (unlike json which requires dynamic field access, eg with dproto you get errors at compile time instead of runtime), supports comments (although

Re: D equivalent of C++11's function local static initialization?

2017-05-16 Thread Timothee Cour via Digitalmars-d-learn
NOTE: curious about both cases: * thread local * shared On Tue, May 16, 2017 at 8:04 PM, Timothee Cour wrote: > what's the best D equivalent of C++11's function local static initialization? > ``` > void fun(){ > static auto a=[](){ > //some code >return some_var; > } > } > ``` > > (C+

D equivalent of C++11's function local static initialization?

2017-05-16 Thread Timothee Cour via Digitalmars-d-learn
what's the best D equivalent of C++11's function local static initialization? ``` void fun(){ static auto a=[](){ //some code return some_var; } } ``` (C++11 guarantees thread safety)

Error: unrecognized switch '--DRT-oncycle=print' => where is switch defined?

2017-05-15 Thread Timothee Cour via Digitalmars-d-learn
Getting this: ``` Deprecation 16211 warning: A cycle has been detected in your program that was undetected prior to DMD 2.072. This program will continue, but will not operate when using DMD 2.073 to compile. Use runtime option --DRT-oncycle=print to see the cycle details. ``` Where is ` --DRT-on

Re: pointer not aligned

2017-04-02 Thread Timothee Cour via Digitalmars-d-learn
indeed. NOTE: ldmd2/ldc2 doens't have this issue to reproduce: ``` rdmd --force --eval='writeln(`hello`)' ``` ld: warning: pointer not aligned at address 0x1000BE0B9 (_D53TypeInfo_S3std5array17__T8AppenderTAyaZ8Appender4Data6__initZ + 24 from .rdmd-501/rdmd-eval.o) with `--compiler=ldmd2`

Re: Strange Bug

2017-01-20 Thread Timothee Cour via Digitalmars-d-learn
This and some other recent posts (`Is this a bug?`, `Hopefully a simple question...`). If you want help (and help other ppl who search for similar issues), could you please make the subject more descriptive? On Fri, Jan 20, 2017 at 12:19 AM, Chris M. via Digitalmars-d-learn < digitalmars-d-learn

DRY version of `static if(__traits(compiles, expr)) fun(expr)`

2016-12-13 Thread Timothee Cour via Digitalmars-d-learn
what's the best (and DRY) way to achieve: ``` static if(__traits(compiles, expr)) fun(expr); ``` ie, without repeating the expression inside expr? eg: ``` static if(__traits(compiles, foo.bar[2])){ counter++; writeln(" expr = ", foo.bar[2]); } ```

Re: [Semi-OT] I don't want to leave this language!

2016-12-06 Thread Timothee Cour via Digitalmars-d-learn
My 2 cents: for most applications, hotspots tend to be in a tiny percentage of the code (ie 90/10 rule where 10% of code accounts for 90% execution time, although my experience in large projects is even more unbalanced) ; throwing away druntime or GC for the whole codebase based on performance conc

extern(C++) with template produces wrong mangleof

2016-12-02 Thread Timothee Cour via Digitalmars-d-learn
What's the difference bw _Z21test_D20161202T141925IiET_S0_ and _Z21test_D20161202T141925IiEii? mangleof produces the one that's not in the library produced: test.cpp: ``` template T test_D20161202T141925(T a); template int test_D20161202T141925(int); ``` clang++ -shared -o libtest.so test.cpp c+

The module 'foo' is already defined in 'libmylib.so'

2016-12-01 Thread Timothee Cour via Digitalmars-d-learn
I want to update a library with new symbols (ie partial recompilation): libmylib.so : compiled from bar.d and foo.d now update the file foo.d dmd -c -fPIC foo.d -offoo.o clang++ -o libmylib_update.so foo.o -shared -Wl,-lmylib When trying to dlopen libmylib_update.so from C++ it fails with: The

how to catch D Throwables (or exceptions) from C++?

2016-11-30 Thread Timothee Cour via Digitalmars-d-learn
eg: ``` dlib.d: extern(C) void dfun(){assert(0, "some_msg");} clib.cpp: extern "C" void dfun(); void fun(){ try{ dfun(); } catch(...){ // works but how do i get "some_msg" thrown from D? } } ```

Re: how to debug exceptions/asserts thrown in module constructors?

2016-11-27 Thread Timothee Cour via Digitalmars-d-learn
UPDATE: * b Loader.d:123 didn't help either: error: parsing line table prologue at 0x (parsing ended around 0x Breakpoint 1: where = mybinary.temp`D4gtkc6Loader6Linker12_staticDtor3FZv, address = 0x000100315410 (process exited despite breakpoint); dmd's dwarf debug info seems

how to debug exceptions/asserts thrown in module constructors?

2016-11-27 Thread Timothee Cour via Digitalmars-d-learn
in the process of trying to debug https://github.com/BlackEdder/ggplotd/issues/32 I would like to get a stracktrace and/or put a breakpoint before exception is thrown: ``` lldb $binary r (lldb) Process 34168 resuming object.Exception@../../../../.dub/packages/gtk-d-3.3.1/gtk-d/src/gtkc/Loader.d(1

mangle!(void function())("foo").demangle = "void function()* foo"

2016-11-02 Thread Timothee Cour via Digitalmars-d-learn
mangle!(void function())("foo").demangle returns "void function()* foo" how would i get instead: `void foo ()` ? my current workaround: alias FunctionTypeOf(Fun)=typeof(*Fun.init); mangle!(FunctionTypeOf!(void function()))("foo")

zip: why isn't requireSameLength the default?

2016-09-13 Thread Timothee Cour via Digitalmars-d-learn
in zip: why isn't requireSameLength the default? This is the most common case and would fit with the goal of being safe by default.

Re: Checking if a port is listening

2016-03-18 Thread Timothee Cour via Digitalmars-d-learn
see also: https://github.com/rejectedsoftware/vibe.d/issues/1431 api to find an available port On Fri, Mar 18, 2016 at 2:50 AM, Marc Schütz via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Looking at an strace of nmap, it seems it opens a bunch of sockets, puts > them into

Re: How to list all version identifiers?

2016-03-15 Thread Timothee Cour via Digitalmars-d-learn
would be easy with compiler as a library... also i thought 'dmd -v -version=foo -c -o- bar.d' would show -version identifiers used on the command line but doesn't seem to On Tue, Mar 15, 2016 at 8:51 AM, Iakh via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Sunday, 13 Marc

get stacktrace across all threads

2016-02-22 Thread Timothee Cour via Digitalmars-d-learn
It would be nice to have an api to get stacktrace across threads; it would be particularly useful for server applications (eg vibe.d). Has anyone implemented something similar? I guess one would need to use signal handlers to interrupt each thread?

Re: Scale-Hierarchy on ndslice

2016-01-13 Thread Timothee Cour via Digitalmars-d-learn
On Wed, Jan 13, 2016 at 10:13 AM, jmh530 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 12 January 2016 at 21:48:39 UTC, Per Nordlöw wrote: > >> Have anybody been thinking about adding a scale-hierarchy structure on >> top of ndslice? >> > > What is a scale-hiera

Re: to!string(double) at compile time

2016-01-01 Thread timothee cour via Digitalmars-d-learn
On Thursday, 23 August 2012 at 13:56:05 UTC, Philippe Sigaud wrote: On Tue, Aug 21, 2012 at 6:43 AM, Bobby Bingham wrote: [...] [...] A possibility is to use a function template, passing the double as a template argument: string test(double d)() // d is a template argument { return

Re: DMD Compiler 'switches'

2015-10-12 Thread Timothee Cour via Digitalmars-d-learn
On Mon, Oct 12, 2015 at 11:33 AM, ric maicle via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 13 October, 2015 01:46 AM, anonymous wrote: > >> On Monday 12 October 2015 17:38, ric maicle wrote: >> >> I'm wondering if this small irregularity should be made consisten

IFTI with template alias fails in D, works in C++

2015-08-12 Thread Timothee Cour via Digitalmars-d-learn
main.d: -- struct A(T, int D) { this(string ignore){} } alias B(T)=A!(T, 1); void fun1(T)(A!(T,1) a) { } void fun2(T)(B!T a) { } unittest{ auto a=A!(double,1)("a"); assert(is(typeof(a) == B!double)); fun1(a);//ok fun2!double(a);//ok // no IFTI here: //fun2(a);//not ok:

Re: exclude current directory from search path in dmd ?

2015-07-20 Thread Timothee Cour via Digitalmars-d-learn
https://github.com/D-Programming-Language/dmd/pull/4823 On Sun, Jul 19, 2015 at 10:42 PM, ZombineDev via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, 20 July 2015 at 03:33:08 UTC, Timothee Cour wrote: > >> I've attached a reduced use case showing that the solutions

Re: exclude current directory from search path in dmd ?

2015-07-19 Thread Timothee Cour via Digitalmars-d-learn
I've attached a reduced use case showing that the solutions proposed in this thread do not work, and wrote a local modification to dmd to allow a flag -exclude_cwd_from_imports that does work. Would that be acceptable to have this in official dmd? On Sun, Jul 19, 2015 at 8:07 PM, Timothee Cour w

Re: exclude current directory from search path in dmd ?

2015-07-19 Thread Timothee Cour via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=14811 On Wed, Jun 17, 2015 at 3:22 AM, Liran Zvibel via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, 8 June 2015 at 04:08:55 UTC, Adam D. Ruppe wrote: > >> The easiest way is to not use search paths, and instead pass all the

Re: generic cast(unshared) ?

2015-06-30 Thread Timothee Cour via Digitalmars-d-learn
Note: should work with any types, eg: shared(T[])* => T[]* etc... On Sun, Jun 28, 2015 at 4:42 PM, Timothee Cour wrote: > How would I cast away shared for a given expression? > I can write it for a specific type but I'd like to have a generic way to > do so. > Also, Unqual doesn't help here. >

generic cast(unshared) ?

2015-06-30 Thread Timothee Cour via Digitalmars-d-learn
How would I cast away shared for a given expression? I can write it for a specific type but I'd like to have a generic way to do so. Also, Unqual doesn't help here.

Re: string to time conversion (when string contains time but no date)

2015-06-27 Thread Timothee Cour via Digitalmars-d-learn
thanks, missed that! On Sat, Jun 27, 2015 at 2:59 AM, via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Saturday, 27 June 2015 at 03:17:49 UTC, Timothee Cour wrote: > >> is there a way to convert a string representing a time (without date) to a >> time, eg: >> >> auto t = "

string to time conversion (when string contains time but no date)

2015-06-26 Thread Timothee Cour via Digitalmars-d-learn
is there a way to convert a string representing a time (without date) to a time, eg: auto t = "19:03:40.143656"; auto a=SysTime.fromTimeString(t); // doesn't exist My current workaround is to append a dummy date before and then calling SysTime.fromSimpleString. Is there a better way? seems need

type of a variable as a mixin-able string?

2015-06-21 Thread Timothee Cour via Digitalmars-d-learn
Suppose I have: import std.range; auto a=iota(complex_expr_returning_3()); I'd like to have a function/trait/template/compiler magic that takes variable a and generates a string that can be mixed in to represent the type of a. The difficulty is that typeid(a).to!string doesn't work for Voldermort

how come is this legal? 'void fun(int){ }' ?

2015-06-13 Thread Timothee Cour via Digitalmars-d-learn
I understand this is legal for declaration wo definition (void fun(int);) but why allow this: void test(int){} ?

Re: Why is there no named parameter support?

2015-06-08 Thread Timothee Cour via Digitalmars-d-learn
On Mon, Jun 8, 2015 at 11:32 PM, Jonathan M Davis via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, June 08, 2015 23:18:50 Timothee Cour via Digitalmars-d-learn > wrote: > > nim has both overloading and named arguments (with reordering and >

Re: Why is there no named parameter support?

2015-06-08 Thread Timothee Cour via Digitalmars-d-learn
nim has both overloading and named arguments (with reordering and defaults allowed): http://nim-lang.org/docs/tut1.html#procedures-named-arguments and it doesn't seem to cause issues. Is there a document / thread that explains the argument against named arguments in more details than 'do not play

Re: exclude current directory from search path in dmd ?

2015-06-08 Thread Timothee Cour via Digitalmars-d-learn
On Mon, Jun 8, 2015 at 12:08 AM, Adam D. Ruppe via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > The easiest way is to not use search paths, and instead pass all the > modules you want compiled to the compiler directly. Then it will look for > the module name declaration instea

Re: exclude current directory from search path in dmd ?

2015-06-07 Thread Timothee Cour via Digitalmars-d-learn
ping? On Sun, Mar 15, 2015 at 10:26 PM, Timothee Cour wrote: > Is there a way to exclude current directory from search path in dmd, so > that the search path is only given by '-I' arguments (+ones from dmd.conf)? > > use case: > > files: > /base/foo.d > /base/bar/foo.d > /base/bar/main.d #contai

attribute alias? eg: asm @my_alias {...} alias my_alias=pure nothrow @trusted @nogc;

2015-05-30 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to alias attributes? alias my_alias=pure nothrow @trusted @nogc; asm @my_alias {...} This came up here: https://github.com/Hackerpilot/libdparse/issues/50 Or at least to do the following in a less ugly way? static if(__VERSION__<2067) enum asm_att=``; else enum asm_att=`pure noth

deserialization: creating a class instance without calling constructor

2015-05-21 Thread Timothee Cour via Digitalmars-d-learn
Can I create an instance of A without calling a constructor? (see below) Use case: for generic deserialiaztion, when the deserialization library encounters a class without default constructor for example (it knows what the fields should be set to, but doesn't know how to construct the object). cla

why does phobos use [0, 5, 8, 9][] instead of [0, 5, 8, 9] in examples?

2015-04-07 Thread Timothee Cour via Digitalmars-d-learn
Eg, code like this in std.algorithm: assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9][])); why not just: assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9])); ?

exclude current directory from search path in dmd ?

2015-03-15 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to exclude current directory from search path in dmd, so that the search path is only given by '-I' arguments (+ones from dmd.conf)? use case: files: /base/foo.d /base/bar/foo.d /base/bar/main.d #contains: import foo.d cd /base/bar dmd -I/base main.d => I want 'import foo.d' to p

mixin template can't contain statements: workaround?

2015-03-14 Thread Timothee Cour via Digitalmars-d-learn
Why can't we allow mixin templates to contain statements, as is the case for regular mixins? Is there a workaround? here's a dummy example: template mixin Foo{ //some statement, eg: 'return;' } void fun(){ mixin Foo; } Note that I can do this with a regular mixin, but template mixins are cle

boilerplate for constructor

2015-03-10 Thread Timothee Cour via Digitalmars-d-learn
I'm trying to define a boilerplate mixin for class constructor to generate code such as: this(T1 a1, T2 a2){this.a1=a1; this.a2=a2;} The following works, but fails if one field is from a superclass, with an error such as: template instance GenThis!(b, a) GenThis!(b, a) is nested in both B and A.

Re: is struct delete deterministic? (cf used in Unique)

2015-03-08 Thread Timothee Cour via Digitalmars-d-learn
On Sun, Mar 8, 2015 at 4:36 AM, Jonathan M Davis via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Sunday, March 08, 2015 04:13:28 Jonathan M Davis via > Digitalmars-d-learn wrote: > > On Saturday, March 07, 2015 17:20:49 Timothee Cour via > Digi

Re: is struct delete deterministic? (cf used in Unique)

2015-03-07 Thread Timothee Cour via Digitalmars-d-learn
To clarify, I'm only asking about a struct allocated via new. Unique!T is wrapped around a struct, but it allocates a struct T via 'new', so my question still holds: does 'delete t' (where t is a struct allocated via new) guarantee deterministic destruction? I'm guessing yes, otherwise Unique woul

is struct delete deterministic? (cf used in Unique)

2015-03-07 Thread Timothee Cour via Digitalmars-d-learn
I'm a little confused about the following: clear,delete,destroy. My understanding is that clear is deprecated and delete is planned to be deprecated, so we should only ever use destroy (which deterministic calls the destructor but doesn't release memory). Unique uses delete however in the destruct

Re: mixin template scope inconsistency?

2015-03-03 Thread Timothee Cour via Digitalmars-d-learn
posted as bugzilla/14243. Am I misunderstanding something here? On Tue, Mar 3, 2015 at 10:20 PM, Timothee Cour wrote: > Template mixin scope seems to have a weird behavior: > I don't understand 'WEIRD(1)' and 'WEIRD(2)' below. > > import std.stdio; > struct A{ > int b; > this(int b){ > t

mixin template scope inconsistency?

2015-03-03 Thread Timothee Cour via Digitalmars-d-learn
Template mixin scope seems to have a weird behavior: I don't understand 'WEIRD(1)' and 'WEIRD(2)' below. import std.stdio; struct A{ int b; this(int b){ this.b=b; writeln("A.begin"); } ~this(){ writeln("A.end"); } } mixin template Entry(){ auto a=A(12); } void test1(){

shallowCopyFrom: how to shallow copy objects / swap contents ?

2015-02-13 Thread Timothee Cour via Digitalmars-d-learn
Is there a standard way to shallow copy objects? eg: class A{ int* a; string b; } unittest{ auto a=new A; a.a=new int(1); a.b="asdf"; auto b=new A; b.shallowCopyFrom(a); assert(b.a==a.a); assert(b.b==a.b); } How about: option A1: void shallowCopyFrom(T)(T a, T b) if(is(T==cla

parse string as char

2015-02-08 Thread Timothee Cour via Digitalmars-d-learn
Is there a simple way to parse a string as a char? eg: unittest{ assert(parseChar(`a`)=='a'); assert(parseChar(`\n`)=='\n'); //NOTE: I'm looking at `\n` not "\n" // should also work with other forms of characters, see http://dlang.org/lex.html } Note, std.conv.to doesn't work (`\n`.to!char do

Re: eraseInPlace (eg using memmove)?

2014-12-16 Thread Timothee Cour via Digitalmars-d-learn
Here's what I'd like in phobos: void eraseInPlace(T)(ref T a, size_t index, size_t n=1) if(isArray!T){ enum s=typeof(a[0]).sizeof; auto ptr=a.ptr+index; import core.stdc.string:memmove; memmove(ptr,ptr+n,(a.length-(index+n))*s); a.length-=n; } unittest{ auto a=[0,1,2,3,4,5,6]; a.erase

eraseInPlace (eg using memmove)?

2014-12-16 Thread Timothee Cour via Digitalmars-d-learn
Is there a phobos way to do eraseInPlace (eg with optimization using memmove where appropriate) ? (akin to insertInPlace)

Re: how to redirect stderr to stdout io in spawnProcess (eg stderr to stdout)?

2014-09-14 Thread Timothee Cour via Digitalmars-d-learn
ping? On Tue, Sep 9, 2014 at 6:48 PM, Timothee Cour wrote: > How to redirect io in spawnProcess (eg stderr to stdout)? > > is it safe to use it with a same File object for stderr and stdout as > follows? > Couldn't find this in the docs. > > auto logFile =File(...); > auto pid = spawnShell(comma

how to redirect stderr to stdout io in spawnProcess (eg stderr to stdout)?

2014-09-09 Thread Timothee Cour via Digitalmars-d-learn
How to redirect io in spawnProcess (eg stderr to stdout)? is it safe to use it with a same File object for stderr and stdout as follows? Couldn't find this in the docs. auto logFile =File(...); auto pid = spawnShell(command, std.stdio.stdin, logFile

spawnShell: how to specify buffering mode (unbuffered, line-buffered, block-buffered)?

2014-09-09 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to specify buffering mode (unbuffered,line-buffered,block-buffered) in spawnShell + friends? This is very useful to have in many applications, eg for logging where one wants to view in progress log results without waiting for entire process to complete or for a 40960-sized block to b

extern(C) function declaration inside a function without altering mangling

2014-09-06 Thread Timothee Cour via Digitalmars-d-learn
Is there way to declare a extern(C) function inside a function without altering the mangled name? Should I write a mixin for that based on pragma(mangleof) (used as extern_C_global_scope in example below) ? Or did someone already implement that? extern(C) void foo1(); void fun(){ extern(C) void f

Re: RAII limitations in D?

2014-08-21 Thread Timothee Cour via Digitalmars-d-learn
On Thu, Aug 21, 2014 at 7:26 PM, Dicebot via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > http://dlang.org/phobos/std_typecons.html#.RefCounted That doesn't work with classes though; is there any way to get a ref counted class? (and btw RefCounted should definitely appear i

RAII limitations in D?

2014-08-21 Thread Timothee Cour via Digitalmars-d-learn
What would be a good answer to this article? http://swiftcoder.wordpress.com/2009/02/18/raii-why-is-it-unique-to-c/ Especially the part mentioning D:{ D’s scope keyword, Python’s with statement and C#’s using declaration all provide limited RAII, by allowing resources to have a scoped lifetime, bu

Deprecation: Read-modify-write operations are not allowed for shared variables

2014-08-12 Thread Timothee Cour via Digitalmars-d-learn
dmd 2.066(rc) generates warning: 'Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"-="(a, 1) instead.' for following code: synchronized { ++a; } Is that correct given that it's inside synchronized?

Re: alias to fully qualified enum in scope where enum is expected

2014-08-06 Thread Timothee Cour via Digitalmars-d-learn
On Wed, Aug 6, 2014 at 12:04 PM, via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, 6 August 2014 at 16:48:57 UTC, Timothee Cour via > Digitalmars-d-learn wrote: > >> Thanks, I know with statement could be used but I was hoping for a >>

'with(Foo):' not allowed, why?

2014-08-06 Thread Timothee Cour via Digitalmars-d-learn
Is there a reason why 'with(Foo):' is not allowed, and we have to use with(Foo){...} ? It would be more in line with how other scope definitions work (extern(C) etc)

Re: alias to fully qualified enum in scope where enum is expected

2014-08-06 Thread Timothee Cour via Digitalmars-d-learn
Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site. void fun(with(A){A a}, int b){...} //conceptually like this void test(){ int a1=1; fun(A.a1, a1); // would work fun(a1, a1);// would work } On Wed, Aug 6, 2014 at 8:22 AM,

alias to fully qualified enum in scope where enum is expected

2014-08-05 Thread Timothee Cour via Digitalmars-d-learn
Is there a simple way to to do this? enum A{ a1, a2 } void fun(A a){...} void test(){ fun(A.a1); //works fun(a1); //I'd like a1 to work, but just where an A is expected to avoid polluting namespace. }

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-29 Thread Timothee Cour via Digitalmars-d-learn
On Sun, Jul 27, 2014 at 9:20 PM, H. S. Teoh via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Sun, Jul 27, 2014 at 07:42:17PM -0700, Timothee Cour via > Digitalmars-d-learn wrote: > > Just for clarification, I wanted 'myrange.a

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-27 Thread Timothee Cour via Digitalmars-d-learn
Just for clarification, I wanted 'myrange.at(i)' to be the same as `myrange.dropExactly(i).front` (so I don't assume it's a random access range). >> myrange.dropExactly(i).front makes it much more obvious what you're doing and that it's inefficient. It might be necessary in some cases, but we don'

myrange.at(i) for myrange.dropExactly(i).front

2014-07-25 Thread Timothee Cour via Digitalmars-d-learn
Is there a function for doing this? myrange.at(i) (with meaning of myrange.dropExactly(i).front) it's a common enough operation (analog to myrange[i]; the naming is from C++'s std::vector::at)

__traits(position,symbol) to get the file:line:column:index of a symbol (module,unittest etc)

2014-06-12 Thread Timothee Cour via Digitalmars-d-learn
Wouldn't that be nice? it's all known at CT so why not expose it among other things it'd allow proper association of modules to files in stacktraces (sometimes this is impossible / ambiguous), custom user defined error messages involving lambdas, printing unittest lines etc.

escape string into a C style string litteral (pasteable in C code)

2014-06-11 Thread Timothee Cour via Digitalmars-d-learn
Is there an existing way to do it or do I have to roll my own? unittest{ assert(escapeC(`a"bc\ndef`~"\n") == `"a\"bc\\ndef\n"`); } Likewise with escapeD (pastable in D code), which would return something like: `r"..."` for more readability

findBack: find a needle in a haystack from the back

2014-06-09 Thread Timothee Cour via Digitalmars-d-learn
Is there a more idiomatic/elegant way to achieve the following, while remaining as efficient as possible? Same question in the simpler case n==0? using retro seems inefficient because of all the decodings // returns the largest suffix of a that contains no more than n times c string findBack(stri

Re: alias with lambda syntax: alias fun2=a=>fun(a);

2014-06-05 Thread Timothee Cour via Digitalmars-d-learn
ok I remembered we can use std.typetuple.Alias for that. On Wed, Jun 4, 2014 at 11:58 PM, Timothee Cour wrote: > Is there a way to do this? > > import std.algorithm; > > auto fun(T)(T a){return a;} > > template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and > cannot be nested

alias with lambda syntax: alias fun2=a=>fun(a);

2014-06-04 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and cannot be nested inside test() void main(){ //alias fun2=fun!int; //OK but needs to specify template params //none of those work: //alias

Re: Best way to check for an element in an array?

2014-04-21 Thread Timothee Cour via Digitalmars-d-learn
you can use stuff.canFind(2) but sometimes it'd be more convenient to have the other way around (UFCS chains etc); how about: bool isIn(T,T2...)(T needle, T2 haystack) if(__traits(compiles,T.init==T2[0].init)){ foreach(e;haystack){ if(needle==e) return true; } return false; } unittest{

Re: string -> string literal

2014-04-21 Thread Timothee Cour via Digitalmars-d-learn
does that work? string escapeD(string a){ import std.array:replace; return `r"`~a.replace(`"`,`" "\"" r"`)~`"`; } On Sun, Apr 20, 2014 at 11:14 AM, monarch_dodra via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Sunday, 20 April 2014 at 17:55:25 UTC, Ellery Newcomer wrote: