Skip to content

Commit

Permalink
Fix build errors (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoemmen authored Apr 6, 2023
1 parent b53ee96 commit a01bd14
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions examples/pitched_allocation/pitched_allocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ template<class T>
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.
Expand All @@ -61,6 +63,7 @@ class const_proxy {
std::memcpy(&f, p_, sizeof(T));
return f;
}

private:
const char* p_ = nullptr;
};
Expand All @@ -69,17 +72,19 @@ template<class T>
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;
Expand All @@ -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)};
};

Expand All @@ -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)};
};

Expand Down

0 comments on commit a01bd14

Please sign in to comment.