General: Make operator bool() explicit where applicable

Makes conversions to bool slightly less error-prone by requiring them to
be explicit in non-obvious contexts.
This commit is contained in:
Lioncash 2019-08-21 17:31:20 -04:00
parent 120ed20bfa
commit 7bb3912d39
8 changed files with 10 additions and 10 deletions

View File

@ -67,7 +67,7 @@ public:
return *this;
}
operator bool() const { return ((*WordRef) & (BitWord(1) << BitPos)) != 0; }
explicit operator bool() const { return ((*WordRef) & (BitWord(1) << BitPos)) != 0; }
};
/// BitVector default ctor - Creates an empty bitvector.

View File

@ -57,7 +57,7 @@ class SDNARead {
public:
explicit SDNARead(SystemStringView path);
operator bool() const { return !m_data.empty(); }
explicit operator bool() const { return !m_data.empty(); }
const SDNABlock& sdnaBlock() const { return m_sdnaBlock; }
void enumerate(const std::function<bool(const FileBlock& block, athena::io::MemoryReader& r)>& func) const;
};

View File

@ -246,7 +246,7 @@ private:
public:
Project(const ProjectRootPath& rootPath);
operator bool() const { return m_valid; }
explicit operator bool() const { return m_valid; }
/**
* @brief Configuration file handle

View File

@ -173,7 +173,7 @@ public:
}, static_cast<const base&>(*this));
}
constexpr operator bool() const noexcept {
constexpr explicit operator bool() const noexcept {
return !std::holds_alternative<typename std::variant_alternative_t<0, std::variant<_Types...>>>(*this);
}
};

View File

@ -153,7 +153,7 @@ public:
return {bucket.buffer, m_div.rem * m_pool->m_stride};
}
operator bool() const { return m_pool != nullptr && m_index != -1; }
explicit operator bool() const { return m_pool != nullptr && m_index != -1; }
};
UniformBufferPool() = default;

View File

@ -158,7 +158,7 @@ public:
return {bucket.buffer, m_div.rem};
}
operator bool() const { return m_pool != nullptr && m_index != -1; }
explicit operator bool() const { return m_pool != nullptr && m_index != -1; }
};
VertexBufferPool() = default;

View File

@ -525,7 +525,7 @@ public:
DirectoryEnumerator(SystemStringView path, Mode mode = Mode::DirsThenFilesSorted, bool sizeSort = false,
bool reverse = false, bool noHidden = false);
operator bool() const { return m_entries.size() != 0; }
explicit operator bool() const { return m_entries.size() != 0; }
size_t size() const { return m_entries.size(); }
std::vector<Entry>::const_iterator begin() const { return m_entries.cbegin(); }
std::vector<Entry>::const_iterator end() const { return m_entries.cend(); }
@ -557,7 +557,7 @@ public:
/**
* @brief Tests for non-empty project root path
*/
operator bool() const { return m_projRoot.size() != 0; }
explicit operator bool() const { return m_projRoot.size() != 0; }
/**
* @brief Construct a representation of a project root path
@ -677,7 +677,7 @@ public:
/**
* @brief Tests for non-empty project path
*/
operator bool() const { return m_absPath.size() != 0; }
explicit operator bool() const { return m_absPath.size() != 0; }
/**
* @brief Clears path

View File

@ -25,7 +25,7 @@ public:
inflateInit(&m_zstrm);
}
~ShaderCacheZipStream() override { inflateEnd(&m_zstrm); }
operator bool() const { return m_compBuf.operator bool(); }
explicit operator bool() const { return m_compBuf.operator bool(); }
atUint64 readUBytesToBuf(void* buf, atUint64 len) override {
m_zstrm.next_out = (Bytef*)buf;
m_zstrm.avail_out = len;