OpenTTD Source: src/core/container_func.hpp File Reference

OpenTTD Source 14.1

Functions
container_func.hpp File Reference

Go to the source code of this file.

## Functions
template<typename Container >
bool | include (Container &container, typename Container::const_reference &item)
| Helper function to append an item to a container if it is not already contained. More...
template<typename Container >
int | find_index (Container const &container, typename Container::const_reference item)
| Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_set in new code. More...

## Detailed Description

Some simple functions to help with accessing containers.

Definition in file container_func.hpp.

## Function Documentation

## ◆ find_index()

template<typename Container >

int find_index | ( | Container const & | container,
|  | typename Container::const_reference | item
| ) |  |

Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_set in new code.

Parameters

  container | A reference to the container to be searched.
  item | Reference to the item to be search for

Returns
  Index of element if found, otherwise -1

Definition at line 41 of file container_func.hpp.

Referenced by NetworkContentListWindow::FilterContentList(), GetReverseRailTypeTranslation(), VehicleGroupWindow::SelectGroup(), and NetworkContentListWindow::SortContentList().

## ◆ include()

template<typename Container >

bool include | ( | Container & | container,
|  | typename Container::const_reference & | item
| ) |  |
| inline

Helper function to append an item to a container if it is not already contained.

The container must have a `emplace_back` function. Consider using std::set, std::unordered_set or std::flat_set in new code.

Parameters

  container | A reference to the container to be extended
  item | Reference to the item to be copy-constructed if not found

Returns
  Whether the item was already present

Definition at line 24 of file container_func.hpp.

Referenced by AddAnimatedTile(), ClientNetworkContentSocketHandler::AddCallback(), ScenarioScanner::AddFile(), RefitWindow::BuildRefitList(), CheckSubsidised(), DeliverGoodsToIndustry(), GetBestFittingSubType(), GetVehicleSet(), ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(), UpdateRoadVehPowerProc(), and UpdateTrainPowerProc().