KASSERT  0.0.1
Karlsruhe Assertion Library
logger.hpp File Reference

Logger utility class to build error messages for failed assertins. More...

#include <ostream>
#include <sstream>
#include <type_traits>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

struct  kassert::internal::is_streamable_type_impl< typename, typename, typename >
 
struct  kassert::internal::is_streamable_type_impl< StreamT, ValueT, std::void_t< decltype(std::declval< StreamT & >()<< std::declval< ValueT >())> >
 
class  kassert::Logger< StreamT >
 Simple wrapper for output streams that is used to stringify values in assertions and exceptions. More...
 

Typedefs

using kassert::internal::OStreamLogger = Logger< std::ostream & >
 Logger writing all output to a std::ostream. This specialization is used to generate the KASSERT error messages.
 
using kassert::internal::RrefOStringstreamLogger = Logger< std::ostringstream && >
 Logger writing all output to a rvalue std::ostringstream. This specialization is used to generate the custom error message for THROWING_KASSERT exceptions.
 

Functions

template<typename StreamT , typename ValueT >
void kassert::internal::stringify_value (Logger< StreamT > &out, ValueT const &value)
 Stringify a value using the given assertion logger. If the value cannot be streamed into the logger, print <?> instead. More...
 
template<typename StreamT , typename ValueT , typename AllocatorT >
Logger< StreamT > & kassert::operator<< (Logger< StreamT > &logger, std::vector< ValueT, AllocatorT > const &container)
 Stringification of std::vector<T> in assertions. More...
 
template<typename StreamT , typename Key , typename Value >
Logger< StreamT > & kassert::operator<< (Logger< StreamT > &logger, std::pair< Key, Value > const &pair)
 Stringification of std::pair<K, V> in assertions. More...
 

Variables

template<typename StreamT , typename ValueT >
constexpr bool kassert::internal::is_streamable_type = is_streamable_type_impl<StreamT, ValueT>::value
 Determines whether a value of type ValueT can be streamed into an output stream of type StreamT. More...
 

Detailed Description

Logger utility class to build error messages for failed assertins.

Function Documentation

◆ operator<<() [1/2]

template<typename StreamT , typename Key , typename Value >
Logger< StreamT > & kassert::operator<< ( Logger< StreamT > &  logger,
std::pair< Key, Value > const &  pair 
)

Stringification of std::pair<K, V> in assertions.

Outputs a std::pair<K, V> in the following format, where first and second are the stringified components of the pair: (first, second).

Template Parameters
StreamTThe underlying output stream of the Logger.
KeyType of the first component of the pair.
ValueType of the second component of the pair.
Parameters
loggerThe assertion logger.
pairThe pair to be stringified.
Returns
The stringification of the pair as described above.

◆ operator<<() [2/2]

template<typename StreamT , typename ValueT , typename AllocatorT >
Logger< StreamT > & kassert::operator<< ( Logger< StreamT > &  logger,
std::vector< ValueT, AllocatorT > const &  container 
)

Stringification of std::vector<T> in assertions.

Outputs a std::vector<T> in the following format, where element i are the stringified elements of the vector: [element 1, element 2, ...]

Template Parameters
StreamTThe underlying output stream of the Logger.
ValueTThe type of the elements contained in the vector.
AllocatorTThe allocator of the vector.
Parameters
loggerThe assertion logger.
containerThe vector to be stringified.
Returns
The stringified vector as described above.