Evo primitive and basic container types.
- Primitives
Evo has class variations of basic primitives with some added features:
- Nullable: Can have an explicit null value
- Defaulting: Value defaults to 0 by constructor
- Type traits like min/max value
- Various helper methods
- Smart pointers make sure memory is always freed
All Evo primitives implement these methods:
bool null() const
bool valid() const
This& set()
Primitives:
- CharT
- IntegerT
- Short, Int, Long, LongL / UShort, UInt, ULong, ULongL
- Int8, Int16, Int32, Int64 / UInt8, UInt16, UInt32, UInt64
- FloatT
- SmartPtr, SharedPtr, Ptr
- Pair
Related:
- Containers
Evo containers:
- Nullable: Can have an explicit null value
- Hashable: Have a
hash()
method for hashing items as a group
- Containers have iterator subtypes:
- Iter for read-only (const) access
- IterM for read and write (mutable) access (optional)
- See below for more on iterators
- Optimizations for handling different types efficiently – see Plain Old Data & Copying
- May support Sharing and/or Slicing
- New empty containers do not allocate memory until necessary
- Advanced methods with "adv" prefix for more intrusive use
All Evo containers implement these methods:
const This& asconst() const
bool null() const
bool empty() const
Size size() const
bool shared() const
This& set()
This& clear()
This& unshare()
ulong hash(ulong seed=0) const
Evo containers support C++11 features:
- Range-based for loops
- Initializer lists
- Move semantics and
std::move()
Types:
Related:
Notes for item classes used with containers:
- Exception Safety
- Item destructor must never throw an exception
- Item default constructor and copy constructor must never throw an exception
- Item assignment operator for copying item must never throw an exception
- Relocatable Objects
- Evo containers may relocate (move) items to a different location in memory (as an internal optimization)
- Items must be relocatable, i.e. must not have any member variables pointing to or referencing a member variable in the same instance (a hacky thing to do anyway)
- Comparisons
- Item must implement operator==() for equality checking
- Item should implement compare() for ordered comparisons
- All POD types are supported by Evo containers
- Caution: If item type violates these requirements then results are undefined (i.e. memory leak/crash under edge cases/weird bugs) if used with Evo containers
- Iterators
Evo iterators work similar to pointers.
- Increment or decrement iterator to move to next or previous item
- Dereference iterator to get value
The general iterator types aren't normally used directly. A container will have subtypes defining concrete iterator types to use – see List::Iter and List::IterM for example.
Iterator types:
- IteratorFw: Forward iterator
- IteratorBi: Bidirectional (forward and reverse) iterator
- IteratorRa: Random access (forward, reverse, and random access) iterator
- Comparison
Containers with ordering or sorting do comparisons with a comparison type that implements CompareBase. Comparison types:
- are specified via template param, and the compiler can optimize out (inline) the comparison calls
- implement
operator()()
to compare 2 items (a
& b
) and return an int: 0 if a == b
, positive if a > b
, negative if a < b
- define a
PassItem
type (inheriting CompareBase) used for passing items to compare
- can hold state for advanced use, such as tracking stats
- interface:
int operator()(PassItem a, PassItem b) const
Standard comparison types:
- Hashing
Containers using hash tables use a single combined type for hashing and comparisons because values that compare as equal must also hash to the same bucket, otherwise collisions won't be handled correctly. Hashing types:
- are specified via template param, and the compiler can optimize out (inline) the hash/comparison calls
- implement
operator()()
to compare 2 items (a
& b
) in case of collisions and return an int: 0 if a == b
, positive if a > b
, negative if a < b
- implement
hash()
method to compute a hash value for a key, with a seed for chaining a previous hash method
- define a
PassItem
type (inheriting CompareBase) used for passing items to hash/compare
- can hold state for advanced use, such as tracking stats
- interface:
int operator()(PassItem a, PassItem b) const
ulong hash(PassItem key, ulong seed=0) const
Standard hashing types: