git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Simplify 'unbox' functions (runtime)
7aa15fbAndy Arvanitis
runtime/purescript.h+7−9
@@ -135,24 +135,22 @@ namespace purescript {
135 return *static_cast<const T*>(b.get());
135 return *static_cast<const T*>(b.get());
136 }
136 }
137
137
138− template <typename T,
138+ template <typename T>
139− typename = typename std::enable_if<!std::is_same<T, const boxed&>::value>::type>
139+ constexpr auto unbox(boxed& b) -> T& {
140+ return *static_cast<T*>(b.get());
141+ }
142+
143+ template <typename T>
140 constexpr auto unbox(const T value) -> T {
144 constexpr auto unbox(const T value) -> T {
141 return value;
145 return value;
142 }
146 }
143
147
144 template <typename T,
148 template <typename T,
145− typename = typename std::enable_if<!std::is_same<T, const boxed&>::value &&
146− std::is_same<T, int>::value>::type>
149+ typename = typename std::enable_if<std::is_same<T, int>::value>::type>
147 constexpr auto unbox(const std::size_t value) -> long long {
150 constexpr auto unbox(const std::size_t value) -> long long {
148 return value;
151 return value;
149 }
152 }
150
153
151− template <typename T>
152− constexpr auto peek(boxed& b) -> T& {
153− return *static_cast<T*>(b.get());
154− }
155−
156 inline auto array_length(const boxed& a) -> boxed::array_t::size_type {
154 inline auto array_length(const boxed& a) -> boxed::array_t::size_type {
157 return unbox<boxed::array_t>(a).size();
155 return unbox<boxed::array_t>(a).size();
158 }
156 }