Performance of tables slower than built in?

2019-05-21 Thread JS via Digitalmars-d-learn
I am trying to create some fast sin, sinc, and exponential routines to speed up some code by using tables... but it seems it's slower than the function itself?!? The code below uses matplotlibd but is not necessary. The timing code is lower. Ideally I'd like to have quadratic interpolation an

EnumToFlags

2016-06-29 Thread JS via Digitalmars-d-learn
I created a type that makes working with flags much easier. Please review for issues and enhancements. It would be nice to simplify the value size code. struct EnumToFlags(alias E) { import std.traits, std.conv, std.string, std.algorithm, std.array; static if (E.max < 8)

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread JS
On Thursday, 29 August 2013 at 08:58:02 UTC, Paul Jurczak wrote: On Thursday, 29 August 2013 at 08:26:11 UTC, Jonathan M Davis wrote: On Thursday, August 29, 2013 10:07:31 Paul Jurczak wrote: On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis wrote: [..] > as any integral value in a

Re: How do i depend on struct composition

2013-08-22 Thread JS
On Thursday, 22 August 2013 at 23:10:40 UTC, anonymous wrote: On Thursday, 22 August 2013 at 22:32:53 UTC, JS wrote: On Thursday, 22 August 2013 at 21:07:27 UTC, Mariusz `shd` Gliwiński wrote: [...] struct InnerC { void operate() { auto ptr = this-(void*).sizeof; /* do something with

Re: How do i depend on struct composition

2013-08-22 Thread JS
On Thursday, 22 August 2013 at 21:07:27 UTC, Mariusz `shd` Gliwiński wrote: Let me try to illustrate my question by following pseudo-code: struct InnerA { /* .. */ void* ptr; } struct InnerB { /* .. */ void* ptr; } struct InnerC { void operate() { auto ptr = this-(void*).sizeof;

Re: Order matters on inheritance

2013-08-22 Thread JS
On Thursday, 22 August 2013 at 08:45:36 UTC, Regan Heath wrote: On Thu, 22 Aug 2013 02:43:42 +0100, JS wrote: I don't know what the expected behavior is but it seems odd/wrong: http://dpaste.dzfl.pl/a390f1f4 Note that there are two issues here(almost the same). First is that A.foo

Order matters on inheritance

2013-08-21 Thread JS
I don't know what the expected behavior is but it seems odd/wrong: http://dpaste.dzfl.pl/a390f1f4 Note that there are two issues here(almost the same). First is that A.foo isn't called and second is that the order of inheritance on A matters(: X, Y vs : Y,X). I would expect that A.foo(A) sh

Re: Is enum static?

2013-08-20 Thread JS
On Tuesday, 20 August 2013 at 21:01:43 UTC, Jonathan M Davis wrote: On Tuesday, August 20, 2013 22:10:28 JS wrote: On Monday, 19 August 2013 at 18:28:10 UTC, Ali Çehreli wrote: > On 08/19/2013 03:18 AM, Borislav Kosharov wrote:> So if I > want > > to have a string constant it

Re: Is enum static?

2013-08-20 Thread JS
On Monday, 19 August 2013 at 18:28:10 UTC, Ali Çehreli wrote: On 08/19/2013 03:18 AM, Borislav Kosharov wrote:> So if I want to have a string constant it is a lot better to declare it as: > > static immutable string MY_STRING = "Some string"; > > Because it won't be duplicated? enum is fine wit

Re: more enum and pragma troubles

2013-08-18 Thread JS
On Monday, 19 August 2013 at 04:37:58 UTC, captaindet wrote: On 2013-08-17 21:54, JS wrote: On Sunday, 18 August 2013 at 00:17:22 UTC, captaindet wrote: On 2013-08-17 14:36, Jesse Phillips wrote: Third you've declared a variable, bar, which will store your enumerated value, 4. Variable

Re: how to get enclosing function as symbol ? (eg: __function__.stringof ==__FUNCTION__)

2013-08-17 Thread JS
On Sunday, 18 August 2013 at 01:52:50 UTC, Timothee Cour wrote: Is there any way to get the enclosing function as symbol ? I'd like something like that: alternative names would be: __function__ __context__ auto fun(alias caller=__function__)(){ //caller represents fun1!double return Re

Re: more enum and pragma troubles

2013-08-17 Thread JS
On Sunday, 18 August 2013 at 00:17:22 UTC, captaindet wrote: On 2013-08-17 14:36, Jesse Phillips wrote: Third you've declared a variable, bar, which will store your enumerated value, 4. Variables are not compile time, even if the value stored came from a compile time known value. yep, it com

Re: more enum and pragma troubles

2013-08-16 Thread JS
On Saturday, 17 August 2013 at 05:22:53 UTC, captaindet wrote: are these bugs or expected behavior? (2 issues, see code below) i thought enums are just compile time copy&paste magic so i cannot think of a reason why it should not be available at compile time... if buggy, what is broken, enum

Re: Recommended ways to handle final classes

2013-08-16 Thread JS
On Friday, 16 August 2013 at 15:47:21 UTC, Joseph Rushton Wakeling wrote: On 08/16/2013 05:40 PM, JS wrote: Can you describe how this helps? Sure, if you use A the compiler should be able to optimize method calls but you can't use A in inheritance because it is a final class. e.g.,

Re: Recommended ways to handle final classes

2013-08-16 Thread JS
On Friday, 16 August 2013 at 15:12:03 UTC, Joseph Rushton Wakeling wrote: Hi all, I'm writing some class-based code and so my concerns have turned to the issue of final classes vs. inheritance. Suppose that you want a particular class to be able to act as a base class, but also to perform at

Re: double.init is real.nan, is it a bug?

2013-08-14 Thread JS
On Thursday, 15 August 2013 at 04:01:28 UTC, bsd wrote: Hi all, I think this is a bug, but if not I'm very confused and would like some clarification. When checking double values that could be nan or unassigned I have to check both double.init and double.nan. But double.init IS double.nan.

Re: Templated structs / variant values

2013-08-14 Thread JS
On Wednesday, 14 August 2013 at 22:28:13 UTC, Marek Janukowicz wrote: I need to have a generalized "settings" functionality that should work like this: * I need to be able to add this to a class * each setting has its name, description, type and default value * I need to iterate over all setting

Fastest Delegate

2013-08-13 Thread JS
I'm wondering how stuff like http://www.codeproject.com/Articles/11015/The-Impossibly-Fast-C-Delegates?msg=1166433#xx1166433xx holds up in D? I can't quite translate it into D... anyone mind giving it a try?

Profiling Inheritance

2013-08-13 Thread JS
I am trying to profile virtual functions vs delegates http://dpaste.dzfl.pl/dd10c841 Num TreeFuncPer CallsTimeTimeCall 3 1019328 456148 152049 int main._testfooA(main.A) 3 1809331 398939 132979

Re: Get class size of object

2013-08-12 Thread JS
On Monday, 12 August 2013 at 19:44:56 UTC, Jacob Carlborg wrote: On 2013-08-12 17:49, JS wrote: Sorry but this doesn't work. b is a B, not an A. try I a = new A; I b = new B; Right, forgot about the interface. NP, happens to all of us. Simen's method of casting to object s

Re: Get class size of object

2013-08-12 Thread JS
On Monday, 12 August 2013 at 11:34:25 UTC, Jacob Carlborg wrote: On 2013-08-11 21:08, Simen Kjaeraas wrote: If you're looking for a no-overhead solution, then this might not be good enough. I'm surprised that a virtual function call is fine, though. How about this: interface I { size_t

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 20:03:27 UTC, Adam D. Ruppe wrote: On Sunday, 11 August 2013 at 19:58:26 UTC, Adam D. Ruppe wrote: Oh, I see it now. I think typeid(interface) gives a different set of info. Thinking about it a bit more, this makes sense because an interface is not necessarily an

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 19:06:07 UTC, Adam D. Ruppe wrote: On Sunday, 11 August 2013 at 18:33:19 UTC, JS wrote: The code below does this, but at a cost of verbosity. I don't see what the difference is in functionality - it looks to me that you just reimplemented what the compiler

Re: Get class size of object

2013-08-11 Thread JS
BTW, I hope that if you want to be added to the ignore list on my side, you use the script and do the same. I know some will want everyone to see their irrelevant posts but I won't see it and so you will never get a response from me and it just clutters up the NG and distracts from D.

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 19:08:58 UTC, Simen Kjaeraas wrote: On 2013-08-11, 20:33, JS wrote: I think you're missing the point to some degree(I realize there is a diff between an object and a type, but I should be able to easily get the class size of an object at run time regardle

Re: Get class size of object

2013-08-11 Thread JS
I think you're missing the point to some degree(I realize there is a diff between an object and a type, but I should be able to easily get the class size of an object at run time regardless if the object is typed as a base class). The code below does this, but at a cost of verbosity. Here is

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 18:15:28 UTC, Timon Gehr wrote: On 08/11/2013 07:26 PM, JS wrote: On Sunday, 11 August 2013 at 17:12:48 UTC, Timon Gehr wrote: On 08/11/2013 05:28 PM, JS wrote: On Sunday, 11 August 2013 at 13:40:41 UTC, Timon Gehr wrote: On 08/11/2013 06:25 AM, JS wrote: Given

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 18:18:22 UTC, Dicebot wrote: On Sunday, 11 August 2013 at 17:03:04 UTC, JS wrote: This is essentially what I'm doing BUT I am trying to avoid having to repeat the exact same crap in every class because it is time consuming, verbose, and error prone.

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 17:19:21 UTC, Adam D. Ruppe wrote: On Sunday, 11 August 2013 at 17:03:04 UTC, JS wrote: For those that care, here is a snippet of what I am doing. What are you actually going to use the number for? If you are going to write your own New function, you'll nee

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 17:12:48 UTC, Timon Gehr wrote: On 08/11/2013 05:28 PM, JS wrote: On Sunday, 11 August 2013 at 13:40:41 UTC, Timon Gehr wrote: On 08/11/2013 06:25 AM, JS wrote: Given an object, is there a built in way to get the size of the class the object represents? Yes

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 16:43:09 UTC, Dicebot wrote: On Sunday, 11 August 2013 at 16:40:48 UTC, Maxim Fomin wrote: Yes, this is answer to the question. By the way, it can be simply enum S = typeid(Whatever).init.length; If exact type is statically known, no ClassInfo is required: enum

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 15:38:04 UTC, Tobias Pankrath wrote: Is this a mathematical fact that you have proven for all languages? I'd like to see your proof if it's not bigger than what will fit in a post. That's so obvious, that you should be able to come up with one yourself. Maybe you

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 09:30:32 UTC, Tobias Pankrath wrote: On 11.08.2013 06:25, JS wrote: Given an object, is there a built in way to get the size of the class the object represents? The object may be instantiated with a derived instance of the object type, so using classInstanceSize

Re: Get class size of object

2013-08-11 Thread JS
On Sunday, 11 August 2013 at 13:40:41 UTC, Timon Gehr wrote: On 08/11/2013 06:25 AM, JS wrote: Given an object, is there a built in way to get the size of the class the object represents? Yes. Troll.

Get class size of object

2013-08-10 Thread JS
Given an object, is there a built in way to get the size of the class the object represents? The object may be instantiated with a derived instance of the object type, so using classInstanceSize doesn't work on the type of the object. I can obviously go through the trouble of adding a class me

Re: Virtual templates members

2013-08-08 Thread JS
On Thursday, 8 August 2013 at 17:32:56 UTC, Nicolas Sicard wrote: On Thursday, 8 August 2013 at 16:58:37 UTC, JS wrote: On Thursday, 8 August 2013 at 07:21:19 UTC, Nicolas Sicard wrote: On Thursday, 8 August 2013 at 01:48:49 UTC, JS wrote: The following code is used to reduce dependence on new

Re: Virtual templates members

2013-08-08 Thread JS
On Thursday, 8 August 2013 at 07:21:19 UTC, Nicolas Sicard wrote: On Thursday, 8 August 2013 at 01:48:49 UTC, JS wrote: The following code is used to reduce dependence on new and the GC. iNew is used as the replacement. The problem is, where ever New is used, it requires typing the type

Virtual templates members

2013-08-07 Thread JS
The following code is used to reduce dependence on new and the GC. iNew is used as the replacement. The problem is, where ever New is used, it requires typing the type twice. e.g., A.New!A(...) instead of A.New(...) Is there any way to solve this issue? (iNew is suppose to provide the con

Re: Which option is faster...

2013-08-05 Thread JS
On Monday, 5 August 2013 at 13:59:24 UTC, jicman wrote: Greetings! I have this code, foreach (...) { if (std.string.tolower(fext[0]) == "doc" || std.string.tolower(fext[0]) == "docx" || std.string.tolower(fext[0]) == "xls" || std.string.tolower(fext[0]) == "xlsx" || std.stri

Re: Is this a good pattern for allocation?

2013-08-05 Thread JS
On Monday, 5 August 2013 at 12:41:19 UTC, Tobias Pankrath wrote: On Monday, 5 August 2013 at 08:11:59 UTC, JS wrote: I guess you mean that I should use a template as a factory instead of an interface? I'll have to think about it to see what the pro's and con's of each are

Re: Is this a good pattern for allocation?

2013-08-05 Thread JS
On Monday, 5 August 2013 at 07:15:30 UTC, Tobias Pankrath wrote: On Monday, 5 August 2013 at 01:47:26 UTC, JS wrote: Anyways, is this a bad or good way and how can I call Factory to get a new object? (I know that ther is .init and other stuff that can be used by Factor/New. I'm just tryi

Is this a good pattern for allocation?

2013-08-04 Thread JS
Trying to avoid GC dependence on my objects. interface Alloc(T) { T New(A...)(A args); //final T Factory(A...)(T, A args) { return new T(args); } } class A(T) : Alloc!(A!(T)) { static A!T New() { return new A!T();// Use GC for now // Factor(A

Re: Debugging templates!

2013-08-03 Thread JS
On Saturday, 3 August 2013 at 14:04:10 UTC, JS wrote: There has to be a better way?!?!?!?! Of course, I mean string mixin's using template.. and the statement was to ask people how they went about it...

Debugging templates!

2013-08-03 Thread JS
There has to be a better way?!?!?!?!

Re: Simulating sub types

2013-08-02 Thread JS
On Friday, 2 August 2013 at 13:57:08 UTC, Dicebot wrote: On Friday, 2 August 2013 at 13:37:09 UTC, JS wrote: Then that doesn't help. Do you mean A.B is not visible outside the module either? Can B be instantiated and inherited when static, if not then it is no use. Yes, A will act simp

Re: Simulating sub types

2013-08-02 Thread JS
On Friday, 2 August 2013 at 12:29:02 UTC, Meta wrote: On Friday, 2 August 2013 at 11:47:46 UTC, bearophile wrote: JS: the fact remains that I can't do it in Dlang. Is tagging the inner class as static helping? class A { static class B { ... } } Bye, bearophile Just to be

Simulating sub types

2013-08-02 Thread JS
Nesting classes is strange to me in Dlang because it adds a parent pointer to the parent class. I don't see the point of this and it seems like an anti-feature. If we wanting that pattern we could implement it ourselves. I suppose in some cases it can be useful but in my case it breaks logical

Get attributes of type by string name

2013-08-01 Thread JS
how can I get the UDA's of a type that I only know by name and only in a CTFE. I would like to loop over an array of names passed to a me(I don't know their contents beforehand) and get the attributes. I've tried to use a mixin but I can't get the mixin to work on the string name... e.g.,

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 22:26:06 UTC, Dicebot wrote: On Thursday, 1 August 2013 at 22:04:57 UTC, JS wrote: IS A GOING TO BE IN THE BINARY?!?!?! Yes, I'm yelling... just to get the point across about the question I'm trying to get answered. HOW MANY TIMES I NEED TO ANSWER YOU

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 22:13:25 UTC, John Colvin wrote: On Thursday, 1 August 2013 at 22:04:57 UTC, JS wrote: IS A GOING TO BE IN THE BINARY?!?!?! Why don't you try it and see? Disassemble the object file or get your linker of choice to print out some info. I don't have

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 21:17:34 UTC, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 10:06:54PM +0200, JS wrote: [...] Now are you telling me that template A() { void foo() { writeln("asdf"); } } void main() { A!().foo(); } does not create a function foo in the binary?

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 18:09:54 UTC, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:52:28PM +0200, JS wrote: On Thursday, 1 August 2013 at 17:47:00 UTC, H. S. Teoh wrote: >On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: >>On Thursday, 1 August 2013 at 17:09:07 UTC,

Re: Emulating enums

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 16:36:34 UTC, Ali Çehreli wrote: On 08/01/2013 03:29 AM, JS wrote: > On Thursday, 1 August 2013 at 05:22:46 UTC, Ali Çehreli wrote: >> On 07/31/2013 06:10 PM, JS wrote: >>> http://dpaste.dzfl.pl/dbb40dbc >>> >>> The code was p

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 17:53:38 UTC, Ali Çehreli wrote: On 08/01/2013 10:45 AM, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: If I have a bunch of templates that are only used for code generation

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 17:47:00 UTC, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: >If I have a bunch of templates that are only used for code >generation, are they removed in the binary(since th

are mixin string templates with functions removed?

2013-08-01 Thread JS
If I have a bunch of templates that are only used for code generation, are they removed in the binary(since they are not needed)?

Re: Emulating enums

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 16:36:34 UTC, Ali Çehreli wrote: On 08/01/2013 03:29 AM, JS wrote: > On Thursday, 1 August 2013 at 05:22:46 UTC, Ali Çehreli wrote: >> On 07/31/2013 06:10 PM, JS wrote: >>> http://dpaste.dzfl.pl/dbb40dbc >>> >>> The code was p

Named UDA's

2013-08-01 Thread JS
I guess D doesn't support named UDA's directly? e.g., @(Name = "My Name", Other = .34) It would be nice to have the ability to have an "attribute" hierarchy where looking up attributes on objects could easily be done. e.g., @(Name = "s", Other = 2) struct s { @(Name = "q", Default_Valu

Re: Emulating enums

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 05:22:46 UTC, Ali Çehreli wrote: On 07/31/2013 06:10 PM, JS wrote: http://dpaste.dzfl.pl/dbb40dbc The code was pared down from a lot of string mixin code generation. I nest the structs because I want a nested enums. I don't want have to have eStat

Emulating enums

2013-07-31 Thread JS
http://dpaste.dzfl.pl/dbb40dbc The code was pared down from a lot of string mixin code generation. I nest the structs because I want a nested enums. I don't want have to have eState and eStateType but eState and eState.Type. Having the ability to nest enums would solve my problem. Regardles

Re: Alias/template for value

2013-07-31 Thread JS
On Wednesday, 31 July 2013 at 11:15:31 UTC, Joseph Rushton Wakeling wrote: Hi all, When playing with the graph library code, I noticed something odd. Here's a function to calculate the neighbours of a vertex: auto neighbours(immutable size_t v) { immutable size_t

Weird bug in IFTI

2013-07-30 Thread JS
http://dpaste.dzfl.pl/cdabf9fa But adding one more parameter gives an error! http://dpaste.dzfl.pl/a5cfac37 Template has no effect simply because I added an parameter with a default?!?!?!?

Re: Get template name

2013-07-30 Thread JS
On Tuesday, 30 July 2013 at 11:25:38 UTC, Dicebot wrote: On Tuesday, 30 July 2013 at 11:04:10 UTC, JS wrote: 1. No, the code actually will print the message but the error shows up right after(well, depends on which error, the one I get inside templates works fine except the without the

Re: use template function without assignment

2013-07-30 Thread JS
BTW, when I use mixin in my code, the error goes away but no pragma msg is produced, so it is not a solution.

Re: use template function without assignment

2013-07-30 Thread JS
On Tuesday, 30 July 2013 at 20:34:32 UTC, Ali Çehreli wrote: On 07/30/2013 12:09 PM, JS wrote: > I already stated why this is not a proper example, I'm not using Pragma > in run time code(for lack of a better term). > > module main; > > import std.stdio; > >

Re: use template function without assignment

2013-07-30 Thread JS
de *I* provided). Ditto. JS, I wrote the following code for you. Could you please start with it and show us the problem that we are trying to solve. template Pragma(alias amsg) { void Pragma(string file = __FILE__) { pragma(msg, amsg); } } void main() { enum msg = "h

Re: Get template name

2013-07-30 Thread JS
On Tuesday, 30 July 2013 at 11:25:38 UTC, Dicebot wrote: On Tuesday, 30 July 2013 at 11:04:10 UTC, JS wrote: 1. No, the code actually will print the message but the error shows up right after(well, depends on which error, the one I get inside templates works fine except the without the

Re: Get template name

2013-07-30 Thread JS
On Tuesday, 30 July 2013 at 10:45:26 UTC, Dicebot wrote: On Tuesday, 30 July 2013 at 06:45:31 UTC, JS wrote: void f() { pragma(msg, __FUNCTION__); } template t() { pragma(msg, __FUNCTION__); } void main(string[] argv) { readln(); } the function displays main.f. The

Re: use template function without assignment

2013-07-30 Thread JS
On Tuesday, 30 July 2013 at 07:12:11 UTC, Namespace wrote: On Monday, 29 July 2013 at 23:09:20 UTC, JS wrote: I have created a template Pragma that emulates pragma but better, the problem is that I have to assign it to something which is very redundant in my code: enum temp = Pragma!(msg

Re: use template function without assignment

2013-07-30 Thread JS
On Tuesday, 30 July 2013 at 01:19:23 UTC, Meta wrote: On Tuesday, 30 July 2013 at 01:06:39 UTC, Meta wrote: Does this code do what you want, or are there other requirements as well? void Pragma(alias amsg)(string file = __FILE__) { pragma(msg, amsg); } Actually, sorry, that's the exa

Re: Get template name

2013-07-29 Thread JS
On Tuesday, 30 July 2013 at 06:36:12 UTC, Dicebot wrote: On Monday, 29 July 2013 at 23:02:57 UTC, JS wrote: __FUNCTION__ does not return anything when used in templates. For debugging purposes I sometimes use pragma(msg, template_name); (with template_name being the name of the template

use template function without assignment

2013-07-29 Thread JS
I have created a template Pragma that emulates pragma but better, the problem is that I have to assign it to something which is very redundant in my code: enum temp = Pragma!(msg) e.g., template Pragma(alias amsg) { string Pragma(string file = __FILE__) { pragma(msg, amsg);

Get template name

2013-07-29 Thread JS
__FUNCTION__ does not return anything when used in templates. For debugging purposes I sometimes use pragma(msg, template_name); (with template_name being the name of the template assigned an enum) I would like to make this more general such as pragma(msg, mixin(__FUNCTION_NAME__)); e.g.,

untuple a tuple

2013-07-29 Thread JS
if I have something like template t(args...) { pragma(msg, args); } it prints out args in a tuple... e.g., tuple!(...) I do not want it to print out the tuple!(). I can write my own pragma and pass each arg to it (e.g., pragma(msg, arg[0], arg[1], ...)) but this is not very general and

Re: Generic string join

2013-07-29 Thread JS
On Monday, 29 July 2013 at 09:01:36 UTC, JS wrote: Here is a optimal generic string joiner that maximizes compiler optimization, allows for a variable number of arguments that can be strings or arrays of strings. http://dpaste.dzfl.pl/0a021e1f Drawbacks: 1. Static if explosion 2. Not

Generic string join

2013-07-29 Thread JS
Here is a optimal generic string joiner that maximizes compiler optimization, allows for a variable number of arguments that can be strings or arrays of strings. http://dpaste.dzfl.pl/0a021e1f Drawbacks: 1. Static if explosion 2. Not elegant 3. Only works with RT strings or RT stri

Re: static foreach and inline if

2013-07-28 Thread JS
On Sunday, 28 July 2013 at 09:11:55 UTC, anonymous wrote: On Sunday, 28 July 2013 at 08:38:40 UTC, JS wrote: On Sunday, 28 July 2013 at 08:38:01 UTC, JS wrote: On Sunday, 28 July 2013 at 08:30:17 UTC, QAston wrote: On Saturday, 27 July 2013 at 17:14:35 UTC, JS wrote: I'd like to have fo

Re: static foreach and inline if

2013-07-28 Thread JS
The following works but is somewhat of a hack... module main; import std.stdio, std.typetuple; struct tTupleSplit { } template tIndexOf(T, args...) { static if (staticIndexOf!(T, args) < 0) enum tIndexOf = args.length; else enum tIndexOf = staticIndexOf!(T, args); } template tMin(a

Re: static foreach and inline if

2013-07-28 Thread JS
On Sunday, 28 July 2013 at 08:30:17 UTC, QAston wrote: On Saturday, 27 July 2013 at 17:14:35 UTC, JS wrote: I'd like to have foreach and inline if in templates: inline if is available as std.traits.Select This doesn't work for variadic args... Something Split!(Cond, targ..., sp

Re: static foreach and inline if

2013-07-28 Thread JS
On Sunday, 28 July 2013 at 08:38:01 UTC, JS wrote: On Sunday, 28 July 2013 at 08:30:17 UTC, QAston wrote: On Saturday, 27 July 2013 at 17:14:35 UTC, JS wrote: I'd like to have foreach and inline if in templates: inline if is available as std.traits.Select This doesn't work fo

Array reduction

2013-07-27 Thread JS
I have the following code, in which I would like to try and simplify tUnrollArgs which I find to be a mess because of all the redundant code in it(having a static ternary if would definitely simplify things. (the tIf would help if I could "box" the args in an array easily so I could allow for a

Re: static foreach and inline if

2013-07-27 Thread JS
On Saturday, 27 July 2013 at 19:06:48 UTC, anonymous wrote: On Saturday, 27 July 2013 at 17:14:35 UTC, JS wrote: The tIf doesn't work properly but I'm not sure why [...] template tIf(bool cond, alias T) Lower case 'f' here, ... { static if (cond) alias tIF

Re: Closures not yet supported in CTFE's

2013-07-27 Thread JS
On Saturday, 27 July 2013 at 17:18:29 UTC, H. S. Teoh wrote: On Sat, Jul 27, 2013 at 06:47:04PM +0200, JS wrote: When I try to pass a lambda to a template, I get the subject error. (string x) => { return x~"1"; } Drop the "=>", that syntax doesn't do what y

Re: static foreach and inline if

2013-07-27 Thread JS
BTW, it works with static if's, I'm trying to use an inline if to reduce redundant code since there is no static ?:.

static foreach and inline if

2013-07-27 Thread JS
I'd like to have foreach and inline if in templates: The tIf doesn't work properly but I'm not sure why template tuple(args...) { alias tuple = args; } template tIf(bool cond) { alias tIf = tuple!(); } template tIf(bool cond, alias T) { static if (cond) alias tIF = T; else alias tIF =

Closures not yet supported in CTFE's

2013-07-27 Thread JS
When I try to pass a lambda to a template, I get the subject error. (string x) => { return x~"1"; } But when I jsut do (string x) => x~"1" it works Come on!!!

Re: Module-based programming

2013-07-26 Thread JS
On Friday, 26 July 2013 at 11:58:13 UTC, John Colvin wrote: On Friday, 26 July 2013 at 11:42:25 UTC, JS wrote: On Friday, 26 July 2013 at 09:12:27 UTC, Land wrote: I'm confused when it comes to modules. I've read somewhere that modules are basically 'singleton classes' an

Re: Module-based programming

2013-07-26 Thread JS
On Friday, 26 July 2013 at 09:12:27 UTC, Land wrote: I'm confused when it comes to modules. I've read somewhere that modules are basically 'singleton classes' and that anything that doesn't need its own state should not needlessly be put inside a class. But what if I want to create a simple O

Re: Can't use variadic arguments to functions that use templates

2013-07-23 Thread JS
On Tuesday, 23 July 2013 at 19:14:26 UTC, H. S. Teoh wrote: On Tue, Jul 23, 2013 at 08:54:12PM +0200, Jesse Phillips wrote: On Tuesday, 23 July 2013 at 16:22:38 UTC, JS wrote: >On Tuesday, 23 July 2013 at 16:15:03 UTC, Jesse Phillips >wrote: >>On Tuesday, 23 July 2013 at 14:0

Re: Can't use variadic arguments to functions that use templates

2013-07-23 Thread JS
On Tuesday, 23 July 2013 at 16:15:03 UTC, Jesse Phillips wrote: On Tuesday, 23 July 2013 at 14:03:01 UTC, JS wrote: I don't think you understand(or I've already got confused)... I'm trying to use B has a mixin(I don't think I made this clear). I can't use it as a

Re: Can't use variadic arguments to functions that use templates

2013-07-23 Thread JS
On Monday, 22 July 2013 at 16:48:56 UTC, Jesse Phillips wrote: On Sunday, 21 July 2013 at 07:22:08 UTC, JS wrote: void foo(T...)(T t) { pragma(msg, B(t)); } void main() { foo("x", "a", "b"); din.getc(); } does work. I need to have B genera

Re: Dpaste vs dmd 2.063.2 errors

2013-07-23 Thread JS
On Tuesday, 23 July 2013 at 12:59:11 UTC, monarch_dodra wrote: On Tuesday, 23 July 2013 at 12:26:31 UTC, JS wrote: http://dpaste.dzfl.pl/27ca3fbd The code compiles fine on my computer. On DPaste there is all kinds of errors(when fixing one other errors pop up. I am compiling to 32-bit

Dpaste vs dmd 2.063.2 errors

2013-07-23 Thread JS
http://dpaste.dzfl.pl/27ca3fbd The code compiles fine on my computer. On DPaste there is all kinds of errors(when fixing one other errors pop up. I am compiling to 32-bit binary and that is the only real difference I can see, but surely it wouldn't result in such errors? The first error:

Re: Code generation tricks

2013-07-22 Thread JS
On Monday, 22 July 2013 at 21:04:42 UTC, John Colvin wrote: On Sunday, 21 July 2013 at 17:24:11 UTC, JS wrote: This seems to be a somewhat efficient string splitter http://dpaste.dzfl.pl/4307aa5f The basic idea is for(int j = 0; j < s.length; j++) { mixin(ExpandVariadicIf!(&quo

Re: Code generation tricks

2013-07-22 Thread JS
On Monday, 22 July 2013 at 21:04:42 UTC, John Colvin wrote: On Sunday, 21 July 2013 at 17:24:11 UTC, JS wrote: This seems to be a somewhat efficient string splitter http://dpaste.dzfl.pl/4307aa5f The basic idea is for(int j = 0; j < s.length; j++) { mixin(ExpandVariadicIf!(&quo

Re: Why is size_t unsigned?

2013-07-22 Thread JS
On Monday, 22 July 2013 at 12:51:31 UTC, Andrej Mitrovic wrote: On 7/22/13, JS wrote: foreach doesn't allow you to modify the index to skip over elements. It does: - import std.stdio; void main() { int[] x = [1, 2, 3, 4, 5]; foreach (ref i; 0 .. 5) { writel

Re: Why is size_t unsigned?

2013-07-22 Thread JS
On Monday, 22 July 2013 at 07:12:07 UTC, monarch_dodra wrote: On Monday, 22 July 2013 at 03:47:36 UTC, JS wrote: Doing simple stuff like for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is empty. To make right one has to reduce performance by writing extra checks.

Re: Why is size_t unsigned?

2013-07-21 Thread JS
On Monday, 22 July 2013 at 04:31:12 UTC, H. S. Teoh wrote: On Mon, Jul 22, 2013 at 05:47:34AM +0200, JS wrote: Doing simple stuff like for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is empty. To make right one has to reduce performance by writing extra checks. I&#x

Re: Why is size_t unsigned?

2013-07-21 Thread JS
On Monday, 22 July 2013 at 03:58:31 UTC, Ali Çehreli wrote: On 07/21/2013 08:47 PM, JS wrote: > Doing simple stuff like > > for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is > empty. To make right one has to reduce performance by writing extra checks. Checks

Why is size_t unsigned?

2013-07-21 Thread JS
Doing simple stuff like for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is empty. To make right one has to reduce performance by writing extra checks. There seems to be no real good reason why size_t is unsigned... Surely one doesn't require too many strings larger than 2^6

  1   2   3   >