@@ -38,51 +38,37 @@ namespace purescript {
39 using std::shared_ptr<void>::shared_ptr;
39 using std::shared_ptr<void>::shared_ptr;
41− boxed() noexcept : std::shared_ptr<void>() {
41+ boxed() noexcept : std::shared_ptr<void>() {}
44− boxed(const std::nullptr_t) noexcept : std::shared_ptr<void>() {
42+ boxed(const std::nullptr_t) noexcept : std::shared_ptr<void>() {}
47− boxed(const int n) : std::shared_ptr<void>(std::make_shared<int>(n)) {
43+ boxed(const int n) : std::shared_ptr<void>(std::make_shared<int>(n)) {}
50 boxed(const long n) : std::shared_ptr<void>(std::make_shared<int>(static_cast<int>(n))) {
45 boxed(const long n) : std::shared_ptr<void>(std::make_shared<int>(static_cast<int>(n))) {
51−#ifndef NDEBUG
46+#if !defined(NDEBUG) // if debug build
52 if (n < std::numeric_limits<int>::min() || n > std::numeric_limits<int>::max()) {
47 if (n < std::numeric_limits<int>::min() || n > std::numeric_limits<int>::max()) {
53 throw std::runtime_error("integer out of range");
48 throw std::runtime_error("integer out of range");
55−#endif // !NDEBUG
50+#endif // !defined(NDEBUG)
58− boxed(const double n) : std::shared_ptr<void>(std::make_shared<double>(n)) {
61− boxed(const bool b) : std::shared_ptr<void>(std::make_shared<bool>(b)) {
64− boxed(const char s[]) : std::shared_ptr<void>(std::make_shared<string>(s)) {
67− boxed(string&& s) : std::shared_ptr<void>(std::make_shared<string>(std::move(s))) {
70− boxed(array_t&& l) : std::shared_ptr<void>(std::make_shared<array_t>(std::move(l))) {
53+ boxed(const double n) : std::shared_ptr<void>(std::make_shared<double>(n)) {}
54+ boxed(const bool b) : std::shared_ptr<void>(std::make_shared<bool>(b)) {}
55+ boxed(const char s[]) : std::shared_ptr<void>(std::make_shared<string>(s)) {}
56+ boxed(string&& s) : std::shared_ptr<void>(std::make_shared<string>(std::move(s))) {}
57+ boxed(array_t&& l) : std::shared_ptr<void>(std::make_shared<array_t>(std::move(l))) {}
73− boxed(dict_t&& m) : std::shared_ptr<void>(std::make_shared<dict_t>(std::move(m))) {
58+ boxed(dict_t&& m) : std::shared_ptr<void>(std::make_shared<dict_t>(std::move(m))) {}
76 template <typename T,
60 template <typename T,
77 typename = typename std::enable_if<!std::is_same<boxed,T>::value>::type>
61 typename = typename std::enable_if<!std::is_same<boxed,T>::value>::type>
78 boxed(const T& f,
62 boxed(const T& f,
79− typename std::enable_if<std::is_assignable<std::function<boxed(boxed)>,T>::value>::type* = 0) : std::shared_ptr<void>(std::make_shared<fn_t>(f)) {
63+ typename std::enable_if<std::is_assignable<std::function<boxed(boxed)>,T>::value>::type* = 0)
64+ : std::shared_ptr<void>(std::make_shared<fn_t>(f)) {
82 template <typename T,
67 template <typename T,
83 typename = typename std::enable_if<!std::is_same<boxed,T>::value>::type>
68 typename = typename std::enable_if<!std::is_same<boxed,T>::value>::type>
84 boxed(const T& f,
69 boxed(const T& f,
85− typename std::enable_if<std::is_assignable<std::function<boxed(void)>,T>::value>::type* = 0) : std::shared_ptr<void>(std::make_shared<eff_fn_t>(f)) {
70+ typename std::enable_if<std::is_assignable<std::function<boxed(void)>,T>::value>::type* = 0)
71+ : std::shared_ptr<void>(std::make_shared<eff_fn_t>(f)) {
88 template <typename T,
74 template <typename T,
@@ -109,36 +95,30 @@ namespace purescript {
111 auto operator[](const char key[]) const -> const boxed& {
97 auto operator[](const char key[]) const -> const boxed& {
112− const auto& dict = *static_cast<const dict_t*>(get());
98+ return (*static_cast<const dict_t*>(get()))[key];
116 auto operator[](const char key[]) -> boxed& {
101 auto operator[](const char key[]) -> boxed& {
117− auto& dict = *static_cast<dict_t*>(get());
102+ return (*static_cast<dict_t*>(get()))[key];
121−#ifdef NDEBUG
105+#if !defined(NDEBUG) // if debug build
122 auto operator[](const int index) const -> const boxed& {
106 auto operator[](const int index) const -> const boxed& {
123− const auto& array = *static_cast<const array_t*>(get());
107+ return static_cast<const array_t*>(get())->at(index);
124− return array[index];
127 auto operator[](const int index) -> boxed& {
110 auto operator[](const int index) -> boxed& {
128− auto& array = *static_cast<array_t*>(get());
111+ return static_cast<array_t*>(get())->at(index);
129− return array[index];
131−#else
113+#else // not debug build
132 auto operator[](const int index) const -> const boxed& {
114 auto operator[](const int index) const -> const boxed& {
133− const auto& array = *static_cast<const array_t*>(get());
115+ return (*static_cast<const array_t*>(get()))[index];
134− return array.at(index);
137 auto operator[](const int index) -> boxed& {
118 auto operator[](const int index) -> boxed& {
138− auto& array = *static_cast<array_t*>(get());
119+ return (*static_cast<array_t*>(get()))[index];
139− return array.at(index);
141−#endif // NDEBUG
121+#endif // !defined(NDEBUG)
143 }; // class boxed
123 }; // class boxed
@@ -148,9 +128,8 @@ namespace purescript {
150 template <typename T>
130 template <typename T>
151− inline auto unbox(const boxed& b) -> const T& {
131+ constexpr inline auto unbox(const boxed& b) -> const T& {
152− const auto& unboxed = *static_cast<const T*>(b.get());
132+ return *static_cast<const T*>(b.get());
156 template <typename T,
135 template <typename T,
@@ -167,9 +146,8 @@ namespace purescript {
169 template <typename T>
148 template <typename T>
170− inline auto peek(boxed& b) -> T& {
149+ constexpr inline auto peek(boxed& b) -> T& {
171− auto& unboxed = *static_cast<T*>(b.get());
150+ return *static_cast<T*>(b.get());
175 template <typename T>
153 template <typename T>