help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Realizing memdup() compactly in C++


From: Sebastian Waschik
Subject: Re: Realizing memdup() compactly in C++
Date: 14 May 2009 21:02:24 +0200
User-agent: Gnus/42.00 (Gnus v42.0.0) Emacs/42.0

Hello,

Nordlöw <per.nordlow@gmail.com> writes:

> Han anybody written any snippet (template i guess) that realizes memdup
> () using the operator new. Suggested name: new_duplicate.

are you looking for something like this?

template <class T>
T* new_duplicate(const T *const value)
{
  if (!value) {
    return 0;
  } else {
    return new T(*value);
  }
}


But:
Without the check for null, I do not see any advance calling this
function directly compared to a direct call of the copy constructor.

Greetings from Hamburg
Sebastian Waschik





reply via email to

[Prev in Thread] Current Thread [Next in Thread]