STL - does every compiler implement it differently?

前端 未结 5 1673
臣服心动
臣服心动 2020-12-18 13:48

It was said to me that the standard template library is differently implemented by every compiler, is this correct?

How can computational complexity (both in time an

5条回答
  •  眼角桃花
    2020-12-18 14:25

    An example of the actual standard may be helpful to clarify, and unordered_* is a good one I think, since it was added specifically to get a hash table into the standard. This quote is from a draft but I expect the final version is substantially similar:

    23.5.4.4 unordered_map modifiers

    template 
    pair insert(P&& obj);
    
    1. Requires: value_type is constructible from std::forward

      (obj).

    2. Effects: Inserts obj converted to value_type if and only if there is no element in the container with key equivalent to the key of value_type(obj).
    3. Returns: The bool component of the returned pair object indicates whether the insertion took place and the iterator component points to the element with key equivalent to the key of value_type(obj).
    4. Complexity: Average case O(1), worst case O(size()).
    5. Remarks: This signature shall not participate in overload resolution unless P is implicitly convertible to value_type.

    Other parts of the standard effectively require it be implemented as a hash table too, but I think the important part is that they make complexity requirements.

提交回复
热议问题