OpenTTD Source: FlatSet< Tkey, Tcompare > Class Template Reference

OpenTTD Source 15.0-RC2

Public Types | Public Member Functions | Private Attributes
FlatSet< Tkey, Tcompare > Class Template Reference

Flat set implementation that uses a sorted vector for storage. More...

`#include <flatset_type.hpp>`

## Public Types
using | const_iterator = std::vector< Tkey >::const_iterator

## Public Member Functions
std::pair< const_iterator, bool > | insert (const Tkey &key)
| Insert a key into the set, if it does not already exist.
size_t | erase (const Tkey &key)
| Erase a key from the set.
bool | contains (const Tkey &key) const
| Test if a key exists in the set.
const_iterator | begin () const
const_iterator | end () const
const_iterator | cbegin () const
const_iterator | cend () const
size_t | size () const
bool | empty () const
void | clear ()
auto | operator<=> (const FlatSet< Tkey, Tcompare > &) const =default

## Private Attributes
std::vector< Tkey > | data
| Sorted vector. of values.

## Detailed Description

template<class Tkey, class Tcompare = std::less<>>
class FlatSet< Tkey, Tcompare >

Flat set implementation that uses a sorted vector for storage.

This is subset of functionality implemented by std::flat_set in c++23.

Template Parameters

  Tkey | key type.
  Tcompare | key comparator.

Definition at line 20 of file flatset_type.hpp.

## Member Typedef Documentation

## ◆ const_iterator

template<class Tkey , class Tcompare = std::less<>>

using FlatSet< Tkey, Tcompare >::const_iterator = std::vector<Tkey>::const_iterator

Definition at line 23 of file flatset_type.hpp.

## Member Function Documentation

## ◆ begin()

template<class Tkey , class Tcompare = std::less<>>

const_iterator FlatSet< Tkey, Tcompare >::begin | ( |  | ) | const
| inline

Definition at line 62 of file flatset_type.hpp.

## ◆ cbegin()

template<class Tkey , class Tcompare = std::less<>>

const_iterator FlatSet< Tkey, Tcompare >::cbegin | ( |  | ) | const
| inline

Definition at line 65 of file flatset_type.hpp.

## ◆ cend()

template<class Tkey , class Tcompare = std::less<>>

const_iterator FlatSet< Tkey, Tcompare >::cend | ( |  | ) | const
| inline

Definition at line 66 of file flatset_type.hpp.

## ◆ clear()

template<class Tkey , class Tcompare = std::less<>>

void FlatSet< Tkey, Tcompare >::clear | ( |  | ) |
| inline

Definition at line 71 of file flatset_type.hpp.

## ◆ contains()

template<class Tkey , class Tcompare = std::less<>>

bool FlatSet< Tkey, Tcompare >::contains | ( | const Tkey & | key | ) | const
| inline

Test if a key exists in the set.

Parameters

  key | Key to test.

Returns
  true iff the key exists in the set.

Definition at line 57 of file flatset_type.hpp.

Referenced by GetRailTypeByLabel(), and GetRoadTypeByLabel().

## ◆ empty()

template<class Tkey , class Tcompare = std::less<>>

bool FlatSet< Tkey, Tcompare >::empty | ( |  | ) | const
| inline

Definition at line 69 of file flatset_type.hpp.

## ◆ end()

template<class Tkey , class Tcompare = std::less<>>

const_iterator FlatSet< Tkey, Tcompare >::end | ( |  | ) | const
| inline

Definition at line 63 of file flatset_type.hpp.

## ◆ erase()

template<class Tkey , class Tcompare = std::less<>>

size_t FlatSet< Tkey, Tcompare >::erase | ( | const Tkey & | key | ) |
| inline

Erase a key from the set.

Parameters

  key | Key to erase.

Returns
  number of elements removed.

Definition at line 43 of file flatset_type.hpp.

## ◆ insert()

template<class Tkey , class Tcompare = std::less<>>

std::pair< const_iterator, bool > FlatSet< Tkey, Tcompare >::insert | ( | const Tkey & | key | ) |
| inline

Insert a key into the set, if it does not already exist.

Parameters

  key | Key to insert.

Returns
  A pair consisting of an iterator to the inserted element (or to the element that prevented the insertion), and a bool value to true iff the insertion took place.

Definition at line 31 of file flatset_type.hpp.

Referenced by DrawBadgeNameList(), ForAllStationsAroundTiles(), ReplaceVehicleWindow::GenerateReplaceVehList(), GetProductionAroundTiles(), GfxBlitter(), and Station::RemoveFromAllNearbyLists().

## ◆ size()

template<class Tkey , class Tcompare = std::less<>>

size_t FlatSet< Tkey, Tcompare >::size | ( |  | ) | const
| inline

Definition at line 68 of file flatset_type.hpp.

## Field Documentation

## ◆ data

template<class Tkey , class Tcompare = std::less<>>

std::vector<Tkey> FlatSet< Tkey, Tcompare >::data
| private

Sorted vector. of values.

Definition at line 21 of file flatset_type.hpp.

The documentation for this class was generated from the following file:

- src/core/flatset_type.hpp