SPH
Classes | Functions | Variables
Expected.h File Reference

Wrapper of type containing either a value or an error message. More...

#include "objects/wrappers/Variant.h"

Go to the source code of this file.

Classes

struct  UnexpectedTag
 
class  Expected< Type, Error >
 Wrapper of type that either contains a value of given type, or an error message. More...
 

Functions

template<typename T , typename = decltype(std::declval<std::ostream&>() << std::declval<T>())>
std::ostream & operator<< (std::ostream &stream, const Expected< T > &expected)
 Prints the expected value into a stream. More...
 
template<typename Type >
Expected< Type > makeUnexpected (const std::string &error)
 Constructs an unexpected value of given type, given error message as std::string. More...
 

Variables

const UnexpectedTag UNEXPECTED
 

Detailed Description

Wrapper of type containing either a value or an error message.

Author
Pavel Sevecek (sevecek at sirrah.troja.mff.cuni.cz)
Date
2016-2021

Definition in file Expected.h.

Function Documentation

◆ makeUnexpected()

template<typename Type >
Expected<Type> makeUnexpected ( const std::string &  error)

Constructs an unexpected value of given type, given error message as std::string.

For other type of error messages, use constructor of Expected.

Definition at line 138 of file Expected.h.

◆ operator<<()

template<typename T , typename = decltype(std::declval<std::ostream&>() << std::declval<T>())>
std::ostream& operator<< ( std::ostream &  stream,
const Expected< T > &  expected 
)
inline

Prints the expected value into a stream.

If the object contains an expected value, prints the value into the stream, otherwise print the error message. Enabled only if the wrapped type defines the operator<<, to that it corretly works with Catch framework.

Definition at line 125 of file Expected.h.

Variable Documentation

◆ UNEXPECTED

const UnexpectedTag UNEXPECTED

Definition at line 14 of file Expected.h.