Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively included in almost every translation unit.
- Warning
- be sure to understand the ramifications of including anything here...
- See also
- util-coll.hpp
-
util-quant.hpp
-
util-foreach.hpp
Definition in file util.hpp.
|
| template<typename IT , typename V > |
| constexpr IT | find (IT, IT, V const &) |
| |
| template<typename IT , typename V > |
| constexpr IT | remove (IT, IT, V const &) |
| |
| CStr | cStr (std::string const &) |
| | convenience shortcut: forced conversion to c-String via string.
|
| |
| template<class NUM > |
| constexpr int | sgn (NUM n) |
| |
| template<class N1 , class N2 > |
| constexpr N1 | min (N1 n1, N2 n2) |
| |
| template<class N1 , class N2 > |
| constexpr N1 | max (N1 n1, N2 n2) |
| |
| template<typename NUM > |
| constexpr NUM | noneg (NUM val) |
| | cut a numeric value to be >=0
|
| |
| template<typename NUM , typename NB > |
| constexpr NUM | limited (NB lowerBound, NUM val, NB upperBound) |
| | force a numeric to be within bounds, inclusively
|
| |
| template<typename NUM , typename NB > |
| constexpr bool | isLimited (NB lowerBound, NUM val, NB upperBound) |
| |
| template<typename UN , typename N2 > |
| constexpr UN | positiveDiff (N2 newVal, UN refVal) |
| |
| uint | uNum (CStr charPtr) |
| | positive integral number from textual representation
|
| |
| int | sNum (CStr charPtr) |
| |
| template<class OBJ > |
| uint | uNum (OBJ const &spec) |
| |
| template<class OBJ > |
| int | sNum (OBJ const &spec) |
| |
| template<class CONT > |
| bool | isnil (const CONT &container) |
| | a family of util functions providing a "no value whatsoever" test.
|
| |
| template<class CONT > |
| bool | isnil (const CONT *pContainer) |
| |
| template<class CONT > |
| bool | isnil (CONT *pContainer) |
| |
| bool | isnil (CStr charPtr) |
| |
| bool | startsWith (string const &str, string const &prefix) |
| | check if string starts with a given prefix
|
| |
| bool | startsWith (string const &str, CStr prefix) |
| |
| bool | endsWith (string const &str, string const &suffix) |
| | check if string ends with the given suffix
|
| |
| bool | endsWith (string const &str, CStr suffix) |
| |
| void | removePrefix (string &str, string const &prefix) |
| |
| void | removeSuffix (string &str, string const &suffix) |
| |
| template<typename MAP > |
| bool | contains (MAP &map, typename MAP::key_type const &key) |
| | shortcut for containment test on a map
|
| |
| template<typename T , class CMP , class ALO > |
| bool | contains (std::set< T, CMP, ALO > const &set, T const &val) |
| | shortcut for set value containment test
|
| |
| template<typename T > |
| bool | contains (std::string const &str, const T &val) |
| | shortcut for string value containment test
|
| |
| template<typename SEQ > |
| bool | contains (SEQ const &cont, typename SEQ::const_reference val) |
| | shortcut for brute-force containment test in any sequential container
|
| |
| template<class IT > |
| bool | linearSearch (IT iter, typename IT::value_type const &val) |
| | use (and exhaust) a »Lumiera Forward Iterator« for linear search
|
| |
| template<typename MAP > |
| MAP::mapped_type | getValue_or_default (MAP &map, typename MAP::key_type const &key, typename MAP::mapped_type defaultVal) |
| | fetch value from a Map, or return a default if not found
|
| |
| template<typename MAP > |
| MAP::mapped_type const & | access_or_default (MAP &map, typename MAP::key_type const &key, typename MAP::mapped_type const &refDefault) |
| | expose a reference to a map entry, with fall-back to some default object
|
| |
| template<typename SEQ > |
| SEQ::iterator | removeall (SEQ &coll, typename SEQ::value_type const &val) |
| | shortcut for removing all copies of an Element in any sequential collection
|
| |
| template<class SET , typename FUN > |
| bool | remove_if (SET &set, FUN test) |
| | remove all elements fulfilling a given predicate from a (sorted) set.
|
| |
| template<class OBJ > |
| OBJ * | unConst (const OBJ *o) |
| | shortcut to save some typing when having to define const and non-const variants of member functions
|
| |
| template<class OBJ > |
| OBJ & | unConst (OBJ const &) |
| |
| template<class X > |
| const void * | getAdr (X &x) |
| | extract address but strip any type info
|
| |
| template<class X > |
| const void * | getAdr (X *x) |
| |
| template<class X > |
| size_t | addrID (X const &x) |
| | generate an unique numeric ID based on the referred entity
|
| |
| template<typename X > |
| size_t | slotNr (X const &x) |
| | the addressable memory »slot« — platform dependent.
|
| |
| template<class A , class B > |
| bool | isSameAdr (A const &a, B const &b) |
| | compare plain object address identity, disregarding type.
|
| |
| template<class A , class B > |
| bool | isSameObject (A const &a, B const &b) |
| | compare plain object identity, based directly on the referee's memory identities.
|
| |
| template<typename A , typename B > |
| bool | isCloseBy (A &&a, B &&b, size_t consideredNearby=50) |
| | determine heuristically if two objects are located „close to each other“ in memory.
|
| |
| std::string | sanitise (string const &org) |
| | produce an identifier based on the given string.
|
| |
| string | trim (string const &org) |
| | remove leading and trailing whitespace
|
| |
| bool | boolVal (string const &) |
| | interpret text representation of a boolean value.
|
| |
| bool | isYes (string const &) noexcept |
| | check the given text if it can be interpreted as affirmative answer (bool true).
|
| |
| bool | isNo (string const &) noexcept |
| | check if the given text is empty or can be interpreted as rejection (bool false)-
|
| |