Skip to content

Commit

Permalink
cleanup: Belatedly change OIIO_CONSTEXPR14 to constexpr (AcademySoftw…
Browse files Browse the repository at this point in the history
…areFoundation#4153)

We've been using C++14 minimum for years, and in fact will move to 17
for next year's major release.

Also use error reporting correctly if a sufficient C++ verion is not
found

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Feb 29, 2024
1 parent c14910c commit 42f2faa
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/build-scripts/ci-startup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export OpenImageIO_CI=true
export USE_NINJA=${USE_NINJA:=1}
export CMAKE_GENERATOR=${CMAKE_GENERATOR:=Ninja}
export CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:=Release}
export CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD:=11}
export CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD:=14}

export LOCAL_DEPS_DIR=${LOCAL_DEPS_DIR:=$HOME/ext}
export PATH=${LOCAL_DEPS_DIR}/dist/bin:$PATH
Expand Down
2 changes: 1 addition & 1 deletion src/cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
message (STATUS "Building with C++${CMAKE_CXX_STANDARD}, downstream minimum C++${DOWNSTREAM_CXX_STANDARD}")
if (CMAKE_CXX_STANDARD VERSION_LESS CMAKE_CXX_MINIMUM)
message (ERROR "C++${CMAKE_CXX_STANDARD} is not supported, minimum is C++${CMAKE_CXX_MINIMUM}")
message (FATAL_ERROR "C++${CMAKE_CXX_STANDARD} is not supported, minimum is C++${CMAKE_CXX_MINIMUM}")
endif ()

###########################################################################
Expand Down
6 changes: 3 additions & 3 deletions src/include/OpenImageIO/fmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ using std::isnan;
/// Quick test for whether an integer is a power of 2.
///
template<typename T>
inline OIIO_HOSTDEVICE OIIO_CONSTEXPR14 bool
inline OIIO_HOSTDEVICE constexpr bool
ispow2(T x) noexcept
{
// Numerous references for this bit trick are on the web. The
Expand All @@ -158,7 +158,7 @@ ispow2(T x) noexcept

/// Round up to next higher power of 2 (return x if it's already a power
/// of 2).
inline OIIO_HOSTDEVICE OIIO_CONSTEXPR14 int
inline OIIO_HOSTDEVICE constexpr int
ceil2(int x) noexcept
{
// Here's a version with no loops.
Expand All @@ -181,7 +181,7 @@ ceil2(int x) noexcept

/// Round down to next lower power of 2 (return x if it's already a power
/// of 2).
inline OIIO_HOSTDEVICE OIIO_CONSTEXPR14 int
inline OIIO_HOSTDEVICE constexpr int
floor2(int x) noexcept
{
// Make all bits past the first 1 also be 1, i.e. 0001xxxx -> 00011111
Expand Down
12 changes: 6 additions & 6 deletions src/include/OpenImageIO/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ OIIO_HOSTDEVICE inline constexpr uint128_t Uint128(uint64_t lo, uint64_t hi) {
return lo + (((uint128_t)hi) << 64);
}

OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 void
OIIO_HOSTDEVICE inline constexpr void
CopyUint128(uint128_t &dst, const uint128_t src) {
dst = src;
}
Expand All @@ -336,11 +336,11 @@ OIIO_HOSTDEVICE inline constexpr uint64_t Uint128High64(const uint128_t x) {
return x.second;
}

OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 uint128_t Uint128(uint64_t lo, uint64_t hi) {
OIIO_HOSTDEVICE inline constexpr uint128_t Uint128(uint64_t lo, uint64_t hi) {
return uint128_t(lo, hi);
}

OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 void
OIIO_HOSTDEVICE inline constexpr void
CopyUint128(uint128_t &dst, const uint128_t src) {
dst.first = src.first;
dst.second = src.second;
Expand Down Expand Up @@ -402,7 +402,7 @@ uint128_t OIIO_API Hash128WithSeed(const char* s, size_t len, uint128_t seed);
// This is intended to be a reasonably good hash function.
// May change from time to time, may differ on different platforms, may differ
// depending on NDEBUG.
OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 uint64_t Hash128to64(uint128_t x) {
OIIO_HOSTDEVICE inline constexpr uint64_t Hash128to64(uint128_t x) {
// Murmur-inspired hashing.
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
Expand All @@ -426,7 +426,7 @@ uint128_t OIIO_API Fingerprint128(const char* s, size_t len);

// This is intended to be a good fingerprinting primitive.
// See below for more overloads.
OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 uint64_t Fingerprint(uint128_t x) {
OIIO_HOSTDEVICE inline constexpr uint64_t Fingerprint(uint128_t x) {
// Murmur-inspired hashing.
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
Expand All @@ -440,7 +440,7 @@ OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 uint64_t Fingerprint(uint128_t x) {
}

// This is intended to be a good fingerprinting primitive.
OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 uint64_t Fingerprint(uint64_t x) {
OIIO_HOSTDEVICE inline constexpr uint64_t Fingerprint(uint64_t x) {
// Murmur-inspired hashing.
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
uint64_t b = x * kMul;
Expand Down
12 changes: 3 additions & 9 deletions src/include/OpenImageIO/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,14 @@ inline void aligned_delete(T* t) {
}



#if OIIO_CPLUSPLUS_VERSION >= 14
using std::enable_if_t; // Use C++14 std::enable_if_t
#else
// Define enable_if_t for C++11
template <bool B, class T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
#endif
// DEPRECATED(2.6)
using std::enable_if_t;

// An enable_if helper to be used in template parameters which results in
// much shorter symbols: https://godbolt.org/z/sWw4vP
// Borrowed from fmtlib.
#ifndef OIIO_ENABLE_IF
# define OIIO_ENABLE_IF(...) OIIO::enable_if_t<(__VA_ARGS__), int> = 0
# define OIIO_ENABLE_IF(...) std::enable_if_t<(__VA_ARGS__), int> = 0
#endif

OIIO_NAMESPACE_END
10 changes: 5 additions & 5 deletions src/include/OpenImageIO/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ using cspan = span<const T, Extent>;

/// Compare all elements of two spans for equality
template <class T, oiio_span_size_type X, class U, oiio_span_size_type Y>
OIIO_CONSTEXPR14 bool operator== (span<T,X> l, span<U,Y> r) {
constexpr bool operator== (span<T,X> l, span<U,Y> r) {
#if OIIO_CPLUSPLUS_VERSION >= 20
return std::equal (l.begin(), l.end(), r.begin(), r.end());
#else
Expand All @@ -247,7 +247,7 @@ OIIO_CONSTEXPR14 bool operator== (span<T,X> l, span<U,Y> r) {

/// Compare all elements of two spans for inequality
template <class T, oiio_span_size_type X, class U, oiio_span_size_type Y>
OIIO_CONSTEXPR14 bool operator!= (span<T,X> l, span<U,Y> r) {
constexpr bool operator!= (span<T,X> l, span<U,Y> r) {
return !(l == r);
}

Expand Down Expand Up @@ -299,7 +299,7 @@ class span_strided {

/// Construct from std::vector<T>.
template<class Allocator>
OIIO_CONSTEXPR14 span_strided (std::vector<T, Allocator> &v)
constexpr span_strided (std::vector<T, Allocator> &v)
: span_strided(v.data(), v.size(), 1) {}

/// Construct from const std::vector<T>. This turns const std::vector<T>
Expand Down Expand Up @@ -359,7 +359,7 @@ using cspan_strided = span_strided<const T, Extent>;

/// Compare all elements of two spans for equality
template <class T, oiio_span_size_type X, class U, oiio_span_size_type Y>
OIIO_CONSTEXPR14 bool operator== (span_strided<T,X> l, span_strided<U,Y> r) {
constexpr bool operator== (span_strided<T,X> l, span_strided<U,Y> r) {
auto lsize = l.size();
if (lsize != r.size())
return false;
Expand All @@ -371,7 +371,7 @@ OIIO_CONSTEXPR14 bool operator== (span_strided<T,X> l, span_strided<U,Y> r) {

/// Compare all elements of two spans for inequality
template <class T, oiio_span_size_type X, class U, oiio_span_size_type Y>
OIIO_CONSTEXPR14 bool operator!= (span_strided<T,X> l, span_strided<U,Y> r) {
constexpr bool operator!= (span_strided<T,X> l, span_strided<U,Y> r) {
return !(l == r);
}

Expand Down
12 changes: 6 additions & 6 deletions src/include/OpenImageIO/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class basic_string_view {
const CharT* c_str() const;

// Assignment
OIIO_CONSTEXPR14 basic_string_view& operator=(const basic_string_view& copy) noexcept = default;
constexpr basic_string_view& operator=(const basic_string_view& copy) noexcept = default;

/// Convert a string_view to a `std::string`.
operator std::basic_string<CharT, Traits>() const {
Expand Down Expand Up @@ -223,22 +223,22 @@ class basic_string_view {
constexpr const_pointer data() const noexcept { return m_chars; }

// modifiers
OIIO_CONSTEXPR14 void clear() noexcept { init(nullptr, 0); }
OIIO_CONSTEXPR14 void remove_prefix(size_type n) noexcept
constexpr void clear() noexcept { init(nullptr, 0); }
constexpr void remove_prefix(size_type n) noexcept
{
if (n > m_len)
n = m_len;
m_chars += n;
m_len -= n;
}
OIIO_CONSTEXPR14 void remove_suffix(size_type n) noexcept
constexpr void remove_suffix(size_type n) noexcept
{
if (n > m_len)
n = m_len;
m_len -= n;
}

OIIO_CONSTEXPR14 basic_string_view substr(size_type pos, size_type n = npos) const noexcept
constexpr basic_string_view substr(size_type pos, size_type n = npos) const noexcept
{
if (pos >= size())
return basic_string_view(); // start past end -> return empty
Expand Down Expand Up @@ -409,7 +409,7 @@ class basic_string_view {
const CharT* m_chars = nullptr;
size_t m_len = 0;

OIIO_CONSTEXPR14 void init(const CharT* chars, size_t len) noexcept
constexpr void init(const CharT* chars, size_t len) noexcept
{
m_chars = chars;
m_len = len;
Expand Down
6 changes: 3 additions & 3 deletions src/include/OpenImageIO/typedesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct OIIO_UTIL_API TypeDesc {

/// Return the number of elements: 1 if not an array, or the array
/// length. Invalid to call this for arrays of undetermined size.
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 size_t numelements () const noexcept {
OIIO_HOSTDEVICE constexpr size_t numelements () const noexcept {
OIIO_DASSERT_MSG (arraylen >= 0, "Called numelements() on TypeDesc "
"of array with unspecified length (%d)", arraylen);
return (arraylen >= 1 ? arraylen : 1);
Expand All @@ -186,7 +186,7 @@ struct OIIO_UTIL_API TypeDesc {
/// Return the number of basetype values: the aggregate count multiplied
/// by the array length (or 1 if not an array). Invalid to call this
/// for arrays of undetermined size.
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 size_t basevalues () const noexcept {
OIIO_HOSTDEVICE constexpr size_t basevalues () const noexcept {
return numelements() * aggregate;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ struct OIIO_UTIL_API TypeDesc {

/// Return the type of one element, i.e., strip out the array-ness.
///
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 TypeDesc elementtype () const noexcept {
OIIO_HOSTDEVICE constexpr TypeDesc elementtype () const noexcept {
TypeDesc t (*this); t.arraylen = 0; return t;
}

Expand Down

0 comments on commit 42f2faa

Please sign in to comment.