// file : build/diagnostics -*- C++ -*- // copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file #ifndef BUILD_DIAGNOSTICS #define BUILD_DIAGNOSTICS #include #include #include #include #include namespace build { // Throw this exception to terminate the build. The handler should // assume that the diagnostics has already been issued. // class error: public std::exception {}; // Print process commmand line. // void print_process (const char* const* args); inline void print_process (const std::vector& args) { print_process (args.data ()); } // Call a function if there is an exception. // template struct exception_guard; template inline exception_guard> make_exception_guard (F f, A&&... a) { return exception_guard> ( std::move (f), std::forward_as_tuple (a...)); } template struct exception_guard> { typedef std::tuple T; exception_guard (F f, T a): f_ (std::move (f)), a_ (std::move (a)) {} ~exception_guard () { if (std::uncaught_exception ()) call (std::index_sequence_for ()); } private: template void call (std::index_sequence) {f_ (std::get (a_)...);} F f_; T a_; }; } #endif // BUILD_DIAGNOSTICS