Best Practice: Alternatives to Void Pointers

2018-01-30 Thread jsako via Digitalmars-d-learn
The common C way to get a blob of generic data at runtime is to use void pointers like so: struct Structo { int type; void* data; } Then cast the void pointer to whatever data you needed based on the type. I imagine D has a better mechanism for this sort of thing, but after some

Re: Filter a Range Based on a Passed In Variable

2018-01-20 Thread jsako via Digitalmars-d-learn
On Saturday, 20 January 2018 at 19:09:28 UTC, Adam D. Ruppe wrote: On Saturday, 20 January 2018 at 19:04:06 UTC, jsako wrote: I want to be able to filter a range based on a variable known at runtime. Something like this: [code] int id = getFilterID(); auto filteredRange = filter!(a => a.id

Filter a Range Based on a Passed In Variable

2018-01-20 Thread jsako via Digitalmars-d-learn
I want to be able to filter a range based on a variable known at runtime. Something like this: [code] int id = getFilterID(); auto filteredRange = filter!(a => a.id == id)(rangeToBeFiltered); [/code] This doesn't seem to be possible, however as .filter only takes unary predicates. I tried:

Re: Getting a String Literal From an Aliased Template Mixin Parameter

2016-09-14 Thread jsako via Digitalmars-d-learn
On Thursday, 15 September 2016 at 01:40:50 UTC, Anonymouse wrote: You mean, the literal string name of the original symbol you passed as an alias? If so then you want the .stringof property. void main () { int first; bool second; string third; mixin

Getting a String Literal From an Aliased Template Mixin Parameter

2016-09-14 Thread jsako via Digitalmars-d-learn
I was making a quick mocking infrastructure for internal mocks so I wouldn't have to pass in objects to constructors all the time and came up with this: [code] mixin template internalMockRig(alias _var, string _varName, alias _varStandard, alias _varMock) { version(unittest)