diff --git a/deps/ox/src/ox/std/bit.hpp b/deps/ox/src/ox/std/bit.hpp index ef68c8b4..db84ce65 100644 --- a/deps/ox/src/ox/std/bit.hpp +++ b/deps/ox/src/ox/std/bit.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2018 gtalent2@gmail.com + * Copyright 2015 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -16,7 +16,7 @@ namespace ox { template typename enable_if::type bit_cast(From src) noexcept { - To dst = {}; + To dst; memcpy(&dst, &src, sizeof(src)); return dst; } diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index d8d6159e..be525669 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -8,6 +8,7 @@ #pragma once +#include "bit.hpp" #include "new.hpp" #include "types.hpp" #include "utility.hpp" @@ -37,17 +38,17 @@ class Vector { Vector &operator=(Vector &&other); - T &operator[](std::size_t i) noexcept; + [[nodiscard]] T &operator[](std::size_t i) noexcept; - const T &operator[](std::size_t i) const noexcept; + [[nodiscard]] const T &operator[](std::size_t i) const noexcept; - T &front() noexcept; + [[nodiscard]] T &front() noexcept; - const T &front() const noexcept; + [[nodiscard]] const T &front() const noexcept; - T &back() noexcept; + [[nodiscard]] T &back() noexcept; - const T &back() const noexcept; + [[nodiscard]] const T &back() const noexcept; std::size_t size() const noexcept; @@ -57,9 +58,9 @@ class Vector { void resize(std::size_t size); - T *data() noexcept; + [[nodiscard]] T *data() noexcept; - const T *data() const noexcept; + [[nodiscard]] const T *data() const noexcept; [[nodiscard]] bool contains(T) const; @@ -94,7 +95,7 @@ template Vector::Vector(std::size_t size) { m_size = size; m_cap = m_size; - m_items = reinterpret_cast(new AllocAlias[m_cap]); + m_items = bit_cast(new AllocAlias[m_cap]); for (std::size_t i = 0; i < size; i++) { m_items[i] = {}; } @@ -104,7 +105,7 @@ template Vector::Vector(const Vector &other) { m_size = other.m_size; m_cap = other.m_cap; - m_items = reinterpret_cast(new AllocAlias[m_cap]); + m_items = bit_cast(new AllocAlias[m_cap]); for (std::size_t i = 0; i < m_size; i++) { m_items[i] = ox::move(other.m_items[i]); } @@ -127,7 +128,7 @@ Vector::~Vector() { m_items[i].~T(); } } - delete[] reinterpret_cast*>(m_items); + delete[] bit_cast*>(m_items); m_items = nullptr; } @@ -136,7 +137,7 @@ Vector &Vector::operator=(const Vector &other) { this->~Vector(); m_size = other.m_size; m_cap = other.m_cap; - m_items = reinterpret_cast(new AllocAlias[m_cap]); + m_items = bit_cast(new AllocAlias[m_cap]); for (std::size_t i = 0; i < m_size; i++) { m_items[i] = other.m_items[i]; } @@ -293,7 +294,7 @@ template void Vector::expandCap(std::size_t cap) { auto oldItems = m_items; m_cap = cap; - m_items = reinterpret_cast(new AllocAlias[m_cap]); + m_items = bit_cast(new AllocAlias[m_cap]); if (oldItems) { // move over old items const auto itRange = cap > m_size ? m_size : cap; for (std::size_t i = 0; i < itRange; i++) { @@ -302,7 +303,7 @@ void Vector::expandCap(std::size_t cap) { for (std::size_t i = itRange; i < m_cap; i++) { new (&m_items[i]) T; } - delete[] reinterpret_cast*>(oldItems); + delete[] bit_cast*>(oldItems); } }