digitalmars.D.bugs - [Issue 5347] New: Add constructors for primitive types to make pointers easier to use
- d-bugmail puremagic.com (30/30) Dec 13 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5347
- d-bugmail puremagic.com (14/14) Dec 13 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5347
- d-bugmail puremagic.com (18/18) Dec 13 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5347
- d-bugmail puremagic.com (16/16) Dec 13 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5347
- d-bugmail puremagic.com (12/15) Dec 13 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5347
- d-bugmail puremagic.com (12/12) Jan 12 2013 http://d.puremagic.com/issues/show_bug.cgi?id=5347
http://d.puremagic.com/issues/show_bug.cgi?id=5347 Summary: Add constructors for primitive types to make pointers easier to use Product: D Version: unspecified Platform: Other OS/Version: Linux Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: jmdavisProg gmx.com PST --- I'd like to be able to do something like this: int* i = new int(7); It would create a new pointer to int where the int that it points to has a value of 7. But that code results in the compiler complaining that there is no constructor for int, and as far as I can tell the only way to do it so the far less elegant and definitely less compact: int* i = new int; *i = 7; Ideally, you'd be able to use the first syntax for all primitive types. As it is however, you can only use it for structs (and classes if you're using a reference rather than a pointer). This seems unnecessarily limiting. In fact, I thought that the first syntax _was_ legal, and it threw me off when it didn't work (just goes to show how rarely I use pointers, I guess). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 13 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5347 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies gmail.com This doesn't seem like something that would be used very often. You could instead use int* i = [7].ptr; which should generate the same code, due to the way primitive types are allocated. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 13 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5347 Jonathan M Davis <jmdavisProg gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- OS/Version|Linux |All PST --- Not useful very often? How about every time that you create a pointer to an int (or any other primitive type) and want to immediately initialize the value that's pointed to? It seems like it would be _highly_ useful whenever dealing with pointers to primitives. If it's not useful very often, it's because pointers aren't used very often. And a syntax such as new int(7) or new bool(true) would be completely consistent with all of the other types. In fact, adding it would make the language _more_ consistent, not less. This would be particularly true when writing generic code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 13 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5347 I agree it would be more consistent that way, for value types. void f(T)(T v) { auto x = new T(v); // what if T is a class, array, static array etc? } A search of my own code doesn't come up with any instances of allocating a single value type like this. Searching phobos gives two instances, both in unittests. If it's not used very often, what's the point of adding syntax for it? Just saying. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 13 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5347 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs eml.ccNot useful very often? How about every time that you create a pointer to an int (or any other primitive type) and want to immediately initialize the value that's pointed to?The syntax is supported for structs and unions. So please show some use cases for ints, floats, etc. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 13 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5347 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |DUPLICATE Issue 9112 has a pull. *** This issue has been marked as a duplicate of issue 9112 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 12 2013