Browse Source

Remove C++11 compatibility code

pull/6458/head
Gleb Mazovetskiy 3 years ago committed by Anders Jenbo
parent
commit
2f1290c5d2
  1. 26
      Source/engine.h
  2. 12
      Source/utils/static_vector.hpp
  3. 12
      Source/utils/stdcompat/abs.hpp
  4. 10
      Source/utils/stdcompat/algorithm.hpp
  5. 11
      Source/utils/stdcompat/cstddef.hpp
  6. 21
      Source/utils/stdcompat/invoke_result_t.hpp
  7. 13
      Source/utils/stdcompat/optional.hpp
  8. 24
      Source/utils/stdcompat/string_view.hpp
  9. 19
      Source/utils/str_cat.hpp

26
Source/engine.h

@ -43,7 +43,6 @@
namespace devilution {
#if __cplusplus >= 201703L
template <typename V, typename X, typename... Xs>
constexpr bool IsAnyOf(const V &v, X x, Xs... xs)
{
@ -55,31 +54,6 @@ constexpr bool IsNoneOf(const V &v, X x, Xs... xs)
{
return v != x && ((v != xs) && ...);
}
#else
template <typename V, typename X>
constexpr bool IsAnyOf(const V &v, X x)
{
return v == x;
}
template <typename V, typename X, typename... Xs>
constexpr bool IsAnyOf(const V &v, X x, Xs... xs)
{
return IsAnyOf(v, x) || IsAnyOf(v, xs...);
}
template <typename V, typename X>
constexpr bool IsNoneOf(const V &v, X x)
{
return v != x;
}
template <typename V, typename X, typename... Xs>
constexpr bool IsNoneOf(const V &v, X x, Xs... xs)
{
return IsNoneOf(v, x) && IsNoneOf(v, xs...);
}
#endif
/**
* @brief Draw a horizontal line segment in the target buffer (left to right)

12
Source/utils/static_vector.hpp

@ -73,11 +73,7 @@ public:
~StaticVector()
{
for (std::size_t pos = 0; pos < size_; ++pos) {
#if __cplusplus >= 201703L
std::destroy_at(data_[pos].ptr());
#else
data_[pos].ptr()->~T();
#endif
}
}
@ -87,20 +83,12 @@ private:
const T *ptr() const
{
#if __cplusplus >= 201703L
return std::launder(reinterpret_cast<const T *>(data));
#else
return reinterpret_cast<const T *>(data);
#endif
}
T *ptr()
{
#if __cplusplus >= 201703L
return std::launder(reinterpret_cast<T *>(data));
#else
return reinterpret_cast<T *>(data);
#endif
}
};
AlignedStorage data_[N];

12
Source/utils/stdcompat/abs.hpp

@ -3,15 +3,5 @@
#include <cstdlib>
namespace devilution {
template <typename T>
constexpr T abs(const T &a)
{
#if defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER)
return std::abs(a);
#else
return (a < 0) ? -a : a;
#endif
}
using ::std::abs;
} // namespace devilution

10
Source/utils/stdcompat/algorithm.hpp

@ -3,13 +3,5 @@
#include <algorithm> // IWYU pragma: export
namespace devilution {
#if defined(__cplusplus) && __cplusplus >= 201703L
using std::clamp; // NOLINT(misc-unused-using-decls)
#else
template <typename T>
constexpr const T &clamp(const T &x, const T &lower, const T &upper)
{
return std::min(std::max(x, lower), upper);
}
#endif
using ::std::clamp;
} // namespace devilution

11
Source/utils/stdcompat/cstddef.hpp

@ -2,13 +2,6 @@
#include <cstddef> // IWYU pragma: export
#if defined(__cplusplus) && __cplusplus >= 201703L
namespace devilution {
using byte = std::byte;
} // namespace devilution
#else
#include <cstdint>
namespace devilution {
using byte = std::uint8_t;
} // namespace devilution
#endif
using ::std::byte;
}

21
Source/utils/stdcompat/invoke_result_t.hpp

@ -1,14 +1,7 @@
#pragma once
#include <type_traits>
namespace devilution {
#if defined(__cplusplus) && __cplusplus >= 201703L
using std::invoke_result_t;
#else
template <typename F, typename... Args>
using invoke_result_t = typename std::result_of<F(Args...)>::type;
#endif
} // namespace devilution
#pragma once
#include <type_traits>
namespace devilution {
using ::std::invoke_result_t;
} // namespace devilution

13
Source/utils/stdcompat/optional.hpp

@ -1,16 +1,3 @@
#pragma once
#ifdef __has_include
#if defined(__cplusplus) && (__cplusplus >= 201606L || _MSC_VER >= 1930) && __has_include(<optional>)
#include <optional> // IWYU pragma: export
#elif __has_include(<experimental/optional>)
#include <experimental/optional> // IWYU pragma: export
#define optional experimental::optional
#define nullopt experimental::nullopt
#define nullopt_t experimental::nullopt_t
#else
#error "Missing support for <optional> or <experimental/optional>"
#endif
#else
#error "__has_include unavailable"
#endif

24
Source/utils/stdcompat/string_view.hpp

@ -1,34 +1,12 @@
#pragma once
#ifdef __has_include
#if defined(__cplusplus) && (__cplusplus >= 201703L || _MSC_VER >= 1930) && __has_include(<string_view>) // should be 201606L, but STL headers disagree
#include <string>
#include <string_view> // IWYU pragma: export
namespace devilution {
using string_view = std::string_view;
using ::std::string_view;
inline void AppendStrView(std::string &out, string_view str)
{
out.append(str);
}
} // namespace devilution
#elif __has_include(<experimental/string_view>)
#include <experimental/string_view> // IWYU pragma: export
namespace devilution {
using string_view = std::experimental::string_view;
inline void AppendStrView(std::string &out, string_view str)
{
out.append(str.data(), str.size());
}
} // namespace devilution
#else
#error "Missing support for <string_view> or <experimental/string_view>"
#endif
#else
#error "__has_include unavailable"
#endif

19
Source/utils/str_cat.hpp

@ -54,38 +54,19 @@ inline void StrAppend(std::string &out, const char *str)
AppendStrView(out, string_view(str != nullptr ? str : "(nullptr)"));
}
#if __cplusplus >= 201703L
template <typename... Args>
typename std::enable_if<(sizeof...(Args) > 1), char *>::type
BufCopy(char *out, Args &&...args)
{
return ((out = BufCopy(out, std::forward<Args>(args))), ...);
}
#else
template <typename Arg, typename... Args>
inline typename std::enable_if<(sizeof...(Args) > 0), char *>::type
BufCopy(char *out, Arg &&arg, Args &&...args)
{
return BufCopy(BufCopy(out, std::forward<Arg>(arg)), std::forward<Args>(args)...);
}
#endif
#if __cplusplus >= 201703L
template <typename... Args>
typename std::enable_if<(sizeof...(Args) > 1), void>::type
StrAppend(std::string &out, Args &&...args)
{
(StrAppend(out, std::forward<Args>(args)), ...);
}
#else
template <typename Arg, typename... Args>
typename std::enable_if<(sizeof...(Args) > 0), void>::type
StrAppend(std::string &out, Arg &&arg, Args &&...args)
{
StrAppend(out, std::forward<Arg>(arg));
StrAppend(out, std::forward<Args>(args)...);
}
#endif
template <typename... Args>
std::string StrCat(Args &&...args)

Loading…
Cancel
Save