feat(command): adding a search list with template
This commit is contained in:
parent
4598e0f3c1
commit
ca7ca692d4
1 changed files with 30 additions and 0 deletions
30
include/commands/commands.tpp
Normal file
30
include/commands/commands.tpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* commands.tpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/24 17:34:30 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/05/24 18:23:26 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the element searched in a list
|
||||||
|
*
|
||||||
|
* @tparam T Type of the list have to be search (have to get an getName() method)
|
||||||
|
* @param list list to search in
|
||||||
|
* @param name name of the element to search
|
||||||
|
* @return pointer to the element found or nullptr if not found
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T cmd::searchList(const std::list<T> &list, const std::string &name) {
|
||||||
|
for (typename std::list<T>::iterator it = list.begin(); it != list.end(); ++it) {
|
||||||
|
if ((*it)->getName() == name)
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue