【发布时间】:2017-06-11 09:25:12
【问题描述】:
我需要从结构数组中删除元素,例如值3。
这是我的代码:
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.algorithm;
import std.conv;
void main()
{
struct Point
{
int order;
int pos;
int val;
}
Point point;
Point [] points;
point.order = 1;
point.pos = 1;
point.val = 1;
points ~= point;
point.order = 2;
point.pos = 4;
point.val = 2;
points ~= point;
point.order = 3;
point.pos = 14;
point.val = 3;
points ~= point;
point.order = 4;
point.pos = 24;
point.val = 1;
points ~= point;
writeln(points);
}
我想这样做:
points.map!(a=>a.val.canFind(3).drop);
但这是行不通的。我需要更改原始 points 数组并从中删除元素。
【问题讨论】: