diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-16 19:03:08 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-16 19:03:08 +0200 |
commit | aded6de920f420b5c36fee1081c795cf8c6c6dc9 (patch) | |
tree | ea62cba64fdd01cb8ae0a67611038e9522d6fa4d /build/utility | |
parent | e62aef8ebe4b4b7eb733da6822d7759c0427222b (diff) |
Rely on as few C++14 features as possible
Diffstat (limited to 'build/utility')
-rw-r--r-- | build/utility | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/build/utility b/build/utility index 6769f95..bcb6b58 100644 --- a/build/utility +++ b/build/utility @@ -5,11 +5,9 @@ #ifndef BUILD_UTILITY #define BUILD_UTILITY -#include <tuple> -#include <string> #include <utility> // move(), make_pair() #include <cassert> // assert() -#include <exception> +#include <exception> // uncaught_exception() #include <unordered_set> #include <build/types> @@ -44,40 +42,32 @@ namespace build // extern bool exception_unwinding_dtor; - template <typename F, typename T> + template <typename F> struct exception_guard; - template <typename F, typename... A> - inline exception_guard<F, std::tuple<A&&...>> - make_exception_guard (F f, A&&... a) + template <typename F> + inline exception_guard<F> + make_exception_guard (F f) { - return exception_guard<F, std::tuple<A&&...>> ( - std::move (f), std::forward_as_tuple (a...)); + return exception_guard<F> (move (f)); } - template <typename F, typename... A> - struct exception_guard<F, std::tuple<A...>> + template <typename F> + struct exception_guard { - typedef std::tuple<A...> T; - - exception_guard (F f, T a): f_ (std::move (f)), a_ (std::move (a)) {} + exception_guard (F f): f_ (move (f)) {} ~exception_guard () { if (std::uncaught_exception ()) { exception_unwinding_dtor = true; - call (std::index_sequence_for<A...> ()); + f_ (); exception_unwinding_dtor = false; } } private: - template <std::size_t... I> - void - call (std::index_sequence<I...>) {f_ (std::get<I> (a_)...);} - F f_; - T a_; }; // Pools (@@ perhaps move into a separate header). |