Re: Is this a bug ?
On Tuesday, 12 July 2016 at 04:38:42 UTC, Chang Long wrote: test.d = template newType(size_t N){ class NewType { enum Type = N ; } } just find it should be this: template newType(size_t N){ class NewType { enum Type = N ; } alias newType = NewType; }
adding toString to struct
windows libs have a lot of structs and it would be nice to have the ability to convert them to a string to see them in the debugger(e.g., CLSID). Is there a way to do this? I've tried to pull out the code from the libs but it if a total clusterfuck.
Re: sorting std.container
On Monday, 11 July 2016 at 19:07:51 UTC, ketmar wrote: list slices are not random-access ranges, thus they can't be sorted in-place (this is what std.algorithm.sort does). so the only way is to convert list to array, sort it, and make a list from sorted array. probably not something you want. ;-) this is common for any "traditional" linked list implementation: random access is very costly, thus even if it is implemented, it's better to not use it. SList and DList are "traditional" lists without any fancy algorithms inside (like finger trees or skip lists). you may want to use arrays instead (it is often more efficient anyway, especially if you don't need to insert elements in the middle of the array), or associative arrays. If I may deviate from the discussion a bit,are there any real world scenarios where the SList and DList (that is, "traditional" linked lists) is superior to fixed, dynamic or associative arrays? Or are lists more of a data type exercise?
Is this a bug ?
test.d = template newType(size_t N){ class NewType { enum Type = N ; } } class A{} alias Type = newType!1 ; N New(N)(){ return new N(); } void main(){ auto a = New!A; auto n = New!Type; } test.d(19): Error: template instance New!(__T7newTypeVmi1Z) does not match template declaration New(N)()
Re: How to create nogc code?
On Monday, 11 July 2016 at 21:28:58 UTC, Jonathan M Davis wrote: If all you're doing is passing around int* and the like, then the situation is the same as in C and is fine. But stuff like int[] becomes problematic, because it assumes that you're using the GC. But that's stuff that doesn't exist in C++. It exists in C++, but is broken into multiple separate concepts: std::string_view, std::vector, gsl::span etc. D and Go mixes up a view and ownership which is confusing.
Docs for `Group` type
When using `chunkBy` (unary pred) the result is a list of tuples. Each tuple holds a key and a `Group` which belong to that key. Where can I find the docs for this `Group` type (I have already tried searching library on dlang.org)? Thanks, -- Bahman
Simple overloading without complications
I have a function that does some weird stuff, and can't really change it to make life easier(due to how windows work, COM, etc..). The function normally takes a string, a name, and does its think(which is the complex part that I can't change). But I also want to overload it so the function takes an int. I can't simply overload the function and call the string version or vice versa as one would normally do because this would require initializing twice, which can't happen because the way the code works. The int value is a lookup into an array, and the name version searches the array for a name match. I can't overload the int version and search the name first because the data doesn't exist yet void Do(string name) { // get index of name in array // can't find x corresponding to name because data is not initialized. // Can't init data more than once. Can't add init flag(could but want to find a better solution) Do(x); } void Do(int index) { Init_Data(); ... } Now, I could simply make Do a template method but then this prevents it being a virtual function. void Do(T)(T name) if (is(T == string) || is(T == int)) { Init_Data(); static if (is(T == string)) { ...Get index from name } } What I really want is a sort of mix between the first overloaded method and the second case. The string version is really just finding the index of the string and should insert itself inside the int version similar to the static if. I know there are many ways and many are going to fuss over doing it with a bool or duplicate the function or whatever. I'm looking for an elegant solution for what I want, I know there are other ways... not interested in them. Given that D has so many meta capabilities, I'm hoping there is some elegant solution. To make it clear. void Do(int index) { // Does stuff // If index was a string instead of a name, we would do a lookup to find the index for name. Everything else is exactly the same // does stuff with index } void Do(string name) { // somehow Do(name_index); } Another way is to use a lambda: void Do(int index, int delegate(data) toName) { // Does stuff if (toName) index = toName(data); // Do stuff with index } void Do(string name) { Do(0, (data) { find i for name; return i; }); // which plugs in the lambda } The problem with all these ways is that they complicate matters and either duplicate a lot of code or create hard to maintain code or problems in other areas. e.g., if I use the template method any literal string is not automatically converted do("this won't be treated as a wstring"). If a bool is used, I have to have the initialization code in both functions. Doesn't seam like much until you scale the problem up. What would be nice is something akin to yield: void Do(int index) { // Does stuff ?yield // If Do is called in a special way, we break out of the code here // Do stuff with index } void Do(string name) { yield Do(0); find i for name; continue Do(i); } This keeps everything internal and from the outside everything looks as it should, avoids duplicate code, extra arguments, flags, etc. Is it possible?
Re: Associative Array c'tor
On 07/11/2016 07:15 PM, Ali Çehreli wrote: > Both AAs and slices behave like reference types even when passed by > value: When a function adds an element, the argument sees that element > as well. This is not the case when the argument is an empty (more > correctly, null) AA or slice: > > void foo(string[int] aa) { > aa[1] = "one"; > } > > void main() { > string[int] a; > foo(a); > assert(a is null); > // The last result would be different if 'a' were not null > // before calling 'foo'. > > string[int] b; > b[0] = "zero"; > foo(b); > assert(b[0] == "zero"); > assert(b[1] == "one"); > } Now I understand. This is tricky --could introduce hard to find bugs. Is there anyway to make sure it doesn't happen? Such as giving the AA a default empty value on the declaration line --like `string[int] a = []`? > P.P.S. There is std.algorithm.fold, which works with range chaining > (unlike reduce, which was designed before ranges): > > https://dlang.org/phobos/std_algorithm_iteration.html#.fold `fold` definitely feels more natural. Thanks. -- Bahman
Re: How to use `format` to repeat a character
On 07/11/2016 03:02 PM, Mike Parker wrote: > You can do it in D with custom format specifiers. See: > > https://wiki.dlang.org/Defining_custom_print_format_specifiers Thanks for the pointer. I'll keep that in mind. -- Bahman
structure alignment
I need to align every member of every struct in a module. I can't simply add align(n) inside every struct because that seems ridiculous. I could search and paste, but then D is missing a relatively important aspect of alignment. I have about 100 struct's to align, member wise. From what I've read, align(n){ struct x; } only aligns the struct itself, is this true? Is there a way to set global alignment for members per module or per scope?
Re: how to mark an extern function @nogc?
On Monday, 11 July 2016 at 15:54:02 UTC, Seb wrote: On Monday, 11 July 2016 at 01:59:51 UTC, Adam Sansier wrote: On Monday, 11 July 2016 at 01:58:23 UTC, Adam Sansier wrote: I'm using some win functions that don't use the gc and are not marked, specifically CLSIDFromString that I imported myself(it's not marked nogc in objbase). I went ahead and copied the import and added nogc. Shouldn't someone add that to objbase? Why don't you fork it & add it yourself? Otherwise to quote Walter: "a bug only exists if it's on Bugzilla [issues.dlang.org]" ;-) If this is a bug then there are some serious issues with D's protocol of updating code. How can entire modules be missed? It seems the maintainers of D's library code do not actually use most of the features then? D needs a real code test suite to keep stuff like this from happening, not individual users from the outside to keep it in shape which makes me feel like a guinea pig. I won't stick around too long if that's the case.
Re: How to create nogc code?
On Monday, July 11, 2016 03:51:27 Adam Sansier via Digitalmars-d-learn wrote: > You know, you don't see your argument much in C++ forums. In > fact, it's probably the opposite ;) C++ doesn't have a GC built-in and does not have features that rely on it. So, it's in a very different situation. And when talking about the GC in D and how avoiding the GC causes problems, you're usually talking about features that C++ doesn't even have. If you never use features like D's dynamic arrays or delegates, then it's mostly a non-issue. If all you're doing is passing around int* and the like, then the situation is the same as in C and is fine. But stuff like int[] becomes problematic, because it assumes that you're using the GC. But that's stuff that doesn't exist in C++. The main area that's a problem in D that isn't a problem in C++ that involves features that C++ has is allocating user-defined objects in that C++'s new does not use the GC, whereas D's does, and in both cases, new is the clean and easy way to allocate an object. So, unlike in C++, in D, if you want to put user-defined objects on a non-GC heap, it can be a pain - since malloc and free don't handle that for you; they just deal with the memory itself. You need a wrapper that handles not only the allocation, but the construction and destruction correctly. But std(.experimental).allocator is where that's getting fixed. So, fortunately, that problem is going away, but without those wrappers, avoiding the GC gets miserable fast. So, if you stick purely to features that don't use the GC at all, then you lose out on some nice features, but you're in a similar boat to C or C++, and you don't need to worry about the GC, since you're not using it, and you're not using anything that's designed to use it. But then you have to avoid some nice features, which sucks, and makes writing your programs harder than they would be otherwise. By far the bigger gain is writing your code in a way that minimizes heap allocations in general, and that's going to be of benefit whether you're using the GC or not (and that's just as true in C++ as it is D). Because their feature sets are different, the situations in C++ and D are fundamentally different even though they're similar languages, and I wouldn't expect the same arguments or conclusions on all of the various topics in a C++ discussion that you'd have in a D discussion, even if the folks making those arguments were the same. Sometimes, the best way to do things is exactly the same in both languages, and sometimes it's very different. - Jonathan M Davis
How can you call a stored function in an AA with proper number of arguments converted to the proper type?
Here's the basic code I'm playing with: struct MyCmd { Variant func; // Has other members. } MyCmd[string] functions_; void addCommand(T)(const string name, T func) { MyCmd cmd; cmd.func = Variant(func); functions_[name] = cmd; } void process(string[] args) // args is only available at runtime. { const string name = args[0]; // Name of the command if(name in functions_) { MyCmd cmd = functions_[name]; cmd.func(/*Call with proper number of arguments converted to the proper type*/); } } I initially got idea from the D Cookbook Chapter Reflection: Creating a command-line function caller. But the code has to reside in the same module as the functions it will use. So I arrived at this code but can't figure out how to call the actual stored function. Thanks!
Re: sorting std.container
On 7/11/16 2:54 PM, George M wrote: Hello everybody, sorry for my bad english(nativ german). D is a very nice language and easy to learn because i am a c# (only private) developer. The only bad is to find examples is very hard. My question: How can i sort a slist or dlist with custom types and lambda expressions? No. Those would need merge sort, which I don't think is implemented in there. -Steve
Re: sorting std.container
On Monday, 11 July 2016 at 19:12:13 UTC, ketmar wrote: p.s. i mean simple D dynamic arrays, like `MyType[] arr;`, not std.array.array. ;-) Ok thank you all for the fast help. I will use Dynamic arrys. For this case my code is working. Super language and super forum :-) Thanks!!
Re: sorting std.container
p.s. i mean simple D dynamic arrays, like `MyType[] arr;`, not std.array.array. ;-)
Re: sorting std.container
list slices are not random-access ranges, thus they can't be sorted in-place (this is what std.algorithm.sort does). so the only way is to convert list to array, sort it, and make a list from sorted array. probably not something you want. ;-) this is common for any "traditional" linked list implementation: random access is very costly, thus even if it is implemented, it's better to not use it. SList and DList are "traditional" lists without any fancy algorithms inside (like finger trees or skip lists). you may want to use arrays instead (it is often more efficient anyway, especially if you don't need to insert elements in the middle of the array), or associative arrays.
Re: sorting std.container
On Monday, 11 July 2016 at 18:54:44 UTC, George M wrote: Hello everybody, sorry for my bad english(nativ german). D is a very nice language and easy to learn because i am a c# (only private) developer. The only bad is to find examples is very hard. My question: How can i sort a slist or dlist with custom types and lambda expressions? The sort function from std.algorithm works only with arrays (in my test). Can give anyone an short example? Thanks for your help. George The "tipical" sorting functions (as those in std.algorithm) expect their input to be a RandomAccessRange, while slists and dlists are, by definition, ForwardRanges and BidirectionalRanges respectively. So I'm afraid there's no standard function to order them out-of-the-box. That's a limitation of many languages (e.g. C++ sort requires a RandomIterator, which forward_list and list do not provide). What's the best workaround depends on your exact use case.
sorting std.container
Hello everybody, sorry for my bad english(nativ german). D is a very nice language and easy to learn because i am a c# (only private) developer. The only bad is to find examples is very hard. My question: How can i sort a slist or dlist with custom types and lambda expressions? The sort function from std.algorithm works only with arrays (in my test). Can give anyone an short example? Thanks for your help. George
Re: how to mark an extern function @nogc?
On Monday, 11 July 2016 at 15:54:02 UTC, Seb wrote: On Monday, 11 July 2016 at 01:59:51 UTC, Adam Sansier wrote: On Monday, 11 July 2016 at 01:58:23 UTC, Adam Sansier wrote: I'm using some win functions that don't use the gc and are not marked, specifically CLSIDFromString that I imported myself(it's not marked nogc in objbase). I went ahead and copied the import and added nogc. Shouldn't someone add that to objbase? Why don't you fork it & add it yourself? Otherwise to quote Walter: "a bug only exists if it's on Bugzilla [issues.dlang.org]" ;-) Unreported bugs can only be fixed by accident.
Re: How to use `format` to repeat a character
On Mon, Jul 11, 2016 at 02:53:24PM +0430, Bahman Movaqar via Digitalmars-d-learn wrote: > On 07/11/2016 02:44 PM, ketmar wrote: [...] > > the fact that format can insert spaces. it is like: "ok, it can do > > spaces. i bet there should be some way to use any character instead > > of space. after all, the implementation would be the same, right?!" > > and then... oops. > > That's my story. > > Thanks people for your help. Here's a cheating way of doing it: import std.stdio, std.range; writefln("%.5s", repeat('-')); It's cheating because the actual repeat is created by repeat(), but we (ab)use the fact that the precision flag is treated as "maximum number of characters" in the %s specifier to be able to control the length of the repeat from the format string. T -- INTEL = Only half of "intelligence".
Re: How to use `format` to repeat a character
On Monday, 11 July 2016 at 09:02:12 UTC, Bahman Movaqar wrote: I'm sure I'm missing something very simple but how can I create a string like "" using `format`? I check the docs on `format` and tried many variations including `format("%.*c\n", 4, '-')` but got nowhere. I'd appreciate any hint/help on this. There's at least one way to do this, by using position arguments and repeating it the desired number of times in the format string. format("%1$s%1$s%1$s%1$s\n", '-') But as you can see this is pretty ugly and can easily introduce bugs in your format string.
Re: how to mark an extern function @nogc?
On Monday, 11 July 2016 at 01:59:51 UTC, Adam Sansier wrote: On Monday, 11 July 2016 at 01:58:23 UTC, Adam Sansier wrote: I'm using some win functions that don't use the gc and are not marked, specifically CLSIDFromString that I imported myself(it's not marked nogc in objbase). I went ahead and copied the import and added nogc. Shouldn't someone add that to objbase? Why don't you fork it & add it yourself? Otherwise to quote Walter: "a bug only exists if it's on Bugzilla [issues.dlang.org]" ;-)
Re: protected + package attributes
On Monday, 11 July 2016 at 12:42:57 UTC, ag0aep6g wrote: On 07/11/2016 02:28 PM, zodd wrote: Suppose I have a class with a few protected functions. I want to let another class from the same package call these functions. Thus I've added a "package" attribute and got the following: Error: conflicting protection attribute 'package' and 'protected' How can I achieve what I want? These member functions must be protected, I can't make them private because this is a base class intended for inheritance. Can have only one level of protection. If package is too restrictive with regards to overriding, and protected is too restrictive with regards to calling, then there's only public left. Other than that, you could add a `package` method with a different name that just calls the `protected` one. It seems that I have no other choice. Thanks for a suggestion!
Re: protected + package attributes
On Monday, 11 July 2016 at 12:42:57 UTC, ag0aep6g wrote: Other than that, you could add a `package` method with a different name that just calls the `protected` one. This is a pattern I have found useful, particularly when dealing with protected abstract methods, e.g. package void someActon() { doSomeAction(); } protected abstract void doSomeAction;
Re: Associative Array c'tor
On 7/11/16 10:33 AM, Bahman Movaqar wrote: On 07/11/2016 06:30 PM, Steven Schveighoffer wrote: But passing empty AA by value sometimes can be surprising. I'm not sure if it will work. Could you elaborate more? An AA initializes on demand. So if you pass by value *after* it has been initialized it behaves like a reference type. But before it's initialized, it's essentially a null pointer. This can cause surprising behavior: foo(int[int] aa) { foreach(i; 0 .. 100) aa[i] = i; } void main() { import std.random; int[int] aa; // initialized as null if(uniform!ubyte < 128) aa[0] = 0; // intialized foo(aa); // at this point, depending on random initialization, either aa is filled or is still null. } -Steve
Re: Associative Array c'tor
On 07/11/2016 07:33 AM, Bahman Movaqar wrote: > On 07/11/2016 06:30 PM, Steven Schveighoffer wrote: >> Untested, but you could try MySt[][string].init. > > That did it. Thanks. > >> But passing empty AA by value sometimes can be surprising. I'm not sure >> if it will work. > > Could you elaborate more? Both AAs and slices behave like reference types even when passed by value: When a function adds an element, the argument sees that element as well. This is not the case when the argument is an empty (more correctly, null) AA or slice: void foo(string[int] aa) { aa[1] = "one"; } void main() { string[int] a; foo(a); assert(a is null); // The last result would be different if 'a' were not null // before calling 'foo'. string[int] b; b[0] = "zero"; foo(b); assert(b[0] == "zero"); assert(b[1] == "one"); } Ali P.S. There is std.array.assocArray if you already have a range of tuples at hand: https://dlang.org/phobos/std_array.html#.assocArray P.P.S. There is std.algorithm.fold, which works with range chaining (unlike reduce, which was designed before ranges): https://dlang.org/phobos/std_algorithm_iteration.html#.fold
Re: Associative Array c'tor
On 07/11/2016 06:30 PM, Steven Schveighoffer wrote: > Untested, but you could try MySt[][string].init. That did it. Thanks. > But passing empty AA by value sometimes can be surprising. I'm not sure > if it will work. Could you elaborate more? -- Bahman
Re: Associative Array c'tor
On 7/11/16 9:48 AM, Bahman Movaqar wrote: I'm processing a list of structs (MySt) with `reduce` to produce an associate array of type `MySt[][string]`. Right now I'm using the following (slimmed down) code: MySt[][string] result; return reduce!( function MySt[][string](MySt[][string] acc, MySt val) { // do something with acc return acc; } )(result, inputList); I was wondering if I could remove the empty declaration line (line 1); for example: return reduce!( function MySt[][string](MySt[][string] acc, MySt val) { // do something with acc return acc; } )(new MySt[][string](), inputList); Obviously, this fails with the error message: "cannot pass type string as a function argument". I very much would like to avoid empty declaration lines like that of `result`. Is there anyway you folks would suggest? Untested, but you could try MySt[][string].init. But passing empty AA by value sometimes can be surprising. I'm not sure if it will work. -Steve
Re: Debugging InvalidMemoryOperationError
On Monday, 11 July 2016 at 13:01:31 UTC, Adam D. Ruppe wrote: The stack trace also says this is being triggered from the garbage collector. Do you have a dynamic array of RefCounted objects, or one inside a class object? I'm not sure as to the nature of the bug but refcounted inside a GC object isn't going to work well anyway. I find this code: // FIXME: D arrays don't call element destructors when GC-d :( RoundBuf!CramSlice _input_queue; Where CramSlice contains RcPtr!(cram_slice, cram_free_slice) and RcPtr contains a RefCounted (allowing a custom free function, wrapping C API - see https://github.com/lomereiter/sambamba/blob/master/cram/wrappers.d#L14). What exactly are the two failure modes you are alluding to?
Associative Array c'tor
I'm processing a list of structs (MySt) with `reduce` to produce an associate array of type `MySt[][string]`. Right now I'm using the following (slimmed down) code: MySt[][string] result; return reduce!( function MySt[][string](MySt[][string] acc, MySt val) { // do something with acc return acc; } )(result, inputList); I was wondering if I could remove the empty declaration line (line 1); for example: return reduce!( function MySt[][string](MySt[][string] acc, MySt val) { // do something with acc return acc; } )(new MySt[][string](), inputList); Obviously, this fails with the error message: "cannot pass type string as a function argument". I very much would like to avoid empty declaration lines like that of `result`. Is there anyway you folks would suggest? Thanks in advance, -- Bahman
Re: Debugging InvalidMemoryOperationError
On 07/11/2016 02:42 PM, Sam wrote: #0 0x00670a50 in onInvalidMemoryOperationError () #1 0x0068657b in gc.gc.GC.malloc() () #2 0x0067a4d2 in _d_newclass () #3 0x00670d53 in _d_assert () #4 0x0053d8e2 in std.typecons.__T10RefCountedTS4cram8wrappers54__T5RcPtrTS4cram6htslib10cram_sliceS15cram_free_sliceZ5RcPtr7PayloadVE3std8typecons24RefCountedAutoInitializei0Z.RefCounted.__dtor() () #5 0x005d39e6 in cram.wrappers.__T5RcPtrTS4cram6htslib10cram_sliceS15cram_free_sliceZ.RcPtr.__fieldDtor() () #6 0x0043a5e4 in cram.wrappers.CramSlice.__fieldDtor() () #7 0x005d4ce2 in cram.wrappers.UndecodedSliceRange.__fieldDtor() () #8 0x0067c20e in rt_finalize2 () #9 0x0068935a in gc.gc.Gcx.sweep() () #10 0x00687a1b in gc.gc.Gcx.fullcollect() () #11 0x00687bae in gc.gc.GC.fullCollectNoStack() () #12 0x0067922b in gc_term () #13 0x00679efa in rt_term () #14 0x0067a170 in _d_run_main () #15 0x00414278 in main () Questions: * does this suggest that an assert in the destructor of std.typecons.RefCounted is trying to allocate memory? Looks like it. I suppose that means that the assert has failed. Otherwise it shouldn't allocate. Allocating in a destructor is what usually raises InvalidMemoryOperationError. The only assert there is this: https://github.com/dlang/phobos/blob/61a7f2a250962a677aa01495cb342234ddac3a7f/std/typecons.d#L4864 * if so, is this considered a bug? Possibly. Would need a smaller test case to make sense of it.
Re: Debugging InvalidMemoryOperationError
On Monday, 11 July 2016 at 12:42:26 UTC, Sam wrote: #3 0x00670d53 in _d_assert () #4 0x0053d8e2 in std.typecons.__T10RefCountedTS4cram8wrappers54__T5RcPtrTS4cram6htslib10cram_sliceS15cram_free_sliceZ5RcPtr7PayloadVE3std8typecons24RefCountedAutoInitializei0Z.RefCounted.__dtor() () I'm not 100% sure but this is saying an assert in RefCounted's destructor and looking at Phobos source, there's just one: assert(_refCounted._store._count > 0); The stack trace also says this is being triggered from the garbage collector. Do you have a dynamic array of RefCounted objects, or one inside a class object? I'm not sure as to the nature of the bug but refcounted inside a GC object isn't going to work well anyway. * the wiki suggests that you need a debug build of the standard library to get accurate stack traces. is this just for line numbers or could the stack be completely wrong? just line numbers and I don't think it even applies here since it is a template.
Re: protected + package attributes
On 07/11/2016 02:28 PM, zodd wrote: Suppose I have a class with a few protected functions. I want to let another class from the same package call these functions. Thus I've added a "package" attribute and got the following: Error: conflicting protection attribute 'package' and 'protected' How can I achieve what I want? These member functions must be protected, I can't make them private because this is a base class intended for inheritance. Can have only one level of protection. If package is too restrictive with regards to overriding, and protected is too restrictive with regards to calling, then there's only public left. Other than that, you could add a `package` method with a different name that just calls the `protected` one.
Debugging InvalidMemoryOperationError
I am building the open source project Sambamba with LDC and running its tests. If I build it in debug configuration (-g in place of -O2) then I get an InvalidMemoryOperationError. This does not occur in release configuration. Various different platforms and debuggers (Linux, OS X, GDB, LLDB) give different quality de-mangling and stack trace output, but none seem to give local variables. Versions: LDC - the LLVM D compiler (1.0.0): based on DMD v2.070.2 and LLVM 3.8.0 built with DMD64 D Compiler v2.071.1 Default target: x86_64-unknown-linux-gnu Here is the stack from GDB (7.6.1-80.el7) on Linux: #0 0x00670a50 in onInvalidMemoryOperationError () #1 0x0068657b in gc.gc.GC.malloc() () #2 0x0067a4d2 in _d_newclass () #3 0x00670d53 in _d_assert () #4 0x0053d8e2 in std.typecons.__T10RefCountedTS4cram8wrappers54__T5RcPtrTS4cram6htslib10cram_sliceS15cram_free_sliceZ5RcPtr7PayloadVE3std8typecons24RefCountedAutoInitializei0Z.RefCounted.__dtor() () #5 0x005d39e6 in cram.wrappers.__T5RcPtrTS4cram6htslib10cram_sliceS15cram_free_sliceZ.RcPtr.__fieldDtor() () #6 0x0043a5e4 in cram.wrappers.CramSlice.__fieldDtor() () #7 0x005d4ce2 in cram.wrappers.UndecodedSliceRange.__fieldDtor() () #8 0x0067c20e in rt_finalize2 () #9 0x0068935a in gc.gc.Gcx.sweep() () #10 0x00687a1b in gc.gc.Gcx.fullcollect() () #11 0x00687bae in gc.gc.GC.fullCollectNoStack() () #12 0x0067922b in gc_term () #13 0x00679efa in rt_term () #14 0x0067a170 in _d_run_main () #15 0x00414278 in main () Questions: * does this suggest that an assert in the destructor of std.typecons.RefCounted is trying to allocate memory? * if so, is this considered a bug? * the wiki suggests that you need a debug build of the standard library to get accurate stack traces. is this just for line numbers or could the stack be completely wrong? * any further suggestions as to finding the cause of this problem?
protected + package attributes
Suppose I have a class with a few protected functions. I want to let another class from the same package call these functions. Thus I've added a "package" attribute and got the following: Error: conflicting protection attribute 'package' and 'protected' How can I achieve what I want? These member functions must be protected, I can't make them private because this is a base class intended for inheritance.
Re: How to use `format` to repeat a character
On Monday, 11 July 2016 at 10:23:24 UTC, Bahman Movaqar wrote: On 07/11/2016 02:44 PM, ketmar wrote: On Monday, 11 July 2016 at 09:31:49 UTC, Ali Çehreli wrote: What makes you expect that format should have that feature? :) I somehow recalled I could do that in C and then there was the "minimum field width" in the docs, so I thought it's possible I'm just not understanding the docs clearly :-) You can do it in D with custom format specifiers. See: https://wiki.dlang.org/Defining_custom_print_format_specifiers
Re: How to use `format` to repeat a character
On 07/11/2016 02:44 PM, ketmar wrote: > On Monday, 11 July 2016 at 09:31:49 UTC, Ali Çehreli wrote: >> What makes you expect that format should have that feature? :) I somehow recalled I could do that in C and then there was the "minimum field width" in the docs, so I thought it's possible I'm just not understanding the docs clearly :-) > the fact that format can insert spaces. it is like: "ok, it can do > spaces. i bet there should be some way to use any character instead of > space. after all, the implementation would be the same, right?!" and > then... oops. That's my story. Thanks people for your help.
Re: How to use `format` to repeat a character
On Monday, 11 July 2016 at 09:31:49 UTC, Ali Çehreli wrote: What makes you expect that format should have that feature? :) the fact that format can insert spaces. it is like: "ok, it can do spaces. i bet there should be some way to use any character instead of space. after all, the implementation would be the same, right?!" and then... oops. probably this worth a ER.
Re: How to use `format` to repeat a character
On 07/11/2016 11:31 AM, Ali Çehreli wrote: // Another one that combines multiple range algorithms import std.range : iota; import std.algorithm : map; assert(7.iota.map!(i => i % 2 ? '=' : '-').equal("-=-=-=-")); An alternative without those scary modulo and ternary operators, just because I think it's cute: import std.range: repeat, roundRobin, take; import std.algorithm: equal; assert(roundRobin(repeat('-'), repeat('=')).take(7).equal("-=-=-=-"));
Re: How to use `format` to repeat a character
On 07/11/2016 02:02 AM, Bahman Movaqar wrote: > I'm sure I'm missing something very simple but how can I create a string > like "" using `format`? You can't. > I check the docs on `format` and tried many variations including > `format("%.*c\n", 4, '-')` but got nowhere. What makes you expect that format should have that feature? :) Perhaps you're familiar with another language's standard library that does that? > I'd appreciate any hint/help on this. There are several ways of repeating characters and range elements in general: void main() { // 'replicate' copies an array (which strings are) eagerly import std.array : replicate; assert("-".replicate(3) == "---"); // 'repeat' repeats lazily import std.range : repeat; import std.algorithm : equal; assert('-'.repeat(3).equal("---")); // Another one that combines multiple range algorithms import std.range : iota; import std.algorithm : map; assert(7.iota.map!(i => i % 2 ? '=' : '-').equal("-=-=-=-")); // etc. } Ali
How to use `format` to repeat a character
I'm sure I'm missing something very simple but how can I create a string like "" using `format`? I check the docs on `format` and tried many variations including `format("%.*c\n", 4, '-')` but got nowhere. I'd appreciate any hint/help on this. -- Bahman Movaqar http://BahmanM.com - https://twitter.com/bahman__m https://github.com/bahmanm - https://gist.github.com/bahmanm PGP Key ID: 0x6AB5BD68 (keyserver2.pgp.com)