From a01bd142fcf9c64d8038057909faf0e46ab06388 Mon Sep 17 00:00:00 2001 From: Mark Hoemmen Date: Thu, 6 Apr 2023 15:46:28 -0600 Subject: [PATCH] Fix build errors (part 2) --- .../pitched_allocation/pitched_allocation.cpp | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/pitched_allocation/pitched_allocation.cpp b/examples/pitched_allocation/pitched_allocation.cpp index 75059e97..66e3195f 100755 --- a/examples/pitched_allocation/pitched_allocation.cpp +++ b/examples/pitched_allocation/pitched_allocation.cpp @@ -46,11 +46,13 @@ template class const_proxy { private: friend class const_tbs_proxy; - constexpr const_proxy(const char* p) : p_(p) {} + constexpr const_proxy(const char* p) noexcept + : p_(p) + {} public: // Not constexpr because of reinterpret_cast or memcpy - operator T () const { + operator T () const noexcept { // We can't do the commented-out reinterpret_cast // in Standard C++, because p_ might not have correct // alignment to point to a T. @@ -61,6 +63,7 @@ class const_proxy { std::memcpy(&f, p_, sizeof(T)); return f; } + private: const char* p_ = nullptr; }; @@ -69,17 +72,19 @@ template class nonconst_proxy { private: friend class nonconst_tbs_proxy; - constexpr nonconst_proxy(char* p) : p_(p) {} + constexpr nonconst_proxy(char* p) noexcept + : p_(p) + {} public: // Not constexpr because of memcpy - nonconst_proxy& operator=(const T& f) { + nonconst_proxy& operator=(const T& f) noexcept { std::memcpy(p_, &f, sizeof(T)); return *this; } // Not constexpr because of memcpy - constexpr operator T () const { + operator T () const noexcept { T f; std::memcpy(&f, p_, sizeof(T)); return f; @@ -93,19 +98,19 @@ class nonconst_tbs_proxy { private: char* p_ = nullptr; -public: - constexpr nonconst_tbs_proxy(char* p) noexcept +public: + nonconst_tbs_proxy(char* p) noexcept : p_(p), f0(p), i(p + sizeof(float)), f1(p + sizeof(float) + sizeof(int)) {} - constexpr nonconst_tbs_proxy& operator=(const tbs& s) noexcept { + nonconst_tbs_proxy& operator=(const tbs& s) noexcept { this->f0 = s.f0; this->i = s.i; this->f1 = s.f1; return *this; } - constexpr operator tbs() const noexcept { + operator tbs() const noexcept { return {float(f0), std::int32_t(i), float(f1)}; }; @@ -127,7 +132,7 @@ class const_tbs_proxy { : p_(p), f0(p), i(p + sizeof(float)), f1(p + sizeof(float) + sizeof(int)) {} - constexpr operator tbs() const noexcept { + operator tbs() const noexcept { return {float(f0), std::int32_t(i), float(f1)}; };