Skip to content

Commit

Permalink
ARROW-17875: [C++] Remove assorted pre-C++17 compatibility measures
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Sep 28, 2022
1 parent 6d02e4f commit 7e3a408
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 67 deletions.
4 changes: 0 additions & 4 deletions cpp/src/arrow/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,7 @@ class [[nodiscard]] Result : public util::EqualityComparable<Result<T>> {

constexpr const T& ValueUnsafe() const& { return *storage_.get(); }

#if __cpp_constexpr >= 201304L // non-const constexpr
constexpr T& ValueUnsafe() & { return *storage_.get(); }
#else
T& ValueUnsafe() & { return *storage_.get(); }
#endif

T ValueUnsafe() && { return MoveValueUnsafe(); }

Expand Down
40 changes: 21 additions & 19 deletions cpp/src/arrow/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status
public util::ToStringOstreamable<Status> {
public:
// Create a success status.
Status() noexcept : state_(NULLPTR) {}
constexpr Status() noexcept : state_(NULLPTR) {}
~Status() noexcept {
// ARROW-2400: On certain compilers, splitting off the slow path improves
// performance significantly.
Expand Down Expand Up @@ -271,41 +271,43 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status
}

/// Return true iff the status indicates success.
bool ok() const { return (state_ == NULLPTR); }
constexpr bool ok() const { return (state_ == NULLPTR); }

/// Return true iff the status indicates an out-of-memory error.
bool IsOutOfMemory() const { return code() == StatusCode::OutOfMemory; }
constexpr bool IsOutOfMemory() const { return code() == StatusCode::OutOfMemory; }
/// Return true iff the status indicates a key lookup error.
bool IsKeyError() const { return code() == StatusCode::KeyError; }
constexpr bool IsKeyError() const { return code() == StatusCode::KeyError; }
/// Return true iff the status indicates invalid data.
bool IsInvalid() const { return code() == StatusCode::Invalid; }
constexpr bool IsInvalid() const { return code() == StatusCode::Invalid; }
/// Return true iff the status indicates a cancelled operation.
bool IsCancelled() const { return code() == StatusCode::Cancelled; }
constexpr bool IsCancelled() const { return code() == StatusCode::Cancelled; }
/// Return true iff the status indicates an IO-related failure.
bool IsIOError() const { return code() == StatusCode::IOError; }
constexpr bool IsIOError() const { return code() == StatusCode::IOError; }
/// Return true iff the status indicates a container reaching capacity limits.
bool IsCapacityError() const { return code() == StatusCode::CapacityError; }
constexpr bool IsCapacityError() const { return code() == StatusCode::CapacityError; }
/// Return true iff the status indicates an out of bounds index.
bool IsIndexError() const { return code() == StatusCode::IndexError; }
constexpr bool IsIndexError() const { return code() == StatusCode::IndexError; }
/// Return true iff the status indicates a type error.
bool IsTypeError() const { return code() == StatusCode::TypeError; }
constexpr bool IsTypeError() const { return code() == StatusCode::TypeError; }
/// Return true iff the status indicates an unknown error.
bool IsUnknownError() const { return code() == StatusCode::UnknownError; }
constexpr bool IsUnknownError() const { return code() == StatusCode::UnknownError; }
/// Return true iff the status indicates an unimplemented operation.
bool IsNotImplemented() const { return code() == StatusCode::NotImplemented; }
constexpr bool IsNotImplemented() const { return code() == StatusCode::NotImplemented; }
/// Return true iff the status indicates a (de)serialization failure
bool IsSerializationError() const { return code() == StatusCode::SerializationError; }
constexpr bool IsSerializationError() const {
return code() == StatusCode::SerializationError;
}
/// Return true iff the status indicates a R-originated error.
bool IsRError() const { return code() == StatusCode::RError; }
constexpr bool IsRError() const { return code() == StatusCode::RError; }

bool IsCodeGenError() const { return code() == StatusCode::CodeGenError; }
constexpr bool IsCodeGenError() const { return code() == StatusCode::CodeGenError; }

bool IsExpressionValidationError() const {
constexpr bool IsExpressionValidationError() const {
return code() == StatusCode::ExpressionValidationError;
}

bool IsExecutionError() const { return code() == StatusCode::ExecutionError; }
bool IsAlreadyExists() const { return code() == StatusCode::AlreadyExists; }
constexpr bool IsExecutionError() const { return code() == StatusCode::ExecutionError; }
constexpr bool IsAlreadyExists() const { return code() == StatusCode::AlreadyExists; }

/// \brief Return a string representation of this status suitable for printing.
///
Expand All @@ -318,7 +320,7 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status
static std::string CodeAsString(StatusCode);

/// \brief Return the StatusCode value attached to this status.
StatusCode code() const { return ok() ? StatusCode::OK : state_->code; }
constexpr StatusCode code() const { return ok() ? StatusCode::OK : state_->code; }

/// \brief Return the specific error message attached to this status.
const std::string& message() const {
Expand Down
18 changes: 7 additions & 11 deletions cpp/src/arrow/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <algorithm>
#include <cstddef>
#include <memory>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -436,18 +435,15 @@ Status TupleRangeFromTable(const Table& table, const compute::CastOptions& cast_
constexpr std::size_t n_columns = std::tuple_size<row_type>::value;

if (table.schema()->num_fields() != n_columns) {
std::stringstream ss;
ss << "Number of columns in the table does not match the width of the target: ";
ss << table.schema()->num_fields() << " != " << n_columns;
return Status::Invalid(ss.str());
return Status::Invalid(
"Number of columns in the table does not match the width of the target: ",
table.schema()->num_fields(), " != ", n_columns);
}

// TODO: Use std::size with C++17
if (rows->size() != static_cast<size_t>(table.num_rows())) {
std::stringstream ss;
ss << "Number of rows in the table does not match the size of the target: ";
ss << table.num_rows() << " != " << rows->size();
return Status::Invalid(ss.str());
if (std::size(*rows) != static_cast<size_t>(table.num_rows())) {
return Status::Invalid(
"Number of rows in the table does not match the size of the target: ",
table.num_rows(), " != ", std::size(*rows));
}

// Check that all columns have the correct type, otherwise cast them.
Expand Down
4 changes: 0 additions & 4 deletions cpp/src/arrow/util/aligned_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ class AlignedStorage {
public:
static constexpr bool can_memcpy = std::is_trivial<T>::value;

#if __cpp_constexpr >= 201304L // non-const constexpr
constexpr T* get() noexcept {
return arrow::internal::launder(reinterpret_cast<T*>(&data_));
}
#else
T* get() noexcept { return arrow::internal::launder(reinterpret_cast<T*>(&data_)); }
#endif

constexpr const T* get() const noexcept {
// Use fully qualified name to avoid ambiguities with MSVC (ARROW-14800)
Expand Down
23 changes: 2 additions & 21 deletions cpp/src/arrow/util/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,14 @@
// This macro takes an optional deprecation message
#ifdef __COVERITY__
# define ARROW_DEPRECATED(...)
# define ARROW_DEPRECATED_USING(...)
#elif __cplusplus > 201103L
# define ARROW_DEPRECATED(...) [[deprecated(__VA_ARGS__)]]
# define ARROW_DEPRECATED_USING(...) ARROW_DEPRECATED(__VA_ARGS__)
#else
# ifdef __GNUC__
# define ARROW_DEPRECATED(...) __attribute__((deprecated(__VA_ARGS__)))
# define ARROW_DEPRECATED_USING(...) ARROW_DEPRECATED(__VA_ARGS__)
# elif defined(_MSC_VER)
# define ARROW_DEPRECATED(...) __declspec(deprecated(__VA_ARGS__))
# define ARROW_DEPRECATED_USING(...)
# else
# define ARROW_DEPRECATED(...)
# define ARROW_DEPRECATED_USING(...)
# endif
# define ARROW_DEPRECATED(...) [[deprecated(__VA_ARGS__)]]
#endif

#ifdef __COVERITY__
# define ARROW_DEPRECATED_ENUM_VALUE(...)
#elif __cplusplus > 201103L
# define ARROW_DEPRECATED_ENUM_VALUE(...) [[deprecated(__VA_ARGS__)]]
#else
# if defined(__GNUC__) && __GNUC__ >= 6
# define ARROW_DEPRECATED_ENUM_VALUE(...) __attribute__((deprecated(__VA_ARGS__)))
# else
# define ARROW_DEPRECATED_ENUM_VALUE(...)
# endif
# define ARROW_DEPRECATED_ENUM_VALUE(...) [[deprecated(__VA_ARGS__)]]
#endif

// clang-format on
Expand Down
8 changes: 0 additions & 8 deletions cpp/src/arrow/util/small_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ struct StaticVectorStorage : public StaticVectorStorageBase<T, N, D> {

StaticVectorStorage() noexcept = default;

#if __cpp_constexpr >= 201304L // non-const constexpr
constexpr storage_type* storage_ptr() { return static_data_; }
#else
storage_type* storage_ptr() { return static_data_; }
#endif

constexpr const storage_type* const_storage_ptr() const { return static_data_; }

Expand Down Expand Up @@ -124,11 +120,7 @@ struct SmallVectorStorage {

~SmallVectorStorage() { destroy(); }

#if __cpp_constexpr >= 201304L // non-const constexpr
constexpr storage_type* storage_ptr() { return data_; }
#else
storage_type* storage_ptr() { return data_; }
#endif

constexpr const storage_type* const_storage_ptr() const { return data_; }

Expand Down

0 comments on commit 7e3a408

Please sign in to comment.