@@ -65,27 +65,26 @@ const size_t constructor = 0;
6565class any {
6666
6767 public:
68− enum class Type : int8_t {
69− Unknown,
70− Integer,
71− Double,
72− Character,
73− Boolean,
74− StringLiteral,
75− String,
76− Map,
77− Data,
78− Array,
79− Function,
80− Closure,
81− EffFunction,
82− Thunk,
83− Pointer
68+ enum Type {
69+ Thunk = 0x00,
70+ Integer = 0x01,
71+ Double = 0x02,
72+ Character = 0x03,
73+ Boolean = 0x04,
74+ StringLiteral = 0x05,
75+ Function = 0x06,
76+ Shared = 0x08,
77+ String = 0x08,
78+ Map = 0x09,
79+ Data = 0x0A,
80+ Array = 0x0B,
81+ Closure = 0x0C,
82+ EffFunction = 0x0D,
83+ Pointer = 0x0E
8484 };
8585
8686 private:
8787 mutable Type type;
88− mutable bool is_shared;
8988
9089 public:
9190 struct as_thunk {
@@ -141,83 +140,83 @@ class any {
141140
142141 private:
143142 union {
143+ mutable thunk t;
144144 mutable long i;
145145 mutable double d;
146146 mutable char c;
147147 mutable bool b;
148148 mutable string r;
149+ mutable fn f;
149150 mutable shared<std::string> s;
150151 mutable shared<map> m;
151152 mutable shared<data> v;
152153 mutable shared<array> a;
153− mutable fn f;
154154 mutable shared<closure> l;
155155 mutable shared<eff_fn> e;
156− mutable thunk t;
157156 mutable shared<void> p;
158157 };
159158
160159 public:
161160
162− any(const long val) : type(Type::Integer), is_shared(false), i(val) {}
163− any(const int val) : type(Type::Integer), is_shared(false), i(val) {}
164− any(const unsigned int val) : type(Type::Integer), is_shared(false), i(val) {}
165− any(const double val) : type(Type::Double), is_shared(false), d(val) {}
166− any(const char val) : type(Type::Character), is_shared(false), c(val) {}
161+ any(const long val) : type(Type::Integer), i(val) {}
162+ any(const int val) : type(Type::Integer), i(val) {}
163+ any(const unsigned int val) : type(Type::Integer), i(val) {}
164+ any(const double val) : type(Type::Double), d(val) {}
165+ any(const char val) : type(Type::Character), c(val) {}
167166
168167 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) {}
170169
171170 template <size_t N>
172− any(const char (&val)[N]) : type(Type::StringLiteral), is_shared(false), r(val) {}
173− any(char * val) : type(Type::String), is_shared(true), s(make_shared<std::string>(val)) {}
171+ any(const char (&val)[N]) : type(Type::StringLiteral), r(val) {}
172+ any(char * val) : type(Type::String), s(make_shared<std::string>(val)) {}
174173
175− any(const std::string& val) : type(Type::String), is_shared(true), 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))) {}
174+ any(const std::string& val) : type(Type::String), s(make_shared<std::string>(val)) {}
175+ any(std::string&& val) : type(Type::String), s(make_shared<std::string>(std::move(val))) {}
177176
178− any(const shared<std::string>& val) : type(Type::String), is_shared(true), s(val) {}
179− any(shared<std::string>&& val) noexcept : type(Type::String), is_shared(true), s(std::move(val)) {}
177+ any(const shared<std::string>& val) : type(Type::String), s(val) {}
178+ any(shared<std::string>&& val) noexcept : type(Type::String), s(std::move(val)) {}
180179
181− any(const map& val) : type(Type::Map), is_shared(true), m(make_shared<map>(val)) {}
182− any(map&& val) noexcept : type(Type::Map), is_shared(true), m(make_shared<map>(std::move(val))) {}
180+ any(const map& val) : type(Type::Map), m(make_shared<map>(val)) {}
181+ any(map&& val) noexcept : type(Type::Map), m(make_shared<map>(std::move(val))) {}
183182
184− any(const data& val) : type(Type::Data), is_shared(true), v(make_shared<data>(val)) {}
185− any(data&& val) noexcept : type(Type::Data), is_shared(true), v(make_shared<data>(std::move(val))) {}
183+ any(const data& val) : type(Type::Data), v(make_shared<data>(val)) {}
184+ any(data&& val) noexcept : type(Type::Data), v(make_shared<data>(std::move(val))) {}
186185
187− any(const array& val) : type(Type::Array), is_shared(true), a(make_shared<array>(val)) {}
188− any(array&& val) noexcept : type(Type::Array), is_shared(true), a(make_shared<array>(std::move(val))) {}
186+ any(const array& val) : type(Type::Array), a(make_shared<array>(val)) {}
187+ any(array&& val) noexcept : type(Type::Array), a(make_shared<array>(std::move(val))) {}
189188
190189 template <typename T>
191190 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) {}
193192
194193 template <typename T, typename = typename std::enable_if<!std::is_same<any,T>::value &&
195194 !std::is_convertible<T,fn>::value>::type>
196195 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)) {}
198197
199198 template <typename T>
200199 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)) {}
202201
203202 template <typename T>
204203 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) {}
206205
207206 template <typename T>
208207 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) {}
210209
211210 template <typename T>
212211 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)) {}
214213
215− any(std::nullptr_t) : type(Type::Pointer), is_shared(true), p(nullptr) {}
214+ any(std::nullptr_t) : type(Type::Pointer), p(nullptr) {}
216215
217216 private:
218217
219218 auto copy(const any& other) const -> void {
220− if (is_shared) {
219+ if (type & Type::Shared) {
221220 new (&p) shared<void>(other.p);
222221 } else {
223222 f = other.f;
@@ -225,7 +224,7 @@ class any {
225224 }
226225
227226 auto move(any& other) const noexcept -> void {
228− if (is_shared) {
227+ if (type & Type::Shared) {
229228 new (&p) shared<void>(std::move(other.p));
230229 } else {
231230 f = other.f;
@@ -233,25 +232,24 @@ class any {
233232 }
234233
235234 auto destruct() noexcept -> void {
236− if (is_shared) {
235+ if (type & Type::Shared) {
237236 p.~shared<void>();
238237 }
239238 }
240239
241240 public:
242241
243− any(const any& other) : type(other.type), is_shared(other.is_shared) {
242+ any(const any& other) : type(other.type) {
244243 copy(other);
245244 }
246245
247− any(any&& other) noexcept : type(other.type), is_shared(other.is_shared) {
246+ any(any&& other) noexcept : type(other.type) {
248247 move(other);
249248 }
250249
251250 auto operator=(const any& rhs) -> any& {
252251 destruct();
253252 type = rhs.type;
254− is_shared = rhs.is_shared;
255253 copy(rhs);
256254 return *this;
257255 }
@@ -259,7 +257,6 @@ class any {
259257 auto operator=(any&& rhs) noexcept -> any& {
260258 destruct();
261259 type = rhs.type;
262− is_shared = rhs.is_shared;
263260 move(rhs);
264261 return *this;
265262 }