Skip to content

Commit

Permalink
typename -> class to match my personal style
Browse files Browse the repository at this point in the history
using std::xxx_v<T> over std::xxx<T>::value
using std::xxx_t<T> over typename std::xxx<T>::type
using c++17 syntax for nested namespaces where appropriate
improve analysis slightly
  • Loading branch information
eteran committed Mar 20, 2024
1 parent 3d69447 commit 39c6112
Show file tree
Hide file tree
Showing 27 changed files with 197 additions and 197 deletions.
2 changes: 1 addition & 1 deletion include/FloatX.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ constexpr int max_printed_length() {

constexpr bool isInteger = Limits::is_integer;
constexpr int mantissaChars = isInteger ? 1 + Limits::digits10 : Limits::max_digits10;
constexpr int signChars = std::is_signed<T>::value;
constexpr int signChars = std::is_signed_v<T>;
constexpr int expSignChars = !isInteger;
constexpr int decimalPointChars = !isInteger;
constexpr int expSymbol = !isInteger; // 'e' for floating-point value in scientific format
Expand Down
24 changes: 12 additions & 12 deletions include/IProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ class IProcess {

public:
// only legal to call when attached
[[nodiscard]] virtual bool isPaused() const = 0;
[[nodiscard]] virtual QList<std::shared_ptr<IThread>> threads() const = 0;
[[nodiscard]] virtual std::shared_ptr<IThread> currentThread() const = 0;
[[nodiscard]] virtual std::size_t readBytes(edb::address_t address, void *buf, size_t len) const = 0;
[[nodiscard]] virtual std::size_t readPages(edb::address_t address, void *buf, size_t count) const = 0;
[[nodiscard]] virtual QMap<edb::address_t, Patch> patches() const = 0;
virtual Status pause() = 0;
virtual Status resume(edb::EventStatus status) = 0;
virtual Status step(edb::EventStatus status) = 0;
virtual std::size_t patchBytes(edb::address_t address, const void *buf, size_t len) = 0;
virtual std::size_t writeBytes(edb::address_t address, const void *buf, size_t len) = 0;
virtual void setCurrentThread(IThread &thread) = 0;
[[nodiscard]] virtual bool isPaused() const = 0;
[[nodiscard]] virtual QList<std::shared_ptr<IThread>> threads() const = 0;
[[nodiscard]] virtual QMap<edb::address_t, Patch> patches() const = 0;
[[nodiscard]] virtual std::shared_ptr<IThread> currentThread() const = 0;
virtual Status pause() = 0;
virtual Status resume(edb::EventStatus status) = 0;
virtual Status step(edb::EventStatus status) = 0;
virtual std::size_t patchBytes(edb::address_t address, const void *buf, size_t len) = 0;
virtual std::size_t readBytes(edb::address_t address, void *buf, size_t len) const = 0;
virtual std::size_t readPages(edb::address_t address, void *buf, size_t count) const = 0;
virtual std::size_t writeBytes(edb::address_t address, const void *buf, size_t len) = 0;
virtual void setCurrentThread(IThread &thread) = 0;
};

#endif
8 changes: 4 additions & 4 deletions include/Register.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EDB_EXPORT Register {

void setScalarValue(std::uint64_t newValue);

template <typename T>
template <class T>
void setValueFrom(const T &source) {
assert(bitSize_ <= 8 * sizeof(source));

Expand All @@ -105,11 +105,11 @@ class EDB_EXPORT Register {
Type type_ = TYPE_INVALID;
std::size_t bitSize_ = 0;

template <std::size_t bitSize, typename T>
template <std::size_t bitSize, class T>
friend Register make_Register(const QString &name, T value, Register::Type type);
};

template <std::size_t BitSize, typename T>
template <std::size_t BitSize, class T>
Register make_Register(const QString &name, T value, Register::Type type) {

constexpr std::size_t bitSize = (BitSize ? BitSize : 8 * sizeof(T));
Expand All @@ -133,7 +133,7 @@ Register make_Register(const QString &name, T value, Register::Type type) {
return reg;
}

template <typename T>
template <class T>
Register make_Register(const QString &name, T value, Register::Type type) {
return make_Register<0>(name, value, type);
}
Expand Down
4 changes: 2 additions & 2 deletions include/RegisterViewModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class EDB_EXPORT Model : public QAbstractItemModel {
};

inline std::ostream &operator<<(std::ostream &os, Model::ElementSize size) {
os << static_cast<std::underlying_type<Model::ElementSize>::type>(size);
os << static_cast<std::underlying_type_t<Model::ElementSize>>(size);
return os;
}

Expand Down Expand Up @@ -535,7 +535,7 @@ class CategoriesHolder final : public RegisterViewItem {
CategoriesHolder();

public:
template <typename CategoryType = Category>
template <class CategoryType = Category>
CategoryType *insert(const QString &name);

[[nodiscard]] SIMDCategory *insertSimd(const QString &name, const std::vector<NumberDisplayMode> &validFormats);
Expand Down
10 changes: 5 additions & 5 deletions include/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Unexpected {
friend class Result;

template <class U>
friend Unexpected<typename std::decay<U>::type> make_unexpected(U &&);
friend Unexpected<std::decay_t<U>> make_unexpected(U &&);

public:
Unexpected(const Unexpected &) = default;
Expand All @@ -69,7 +69,7 @@ class Unexpected {
Unexpected &operator=(Unexpected &&) = default;

private:
template <class U, class = typename std::enable_if<!std::is_same<U, Unexpected>::value && std::is_convertible<U, E>::value>::type>
template <class U, class = std::enable_if_t<!std::is_same_v<U, Unexpected> && std::is_convertible_v<U, E>>>
Unexpected(U &&error)
: error_(std::forward<U>(error)) {
}
Expand All @@ -81,7 +81,7 @@ class Unexpected {
template <class T, class E>
class Result {
public:
template <class U, class = typename std::enable_if<!std::is_same<U, Result>::value && std::is_convertible<U, T>::value>::type>
template <class U, class = std::enable_if_t<!std::is_same_v<U, Result> && std::is_convertible_v<U, T>>>
Result(U &&value)
: value_(std::forward<U>(value)) {
}
Expand Down Expand Up @@ -159,8 +159,8 @@ class Result<void, E> {
};

template <class E>
Unexpected<typename std::decay<E>::type> make_unexpected(E &&e) {
return Unexpected<typename std::decay<E>::type>(std::forward<E>(e));
Unexpected<std::decay_t<E>> make_unexpected(E &&e) {
return Unexpected<std::decay_t<E>>(std::forward<E>(e));
}

#endif
2 changes: 1 addition & 1 deletion include/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace util {

// Used to interconvert between abstract enum defined in an interface and actual enumerators in implementation
template <typename AbstractEnum, typename ConcreteEnum>
template <class AbstractEnum, class ConcreteEnum>
class AbstractEnumData {
AbstractEnum data;

Expand Down
61 changes: 30 additions & 31 deletions include/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#define VALUE_H_20191119_

#include "API.h"
#include <array>
#include <cinttypes>
#include <cstdint>
#include <cstring>
Expand All @@ -27,13 +26,13 @@ EDB_EXPORT bool debuggeeIs32Bit();
namespace detail {

template <class Integer>
using IsInteger = typename std::enable_if<std::is_integral<Integer>::value>::type;
using IsInteger = std::enable_if_t<std::is_integral_v<Integer>>;

template <class T1, class T2>
using PromoteType = typename std::conditional<
using PromoteType = std::conditional_t<
sizeof(T1) >= sizeof(T2),
typename std::make_unsigned<T1>::type,
typename std::make_unsigned<T2>::type>::type;
std::make_unsigned_t<T1>,
std::make_unsigned_t<T2>>;

template <size_t N>
class value_type_large {
Expand All @@ -50,11 +49,11 @@ class value_type_large {
~value_type_large() = default;

public:
template <class U, class = typename std::enable_if<!std::is_arithmetic<U>::value>::type>
template <class U, class = std::enable_if_t<!std::is_arithmetic_v<U>>>
explicit value_type_large(const U &data, size_t offset = 0) {

static_assert(sizeof(data) >= sizeof(T), "value_type can only be constructed from large enough variable");
static_assert(std::is_trivially_copyable<U>::value, "value_type can only be constructed from trivially copyable data");
static_assert(std::is_trivially_copyable_v<U>, "value_type can only be constructed from trivially copyable data");

Q_ASSERT(sizeof(data) - offset >= sizeof(T)); // check bounds, this can't be done at compile time

Expand Down Expand Up @@ -152,11 +151,11 @@ class value_type {
}

public:
template <class U, class = typename std::enable_if<!std::is_arithmetic<U>::value>::type>
template <class U, class = std::enable_if_t<!std::is_arithmetic_v<U>>>
explicit value_type(const U &data, size_t offset = 0) {

static_assert(sizeof(data) >= sizeof(T), "value_type can only be constructed from large enough variable");
static_assert(std::is_trivially_copyable<U>::value, "value_type can only be constructed from trivially copyable data");
static_assert(std::is_trivially_copyable_v<U>, "value_type can only be constructed from trivially copyable data");

Q_ASSERT(sizeof(data) - offset >= sizeof(T)); // check bounds, this can't be done at compile time

Expand Down Expand Up @@ -228,7 +227,7 @@ class value_type {

public:
[[nodiscard]] bool negative() const {
return typename std::make_signed<T>::type(value_) < 0;
return std::make_signed_t<T>(value_) < 0;
}

public:
Expand Down Expand Up @@ -409,7 +408,7 @@ class value_type {
}

[[nodiscard]] QString signedToString() const {
return QStringLiteral("%1").arg(typename std::make_signed<T>::type(value_));
return QStringLiteral("%1").arg(std::make_signed_t<T>(value_));
}

[[nodiscard]] QString toString() const {
Expand Down Expand Up @@ -467,13 +466,13 @@ std::ostream &operator<<(std::ostream &os, value_type<T> &val) {
// operators for value_type, Integer
template <class T, class Integer, class = IsInteger<Integer>>
[[nodiscard]] bool operator==(const value_type<T> &lhs, Integer rhs) {
using U = typename std::make_unsigned<Integer>::type;
using U = std::make_unsigned_t<Integer>;
return lhs.value_ == static_cast<U>(rhs);
}

template <class T, class Integer, class = IsInteger<Integer>>
[[nodiscard]] bool operator!=(const value_type<T> &lhs, Integer rhs) {
using U = typename std::make_unsigned<Integer>::type;
using U = std::make_unsigned_t<Integer>;
return lhs.value_ != static_cast<U>(rhs);
}

Expand Down Expand Up @@ -766,7 +765,7 @@ struct value_type80 {
template <class U>
explicit value_type80(const U &data, size_t offset = 0) {
#ifdef _MSC_VER
if constexpr (std::is_same<U, long double>::value && sizeof(U) < sizeof(T)) {
if constexpr (std::is_same_v<U, long double> && sizeof(U) < sizeof(T)) {
T temp;
convert_real64_to_real80(&data, &temp);

Expand All @@ -779,7 +778,7 @@ struct value_type80 {
#else
static_assert(sizeof(data) >= sizeof(T), "ValueBase can only be constructed from large enough variable");
#endif
static_assert(std::is_trivially_copyable<U>::value, "ValueBase can only be constructed from trivially copyable data");
static_assert(std::is_trivially_copyable_v<U>, "ValueBase can only be constructed from trivially copyable data");

Q_ASSERT(sizeof(data) - offset >= sizeof(T)); // check bounds, this can't be done at compile time

Expand Down Expand Up @@ -874,24 +873,24 @@ using value256 = detail::value_type_large<256>;
// AVX512
using value512 = detail::value_type_large<512>;

static_assert(std::is_standard_layout<value8>::value &&
std::is_standard_layout<value16>::value &&
std::is_standard_layout<value32>::value &&
std::is_standard_layout<value64>::value &&
std::is_standard_layout<value80>::value &&
std::is_standard_layout<value128>::value &&
std::is_standard_layout<value256>::value &&
std::is_standard_layout<value512>::value,
static_assert(std::is_standard_layout_v<value8> &&
std::is_standard_layout_v<value16> &&
std::is_standard_layout_v<value32> &&
std::is_standard_layout_v<value64> &&
std::is_standard_layout_v<value80> &&
std::is_standard_layout_v<value128> &&
std::is_standard_layout_v<value256> &&
std::is_standard_layout_v<value512>,
"Fixed-sized values are intended to have standard layout");

static_assert(std::is_trivially_copyable<value8>::value &&
std::is_trivially_copyable<value16>::value &&
std::is_trivially_copyable<value32>::value &&
std::is_trivially_copyable<value64>::value &&
std::is_trivially_copyable<value80>::value &&
std::is_trivially_copyable<value128>::value &&
std::is_trivially_copyable<value256>::value &&
std::is_trivially_copyable<value512>::value,
static_assert(std::is_trivially_copyable_v<value8> &&
std::is_trivially_copyable_v<value16> &&
std::is_trivially_copyable_v<value32> &&
std::is_trivially_copyable_v<value64> &&
std::is_trivially_copyable_v<value80> &&
std::is_trivially_copyable_v<value128> &&
std::is_trivially_copyable_v<value256> &&
std::is_trivially_copyable_v<value512>,
"Fixed-sized values are intended to be trivially copyable");

}
Expand Down
4 changes: 1 addition & 3 deletions include/os/unix/linux/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LINKER_H_20170103_
#define LINKER_H_20170103_

namespace edb {
namespace linux_struct {
namespace edb::linux_struct {

// Bitness-templated version of struct r_debug defined in link.h
template <class Addr>
Expand All @@ -45,7 +44,6 @@ struct link_map {
Addr l_next, l_prev; // struct link_map*
};

}
}

#endif
6 changes: 3 additions & 3 deletions include/string_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ namespace edb {
namespace detail {

template <std::size_t N, std::size_t n>
constexpr typename std::enable_if<N <= 9 && n == 0, uint64_t>::type string_hash(const char (&)[N]) {
constexpr std::enable_if_t<N <= 9 && n == 0, uint64_t> string_hash(const char (&)[N]) {
return 0;
}

template <std::size_t N, std::size_t n = N - 1>
constexpr typename std::enable_if<N <= 9 && n != 0, uint64_t>::type string_hash(const char (&array)[N]) {
constexpr std::enable_if_t<N <= 9 && n != 0, uint64_t> string_hash(const char (&array)[N]) {
return string_hash<N, n - 1>(array) | ((array[n - 1] & 0xffull) << (8 * (n - 1)));
}

}

template <std::size_t N>
constexpr typename std::enable_if<N <= 9, uint64_t>::type string_hash(const char (&array)[N]) {
constexpr std::enable_if_t<N <= 9, uint64_t> string_hash(const char (&array)[N]) {
return detail::string_hash(array);
}

Expand Down
10 changes: 5 additions & 5 deletions include/util/Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ namespace util {

template <class T, size_t N, class U = T>
constexpr void shl(std::array<T, N> &buffer, U value = T()) {
static_assert(std::is_convertible<T, U>::value, "U must be convertible to the type contained in the array!");
static_assert(std::is_convertible_v<T, U>, "U must be convertible to the type contained in the array!");
std::rotate(buffer.begin(), buffer.begin() + 1, buffer.end());
buffer[N - 1] = value;
}

template <class T, size_t N, class U = T>
constexpr void shr(std::array<T, N> &buffer, U value = T()) {
static_assert(std::is_convertible<T, U>::value, "U must be convertible to the type contained in the array!");
static_assert(std::is_convertible_v<T, U>, "U must be convertible to the type contained in the array!");
std::rotate(buffer.rbegin(), buffer.rbegin() + 1, buffer.rend());
buffer[0] = value;
}
Expand All @@ -32,17 +32,17 @@ constexpr void ror(std::array<T, N> &buffer) {
std::rotate(buffer.rbegin(), buffer.rbegin() + 1, buffer.rend());
}

template <typename T, typename... Tail>
template <class T, class... Tail>
constexpr auto make_array(T head, Tail... tail) -> std::array<T, 1 + sizeof...(Tail)> {
return std::array<T, 1 + sizeof...(Tail)>{head, tail...};
}

template <typename Container, typename Element>
template <class Container, class Element>
bool contains(const Container &container, const Element &element) {
return std::find(std::begin(container), std::end(container), element) != std::end(container);
}

template <typename Container, typename Pred>
template <class Container, class Pred>
bool contains_if(const Container &container, Pred pred) {
return std::find_if(std::begin(container), std::end(container), pred) != std::end(container);
}
Expand Down
14 changes: 7 additions & 7 deletions include/util/Float.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace util {

template <typename Float>
template <class Float>
std::optional<Float> full_string_to_float(const std::string &s) {

static_assert(
std::is_same<Float, float>::value ||
std::is_same<Float, double>::value ||
std::is_same<Float, long double>::value,
std::is_same_v<Float, float> ||
std::is_same_v<Float, double> ||
std::is_same_v<Float, long double>,
"Floating-point type not supported by this function");

// NOTE: Don't use std::istringstream: it doesn't support hexfloat.
Expand All @@ -27,11 +27,11 @@ std::optional<Float> full_string_to_float(const std::string &s) {
Float value;
errno = 0;

if constexpr (std::is_same<Float, float>::value) {
if constexpr (std::is_same_v<Float, float>) {
value = std::strtof(str, &end);
} else if constexpr (std::is_same<Float, double>::value) {
} else if constexpr (std::is_same_v<Float, double>) {
value = std::strtod(str, &end);
} else if constexpr (std::is_same<Float, long double>::value) {
} else if constexpr (std::is_same_v<Float, long double>) {
value = std::strtold(str, &end);
}

Expand Down
Loading

0 comments on commit 39c6112

Please sign in to comment.