正文

数组dup的实现2006-02-05 14:05:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/nothing/9989.html

分享到:

Xref: digitalmars.com digitalmars.D:22525
Original Text:
    Why there is no .dup property of AAs? And if .dup is used for array of, lets say, stucts that have another array as member is it duplicated too or if I modify it in the dup array the original will be modified too?

foo[bar] dup( foo[bar] arr )
{
   foo[bar] copy;
   foreach( bar key, foo val ; arr )
      copy[key]=val;
   return copy;
}

--------------------------------------------------------

泛型实现

template dup(Key, Value)
{
    Value[Key] dup(Value[Key] aa)
    {
         Value[Key] copy;
         foreach( Key key, Value val ; aa ) { copy[key]=val; }
         return copy;
    }
}

阅读(3577) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册