| 1234567891011121314151617181920212223242526272829303132 |
- //
- // require.hpp
- // gameutils
- //
- // Created by Sam Jaffe on 8/19/16.
- //
- #pragma once
- #include <stdexcept>
- #include "macro.h"
- inline namespace precondition {
- template <typename except>
- void _expect(bool expr, char const * message) {
- if (!expr) throw except{message};
- }
- }
- #if defined( __clang__ ) || defined( __GNUC__ )
- # define LOCATION_INFO ". in " STRING(__PRETTY_FUNCTION__) "(" __FILE__ ":" STRING(__LINE__) ")"
- #elif defined( _MSC_VER )
- # define LOCATION_INFO ". in " __FUNCTION__ "(" __FILE__ ":" STRING(__LINE__) ")"
- #else
- # define LOCATION_INFO ". in " __FILE__ ":" STRING(__LINE__)
- #endif
- #define error_msg(expr, msg) msg ": " #expr LOCATION_INFO
- #define expects(expr, msg) expects_e(expr, std::logic_error, msg)
- #define expects_e(expr, except, msg) precondition::_expect<except>( expr, error_msg(expr, msg) )
|