KSS Utility
C++ general utilities
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
kss::util Namespace Reference

General utility methods that don't fit into any of the other categories. More...

Namespaces

 containers
 Containers and items related to containers.
 
 iterators
 Classes used to help build custom iterators.
 
 memory
 Items related to dealing with memory, in particular the destruction of objects.
 
 po
 Program options (i.e. command line arguments)
 
 process
 Items related to processes.
 
 rtti
 Run time type information, such as name demangling and type identification.
 
 strings
 Items related to string handling.
 
 time
 Items related to parsing, formatting, and manipulating time_point and duration objects.
 

Classes

struct  AddRelOps
 Add the operators !=, <=, > and >= assuming the existance of == and <. More...
 
class  Attributes
 Adds an attribures API to subclasses. More...
 
class  RAII
 Implementation of the RAII pattern. More...
 
class  Finally
 Implementation of a "finally" block. More...
 
class  UUID
 C++ wrapper around the uuid_t type. More...
 

Functions

template<class InputIterator , class Operator , class Predicate >
Operator forEachIf (InputIterator first, InputIterator last, Operator f, Predicate p)
 
template<class InputIterator , class InputIterator2 , class BinaryPredicate >
bool notEqual (InputIterator first, InputIterator last, InputIterator2 first2, BinaryPredicate bp)
 
template<class InputIterator , class InputIterator2 >
bool notEqual (InputIterator first, InputIterator last, InputIterator2 first2)
 
bool tryAll (const std::function< void()> &fn) noexcept
 
template<class T >
std::pair< T, bool > tryAll (const std::function< T()> &fn) noexcept
 
std::string errorDescription (const std::exception &e)
 
std::string version () noexcept
 
std::string license () noexcept
 

Detailed Description

General utility methods that don't fit into any of the other categories.

Function Documentation

std::string kss::util::errorDescription ( const std::exception &  e)

Returns a description of an exception that includes the name of the exception and the value returned by its what() method, e.g. "std::runtime_error: this is a test".

In the "special case" of a system_error using the system_category(), the description will also include the value of the error number, e.g. "std::system_error: (12) Cannot allocate memory".

Exceptions
std::bad_allocif the memory could not be allocated
template<class InputIterator , class Operator , class Predicate >
Operator kss::util::forEachIf ( InputIterator  first,
InputIterator  last,
Operator  f,
Predicate  p 
)

Apply an operator, filtered by a predicate, to each item. This method is similar to std::for_each() but adds the ability to specify a predicate as well as an operation. Specifically the operator f is applied to all items for which the predicate p(item) returns true.

Exceptions
anyexception that Operator or Predicate may throw.
Returns
f.

Definition at line 37 of file algorithm.hpp.

std::string kss::util::license ( )
noexcept

Returns the text of the software license.

template<class InputIterator , class InputIterator2 , class BinaryPredicate >
bool kss::util::notEqual ( InputIterator  first,
InputIterator  last,
InputIterator2  first2,
BinaryPredicate  bp 
)

Determine if two sequences of elements differ. Similar to not_equal(first, last, first2) except that the binary predicate bp is used for comparison instead of std::equal_to.

Exceptions
anyexceptions that bp may throw.
Returns
true if at least one inequality is found.

Definition at line 53 of file algorithm.hpp.

template<class InputIterator , class InputIterator2 >
bool kss::util::notEqual ( InputIterator  first,
InputIterator  last,
InputIterator2  first2 
)
inline

Determine if two sequences of elements differ. Compares two sets of iterators and returns true if at least one element differs. Note that ++first2 must be valid for at least as many calls as ++first. Also note that while InputIterator and InputIterator2 may be different types, they must dereference to compatible types.

Exceptions
anyexceptions that the std::equal_to method may throw
Returns
true if at least one inequality is found.

Definition at line 73 of file algorithm.hpp.

bool kss::util::tryAll ( const std::function< void()> &  fn)
noexcept

tryAll is used to convert exceptions into more of a "C"-style error handling. This is useful if you don't care what the error was and just want to know if it worked.

The non-template version will return true if everything works (i.e. if there is no exception thrown), and false if an exception is thrown.

Also note that this will only catch exceptions subclassed from std::exception. Any other exceptions will call std::terminate().

The template version will return a pair<T, bool>. If no exception is thrown, then T will be the value returned by the functional and bool will be true. If an exception is thrown, then T will be the value of an empty T() and the bool will be false.

Note the following limitation: In order to ensure a level of efficiency, the template version will only compile if T supports std::move.

Parameters
fnThe code block (or function) that is to be run.
template<class T >
std::pair<T, bool> kss::util::tryAll ( const std::function< T()> &  fn)
noexcept

Definition at line 51 of file error.hpp.

std::string kss::util::version ( )
noexcept

Returns a string of the form x.y.z<optional tags> that describes the version of this library.