D hackers requested. Dancing around postblit.

IgorStepanov via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 5 11:36:01 PST 2014


Please try to solve this task:
We have a struct S.
S has a some kind of postblit (user-defined or inherited frome 
field) and destructor. S has a @disabled opAssign.
We have an unitialized allocated memory block whick mapped to a S 
array.
struct S
{
    //postblit and dtor here
}
S[] data; // contains a garbarge

void emplace()(ref S val, size_t i);

The task: we should write emplace function, which initializes 
i-th element of data with val;
This function shouldn't call any dtors for example for the old 
data[i] (which contains a garbarge).
This function should be transparent for attributes. For example, 
if S postblit is nothrow emplace should be nothrow too. If S 
postblit is not nothrow, S should't be nothrow.
This function should call postblit only one time and shouldn't 
call any other S special functions (opAssign, ctor etc.)


More information about the Digitalmars-d mailing list