openMSX
Classes | Typedefs | Functions
stl.hh File Reference
#include <algorithm>
#include <tuple>
#include <utility>
#include <cassert>
Include dependency graph for stl.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LessDeref
 
struct  EqualTo
 
struct  LessThan
 
struct  CmpTupleElement< N, CMP >
 
struct  EqualTupleValueImpl< N, T >
 

Typedefs

template<int N>
using LessTupleElement = CmpTupleElement< N, LessThan >
 

Functions

template<int N, typename T >
EqualTupleValueImpl< N, T > EqualTupleValue (const T &t)
 
template<typename ITER , typename VAL >
bool contains (ITER first, ITER last, const VAL &val)
 Check if a range contains a given value, using linear search. More...
 
template<typename RANGE , typename VAL >
bool contains (const RANGE &range, const VAL &val)
 
template<typename ITER , typename VAL >
ITER find_unguarded (ITER first, ITER last, const VAL &val)
 Faster alternative to 'find' when it's guaranteed that the value will be found (if not the behavior is undefined). More...
 
template<typename RANGE , typename VAL >
auto find_unguarded (RANGE &range, const VAL &val) -> decltype(std::begin(range))
 
template<typename ITER , typename PRED >
ITER find_if_unguarded (ITER first, ITER last, PRED pred)
 Faster alternative to 'find_if' when it's guaranteed that the predicate will be true for at least one element in the given range. More...
 
template<typename RANGE , typename PRED >
auto find_if_unguarded (RANGE &range, PRED pred) -> decltype(std::begin(range))
 
template<typename RANGE , typename VAL >
auto rfind_unguarded (RANGE &range, const VAL &val) -> decltype(std::begin(range))
 Similar to the find(_if)_unguarded functions above, but searches from the back to front. More...
 
template<typename RANGE , typename PRED >
auto rfind_if_unguarded (RANGE &range, PRED pred) -> decltype(std::begin(range))
 
template<typename VECTOR >
void move_pop_back (VECTOR &v, typename VECTOR::iterator it)
 Erase the pointed to element from the given vector. More...
 
template<typename ForwardIt , typename OutputIt , typename UnaryPredicate >
std::pair< OutputIt, ForwardIt > partition_copy_remove (ForwardIt first, ForwardIt last, OutputIt out_true, UnaryPredicate p)
 This is like a combination of partition_copy() and remove(). More...
 

Typedef Documentation

◆ LessTupleElement

template<int N>
using LessTupleElement = CmpTupleElement<N, LessThan>

Definition at line 75 of file stl.hh.

Function Documentation

◆ contains() [1/2]

template<typename ITER , typename VAL >
bool contains ( ITER  first,
ITER  last,
const VAL &  val 
)
inline

Check if a range contains a given value, using linear search.

Equivalent to 'find(first, last, val) != last', though this algorithm is more convenient to use. Note: we don't need a variant that uses 'find_if' instead of 'find' because STL already has the 'any_of' algorithm.

Definition at line 102 of file stl.hh.

Referenced by openmsx::MSXMultiIODevice::addDevice(), openmsx::Display::attach(), contains(), openmsx::FileContext::isUserContext(), openmsx::Mixer::registerMixer(), openmsx::VideoSourceSetting::unregisterVideoSource(), openmsx::DirAsDSK::writeSectorImpl(), openmsx::MSXEventDistributor::~MSXEventDistributor(), and openmsx::StateChangeDistributor::~StateChangeDistributor().

◆ contains() [2/2]

template<typename RANGE , typename VAL >
bool contains ( const RANGE &  range,
const VAL &  val 
)
inline

Definition at line 107 of file stl.hh.

References begin(), contains(), and end().

◆ EqualTupleValue()

template<int N, typename T >
EqualTupleValueImpl<N, T> EqualTupleValue ( const T &  t)

Definition at line 90 of file stl.hh.

◆ find_if_unguarded() [1/2]

template<typename ITER , typename PRED >
ITER find_if_unguarded ( ITER  first,
ITER  last,
PRED  pred 
)
inline

Faster alternative to 'find_if' when it's guaranteed that the predicate will be true for at least one element in the given range.

See also 'find_unguarded'.

Definition at line 142 of file stl.hh.

Referenced by find_if_unguarded(), openmsx::GLPostProcessor::paint(), openmsx::MSXCPUInterface::removeBreakPoint(), openmsx::Reactor::replaceBoard(), rfind_if_unguarded(), openmsx::MSXMixer::setRecorder(), openmsx::VideoSourceSetting::setSource(), and openmsx::MSXMixer::updateSoftwareVolume().

◆ find_if_unguarded() [2/2]

template<typename RANGE , typename PRED >
auto find_if_unguarded ( RANGE &  range,
PRED  pred 
) -> decltype(std::begin(range))
inline

Definition at line 152 of file stl.hh.

References begin(), end(), and find_if_unguarded().

◆ find_unguarded() [1/2]

template<typename ITER , typename VAL >
ITER find_unguarded ( ITER  first,
ITER  last,
const VAL &  val 
)
inline

Faster alternative to 'find' when it's guaranteed that the value will be found (if not the behavior is undefined).

When asserts are enabled we check whether we really don't move beyond the end of the range. And this check is the only reason why you need to pass the 'last' parameter. Sometimes you see 'find_unguarded' without a 'last' parameter, we could consider providing such an overload as well.

Definition at line 121 of file stl.hh.

Referenced by find_unguarded(), and rfind_unguarded().

◆ find_unguarded() [2/2]

template<typename RANGE , typename VAL >
auto find_unguarded ( RANGE &  range,
const VAL &  val 
) -> decltype(std::begin(range))
inline

Definition at line 131 of file stl.hh.

References begin(), end(), and find_unguarded().

◆ move_pop_back()

template<typename VECTOR >
void move_pop_back ( VECTOR &  v,
typename VECTOR::iterator  it 
)

◆ partition_copy_remove()

template<typename ForwardIt , typename OutputIt , typename UnaryPredicate >
std::pair<OutputIt, ForwardIt> partition_copy_remove ( ForwardIt  first,
ForwardIt  last,
OutputIt  out_true,
UnaryPredicate  p 
)

This is like a combination of partition_copy() and remove().

Each element is tested against the predicate. If it matches, the element is copied to the output and removed from the input. So the output contains all elements for which the predicate gives true and the input is modified in-place to contain the elements for which the predicate gives false. (Like the remove() algorithm, it's still required to call erase() to also shrink the input).

This algorithm returns a pair of iterators. -first: one past the matching elements (in the output range). Similar to the return value of the partition_copy() algorithm. -second: one past the non-matching elements (in the input range). Similar to the return value of the remove() algorithm.

Definition at line 227 of file stl.hh.

Referenced by openmsx::AfterCommand::tabCompletion().

◆ rfind_if_unguarded()

template<typename RANGE , typename PRED >
auto rfind_if_unguarded ( RANGE &  range,
PRED  pred 
) -> decltype(std::begin(range))
inline

◆ rfind_unguarded()

template<typename RANGE , typename VAL >
auto rfind_unguarded ( RANGE &  range,
const VAL &  val 
) -> decltype(std::begin(range))
inline