DMD 0.177 release

Alexander Panek a.panek at brainsware.org
Sat Dec 9 08:53:07 PST 2006


Those are newCharz and newChars, of course.

Apart from that, this might be interesting, too:

// alias thingie array;

template Ptr (T) {
	// Create a simple thingie
	T *newPtrs ( size_t size ) {
		return (new T[size]).ptr;
	}

	// Create null-terminated thingie
	T *newPtrz ( size_t size ) {
		T *p = (new T[size + 1]).ptr
		p[$ - 1] = '\0';

		return p;
	}
}

alias Ptr!(char).newPtrs newChars;
alias Ptr!(char).newPtrz newCharz;

Not tested, but this might be useful for someone.

Alexander Panek wrote:
> Chris Miller wrote:
>> On Sat, 09 Dec 2006 11:33:17 -0500, Alexander Panek 
>> <a.panek at brainsware.org> wrote:
>>
>>> char *newCharz( uint size ) {
>>>     return (new char [size]).ptr;
>>> }
>>>
>>> char *p = newCharz(32);
>>>
>>> :P
>>>
>>> I like the explicity.
>>
>> Well, I'm not sure what it should be, but you already made a mistake: 
>> it should be size_t instead of uint ;)
>>
>> Plus, I never said it was a zero-terminated string.
> 
> Oi. Sorry:
> 
> char * toChars( size_t size ) {
>     return (new char[size]).ptr;
> }
> 
> char * toCharz( size_t size ) {
>     return (new char[size + 1]).ptr;
> }
> 
> Better? :P
>>
>>>
>>> Chris Miller wrote:
>>>>  char* p = new char[32];
>>>>  Error: cannot implicitly convert expression (new char[](32)) of 
>>>> type char[] to char*
>>>>  Should this be a special case? Currently it needs  (new char[32]).ptr
>>



More information about the Digitalmars-d-announce mailing list