Prefer member functions to algorithms with the same names
2006-01-11 15:56
302 查看
有些容器拥有和STL算法同名的成员函数。关联容器提供了count、find、lower_bound、upper_bound和equal_range,而list提供了remove、remove_if、unique、sort、merge和reverse。大多数情况下,你应该用成员函数代替算法。这样做有两个理由。首先,成员函数更快。其次,比起算法来,它们与容器结合得更好(尤其是关联容器)。那是因为同名的算法和成员函数通常并不是是一样的。
Some containers have member functions with the same names as STL algorithms. The associative containers offer count, find, lower_bound. upper_bound, and equal_range, while list offers remove, remove_if, unique, sort, merge, and reverse. Most of the time, you'll want to use the member functions instead of the algorithms. There are two reasons for this. First, the member functions are faster. Second, they integrate better with the containers (especially the associative containers) than do the algorithms. That's because algorithms and member functions that share the same name typically do not do exactly the same thing.
Some containers have member functions which have the same name with STL algorithms. Associated containers provide count, find, lower_bound. upper_bound, and equal_range, while list provides remove, remove_if, unique, sort, merge, and reverse. In most cases, you should use member functions instead of algorithms. There are two reasons for doing this. For one thing, member functions are faster. For another, comparing to algorithms, they are better-combined with contianers(especially associated containers). Algorithms and member functions with the same name are usually not the same.
Some containers have member functions with the same names as STL algorithms. The associative containers offer count, find, lower_bound. upper_bound, and equal_range, while list offers remove, remove_if, unique, sort, merge, and reverse. Most of the time, you'll want to use the member functions instead of the algorithms. There are two reasons for this. First, the member functions are faster. Second, they integrate better with the containers (especially the associative containers) than do the algorithms. That's because algorithms and member functions that share the same name typically do not do exactly the same thing.
Some containers have member functions which have the same name with STL algorithms. Associated containers provide count, find, lower_bound. upper_bound, and equal_range, while list provides remove, remove_if, unique, sort, merge, and reverse. In most cases, you should use member functions instead of algorithms. There are two reasons for doing this. For one thing, member functions are faster. For another, comparing to algorithms, they are better-combined with contianers(especially associated containers). Algorithms and member functions with the same name are usually not the same.
相关文章推荐
- the same as,the same to,the same with的用法区别
- A slave with the same server_uuid as this slave has connected to the master
- Ch8.6: write a method to paint-fill a closed ring with the same color
- Error: member names cannot be the same as their enclosing type
- Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket
- Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket
- Two output file names resolved to the same output path
- wo or more files with the name of logging.cc will produce outputs to the same location.
- CXF报错[1 counts of IllegalAnnotationExceptions]and[Two classes have the same XML type name]and[Use @XmlType.name and @XmlType.namespace to assign different names to them]
- How to Backup Different Release Databases with the Same Catalog Database
- 69.You need to generate a list of all customer last names with their credit limits from the CUSTOMER
- 70.You want to display only those product names with their list prices where the list price is at le
- An attempt was made to load a program with an incorrect format” even when the platforms are the same
- java.lang.IllegalArgumentException: Registered more than one instance with the same objectName
- How to limit an array of similar hashes to those that have more than one of the same key:value pair
- Reference to Different Versions of the Same Assembly
- The reference to entity "characterEncoding" must end with the ';' delimiter.
- The model used to open the store is incompatible with the one used to create the store
- The installer cannot read the mwinstall.dll file, This is probably due to a CD reader which can only read files with an eight.th
- a different object with the same identifier value was already associated with the session