diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2013-02-27 12:03:30 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-02-28 10:25:32 -0800 |
commit | 94b1d58cc28800cbc7f00febf499a1d9c9928a21 (patch) | |
tree | 8dc05506b3bc27df1178f21230519466613f8ea0 /common.h | |
parent | c55cbd3f2f003ea6e36727f8b985e880d6aded85 (diff) |
Additional changes related to https://github.com/fish-shell/fish-shell/pull/592
Diffstat (limited to 'common.h')
-rw-r--r-- | common.h | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -338,7 +338,7 @@ template <typename CharType_t> class null_terminated_array_t { CharType_t **array; - + /* No assignment or copying */ void operator=(null_terminated_array_t rhs); null_terminated_array_t(const null_terminated_array_t &); @@ -369,7 +369,7 @@ public: null_terminated_array_t(const string_list_t &argv) : array(make_null_terminated_array(argv)) { } - + ~null_terminated_array_t() { this->free(); @@ -385,7 +385,7 @@ public: { return array; } - + void clear() { this->free(); @@ -455,34 +455,32 @@ public: template <typename T> class scoped_push { - T &ref; + T * const ref; T saved_value; bool restored; public: - scoped_push(T &r): - ref(r), restored(false) + scoped_push(T *r): ref(r), saved_value(*r), restored(false) { - saved_value = ref; } - scoped_push(T &r, T new_value): - ref(r), restored(false) + scoped_push(T *r, const T &new_value) : ref(r), saved_value(*r), restored(false) { - saved_value = ref; - ref = new_value; + *r = new_value; } ~scoped_push() { - if (!restored) - restore(); + restore(); } void restore() { - ref = saved_value; - restored = true; + if (!restored) + { + std::swap(*ref, saved_value); + restored = true; + } } }; |