English 中文(简体)
为什么Go像包切割了+帕斯特的食宿?
原标题:Why does the Go image package cut+paste looping over pixels?
最佳回答

There is a limitation to the type system which prevents a general solution (or at least makes it very inefficient).

例如,阿根廷移民总局的机构。 Opaque和NRGBA。 Opaque是一样的,因此,你认为,可以将它们纳入具有类似签名的第三个职能:

func opaque(pix []Color, stride int, rect Rectangle) bool

请将此职能称为:

func (p *RGBA) Opaque() bool {
    return opaque([]Color(p.Pix), p.Stride, p.Rect)
}

But you can t. p.Pix can t be converted to []Color because those types have different in-memory representations and the spec forbids it. We could allocate a new slice, convert each individual element of p.Pix, and pass that, but that would be very inefficient.

认为阿根廷移民总局和阿根廷移民总局拥有同样的结构。 或许我们可以将这两种功能排除在外,因为皮尔斯的内层代表完全相同:

func opaque(pix []RGBAColor, stride int, rect Rectangle) bool

func (p *NRGBA) Opaque() bool {
    return opaque([]RGBAColor(p.Pix), p.Stride, p.Rect)
}

Alas, again this isn t allowed. This seems to be more of a spec/language issue than a technical one. I m sure this has come up on the mailing list before, but I can t find a good discussion of it.

这似乎像一个通商会聚居的领域,但是在戈尔没有解决非专利问题。

问题回答

Why does Go not have generic types?

Generics may well be added at some point. We don t feel an urgency for them, although we understand some programmers do.

Generics are convenient but they come at a cost in complexity in the type system and run-time. We haven t yet found a design that gives value proportionate to the complexity, although we continue to think about it. Meanwhile, Go s built-in maps and slices, plus the ability to use the empty interface to construct containers (with explicit unboxing) mean in many cases it is possible to write code that does what generics would enable, if less smoothly.

这仍然是一个开放的问题。





相关问题
Allow user to change the default web part styles

I have a web part which uses many SharePoint controls like menu, SPGrid, tool bar etc. I want the user to be able to change the style by specifying an external CSS file. Can somebody tell me how I ...

using jqgrid style for usual Table in asp.net mvc

I d prefer using Table and td instead of JqGrid but i like JqGrid styles. has anyone used jqgrid style for usual Grid of asp.net MVC(i mean Table and td) before?

热门标签