design-choices

why do STL containers use copying to populate in resize?

♀尐吖头ヾ 提交于 2019-12-24 16:17:27
问题 all the STL containers that implement resize use copies to populate the new elements even if the source of the copy is a default constructed object? Why is it done this way? I see no advantage and some cost. As context, I ran across this while looking for a random access container for elements that can't be copied: 回答1: It saves on complexity. We certainly need the copy-construction case, and default-construction can be modeled as replicating a default-constructed object. The performance

Java generics - why is “extends T” allowed but not “implements T”?

流过昼夜 提交于 2019-11-26 03:07:49
I wonder if there is a special reason in Java for using always " extends " rather than " implements " for defining bounds of typeparameters. Example: public interface C {} public class A<B implements C>{} is prohibited but public class A<B extends C>{} is correct. What is the reason for that? There is no semantic difference in the generic constraint language between whether a class 'implements' or 'extends'. The constraint possibilities are 'extends' and 'super' - that is, is this class to operate with assignable to that other one (extends), or is this class assignable from that one (super).

Java generics - why is “extends T” allowed but not “implements T”?

独自空忆成欢 提交于 2019-11-26 00:51:25
问题 I wonder if there is a special reason in Java for using always \" extends \" rather than \" implements \" for defining bounds of typeparameters. Example: public interface C {} public class A<B implements C>{} is prohibited but public class A<B extends C>{} is correct. What is the reason for that? 回答1: There is no semantic difference in the generic constraint language between whether a class 'implements' or 'extends'. The constraint possibilities are 'extends' and 'super' - that is, is this