@@ -65,27 +65,26 @@ const size_t constructor = 0;
65class any {
65class any {
68− enum class Type : int8_t {
68+ enum Type {
69− Unknown,
69+ Thunk = 0x00,
70− Integer,
70+ Integer = 0x01,
71− Double,
71+ Double = 0x02,
72− Character,
72+ Character = 0x03,
73− Boolean,
73+ Boolean = 0x04,
74− StringLiteral,
74+ StringLiteral = 0x05,
75− String,
77+ String = 0x08,
77− Data,
79+ Data = 0x0A,
78− Array,
80+ Array = 0x0B,
80− Closure,
81+ Closure = 0x0C,
81− EffFunction,
82+ EffFunction = 0x0D,
83− Pointer
83+ Pointer = 0x0E
87 mutable Type type;
87 mutable Type type;
88− mutable bool is_shared;
91 struct as_thunk {
90 struct as_thunk {
@@ -141,83 +140,83 @@ class any {
144 mutable long i;
144 mutable long i;
145 mutable double d;
145 mutable double d;
146 mutable char c;
146 mutable char c;
147 mutable bool b;
147 mutable bool b;
148 mutable string r;
148 mutable string r;
149 mutable shared<std::string> s;
150 mutable shared<std::string> s;
150 mutable shared<map> m;
151 mutable shared<map> m;
151 mutable shared<data> v;
152 mutable shared<data> v;
152 mutable shared<array> a;
153 mutable shared<array> a;
154 mutable shared<closure> l;
154 mutable shared<closure> l;
155 mutable shared<eff_fn> e;
155 mutable shared<eff_fn> e;
157 mutable shared<void> p;
156 mutable shared<void> p;
162− any(const long val) : type(Type::Integer), is_shared(false), i(val) {}
161+ any(const long val) : type(Type::Integer), i(val) {}
163− any(const int val) : type(Type::Integer), is_shared(false), i(val) {}
162+ any(const int val) : type(Type::Integer), i(val) {}
164− any(const unsigned int val) : type(Type::Integer), is_shared(false), i(val) {}
163+ any(const unsigned int val) : type(Type::Integer), i(val) {}
165− any(const double val) : type(Type::Double), is_shared(false), d(val) {}
164+ any(const double val) : type(Type::Double), d(val) {}
166− any(const char val) : type(Type::Character), is_shared(false), c(val) {}
165+ any(const char val) : type(Type::Character), c(val) {}
168 template <typename T, typename = typename std::enable_if<std::is_same<bool,T>::value>::type>
167 template <typename T, typename = typename std::enable_if<std::is_same<bool,T>::value>::type>
169− any(const T val) : type(Type::Boolean), is_shared(false), b(val) {}
168+ any(const T val) : type(Type::Boolean), b(val) {}
171 template <size_t N>
170 template <size_t N>
172− any(const char (&val)[N]) : type(Type::StringLiteral), is_shared(false), r(val) {}
171+ any(const char (&val)[N]) : type(Type::StringLiteral), r(val) {}
173− any(char * val) : type(Type::String), is_shared(true), s(make_shared<std::string>(val)) {}
172+ any(char * val) : type(Type::String), s(make_shared<std::string>(val)) {}
175− any(const std::string& val) : type(Type::String), is_shared(true), s(make_shared<std::string>(val)) {}
174+ any(const std::string& val) : type(Type::String), s(make_shared<std::string>(val)) {}
176− any(std::string&& val) : type(Type::String), is_shared(true), s(make_shared<std::string>(std::move(val))) {}
175+ any(std::string&& val) : type(Type::String), s(make_shared<std::string>(std::move(val))) {}
178− any(const shared<std::string>& val) : type(Type::String), is_shared(true), s(val) {}
177+ any(const shared<std::string>& val) : type(Type::String), s(val) {}
179− any(shared<std::string>&& val) noexcept : type(Type::String), is_shared(true), s(std::move(val)) {}
178+ any(shared<std::string>&& val) noexcept : type(Type::String), s(std::move(val)) {}
181− any(const map& val) : type(Type::Map), is_shared(true), m(make_shared<map>(val)) {}
180+ any(const map& val) : type(Type::Map), m(make_shared<map>(val)) {}
182− any(map&& val) noexcept : type(Type::Map), is_shared(true), m(make_shared<map>(std::move(val))) {}
181+ any(map&& val) noexcept : type(Type::Map), m(make_shared<map>(std::move(val))) {}
184− any(const data& val) : type(Type::Data), is_shared(true), v(make_shared<data>(val)) {}
183+ any(const data& val) : type(Type::Data), v(make_shared<data>(val)) {}
185− any(data&& val) noexcept : type(Type::Data), is_shared(true), v(make_shared<data>(std::move(val))) {}
184+ any(data&& val) noexcept : type(Type::Data), v(make_shared<data>(std::move(val))) {}
187− any(const array& val) : type(Type::Array), is_shared(true), a(make_shared<array>(val)) {}
186+ any(const array& val) : type(Type::Array), a(make_shared<array>(val)) {}
188− any(array&& val) noexcept : type(Type::Array), is_shared(true), a(make_shared<array>(std::move(val))) {}
187+ any(array&& val) noexcept : type(Type::Array), a(make_shared<array>(std::move(val))) {}
190 template <typename T>
189 template <typename T>
191 any(const T& val, typename std::enable_if<std::is_convertible<T,fn>::value>::type* = 0)
190 any(const T& val, typename std::enable_if<std::is_convertible<T,fn>::value>::type* = 0)
192− : type(Type::Function), is_shared(false), f(val) {}
191+ : type(Type::Function), f(val) {}
194 template <typename T, typename = typename std::enable_if<!std::is_same<any,T>::value &&
193 template <typename T, typename = typename std::enable_if<!std::is_same<any,T>::value &&
195 !std::is_convertible<T,fn>::value>::type>
194 !std::is_convertible<T,fn>::value>::type>
196 any(const T& val, typename std::enable_if<std::is_assignable<std::function<any(const any&)>,T>::value>::type* = 0)
195 any(const T& val, typename std::enable_if<std::is_assignable<std::function<any(const any&)>,T>::value>::type* = 0)
197− : type(Type::Closure), is_shared(true), l(make_shared<_closure<T>>(val)) {}
196+ : type(Type::Closure), l(make_shared<_closure<T>>(val)) {}
199 template <typename T>
198 template <typename T>
200 any(const T& val, typename std::enable_if<std::is_assignable<std::function<any()>,T>::value>::type* = 0)
199 any(const T& val, typename std::enable_if<std::is_assignable<std::function<any()>,T>::value>::type* = 0)
201− : type(Type::EffFunction), is_shared(true), e(make_shared<_eff_fn<T>>(val)) {}
200+ : type(Type::EffFunction), e(make_shared<_eff_fn<T>>(val)) {}
203 template <typename T>
202 template <typename T>
204 any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0)
203 any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0)
205− : type(Type::Thunk), is_shared(false), t(val) {}
204+ : type(Type::Thunk), t(val) {}
207 template <typename T>
206 template <typename T>
208 any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0)
207 any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0)
209− : type(Type::Pointer), is_shared(true), p(val) {}
208+ : type(Type::Pointer), p(val) {}
211 template <typename T>
210 template <typename T>
212 any(T&& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0) noexcept
211 any(T&& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0) noexcept
213− : type(Type::Pointer), is_shared(true), p(std::move(val)) {}
212+ : type(Type::Pointer), p(std::move(val)) {}
215− any(std::nullptr_t) : type(Type::Pointer), is_shared(true), p(nullptr) {}
214+ any(std::nullptr_t) : type(Type::Pointer), p(nullptr) {}
219 auto copy(const any& other) const -> void {
218 auto copy(const any& other) const -> void {
220− if (is_shared) {
219+ if (type & Type::Shared) {
221 new (&p) shared<void>(other.p);
220 new (&p) shared<void>(other.p);
223 f = other.f;
222 f = other.f;
@@ -225,7 +224,7 @@ class any {
227 auto move(any& other) const noexcept -> void {
226 auto move(any& other) const noexcept -> void {
228− if (is_shared) {
227+ if (type & Type::Shared) {
229 new (&p) shared<void>(std::move(other.p));
228 new (&p) shared<void>(std::move(other.p));
231 f = other.f;
230 f = other.f;
@@ -233,25 +232,24 @@ class any {
235 auto destruct() noexcept -> void {
234 auto destruct() noexcept -> void {
236− if (is_shared) {
235+ if (type & Type::Shared) {
237 p.~shared<void>();
236 p.~shared<void>();
243− any(const any& other) : type(other.type), is_shared(other.is_shared) {
242+ any(const any& other) : type(other.type) {
244 copy(other);
243 copy(other);
247− any(any&& other) noexcept : type(other.type), is_shared(other.is_shared) {
246+ any(any&& other) noexcept : type(other.type) {
248 move(other);
247 move(other);
251 auto operator=(const any& rhs) -> any& {
250 auto operator=(const any& rhs) -> any& {
252 destruct();
251 destruct();
253 type = rhs.type;
252 type = rhs.type;
254− is_shared = rhs.is_shared;
255 copy(rhs);
253 copy(rhs);
256 return *this;
254 return *this;
@@ -259,7 +257,6 @@ class any {
259 auto operator=(any&& rhs) noexcept -> any& {
257 auto operator=(any&& rhs) noexcept -> any& {
260 destruct();
258 destruct();
261 type = rhs.type;
259 type = rhs.type;
262− is_shared = rhs.is_shared;
263 move(rhs);
260 move(rhs);
264 return *this;
261 return *this;