Why is it better to use '!=" than '<' in a vector loop? (C++)

后端 未结 7 1332
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 04:53

Why is it better to use \'!=\" than \'<\' in a vector loop? I just can\'t see the difference.

7条回答
  •  悲&欢浪女
    2021-01-02 05:34

    In general, I like to put code like this in a template function similar to the STL algorigthms, such that they are agnostic about what the underlying containter is.

    Since < only makes sense for vectors, it would be a poor fit for a generic function. If you use <, you are locking yourself into using a vector.

提交回复
热议问题