//
// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
//
// The contents of this file are covered under the licence agreement in the
// file "LICENCE" distributed with Cforall.
//
// assert.h --
//
// Author           : Peter A. Buhr
// Created On       : Thu Aug 18 13:19:26 2016
// Last Modified By : Andrew Beach
// Last Modified On : Mon Jun  3 13:11:00 2017
// Update Count     : 18
//

#pragma once
// Pragmas for header cleanup tool
// IWYU pragma: private, include <cassert>

#include_next <cassert>

#include <string>

template < typename ... Params >
std::string toString( const Params & ... params );

#ifdef NDEBUG

#define assertf(expr, fmt, ...) (__ASSERT_VOID_ASSERT (0))

#else

#define assertf(expr, fmt, ...) ((expr) \
	? (__ASSERT_VOID_CAST (0)) \
	: __assert_fail_f( #expr, __FILE__, __LINE__, \
	__ASSERT_FUNCTION, fmt, ## __VA_ARGS__ ))

void __assert_fail_f( 	const char *assertion, const char *file,
						unsigned int line, const char *function,
						const char *fmt, ...
	) __attribute__((noreturn, format(printf, 5, 6)));

#endif

template<typename T, typename U>
static inline T strict_dynamic_cast( const U & src ) {
	assert(src);
	T ret = dynamic_cast<T>(src);
	assertf(ret, "%s", toString(src).c_str());
	return ret;
}

template<typename T, decltype(nullptr) null, typename U>
static inline T strict_dynamic_cast( const U & src ) {
	return src ? strict_dynamic_cast<T, U>( src ) : nullptr;
}

extern void abort(const char *fmt, ...	) noexcept __attribute__((noreturn, format(printf, 1, 2)));
// Local Variables: //
// tab-width: 4 //
// mode: c++ //
// compile-command: "make install" //
// End: //
