Skip to content

Commit

Permalink
Use is_trivially_copyable and is_standard_layout instead of deprecate…
Browse files Browse the repository at this point in the history
…d std::is_pod in C++20
  • Loading branch information
mogemimi committed Oct 1, 2020
1 parent f8be047 commit daa4917
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
12 changes: 8 additions & 4 deletions include/Pomdog/Content/Utility/BinaryReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct POMDOG_EXPORT BinaryReader final {
template <typename T, class Stream>
static std::vector<T> ReadArray(Stream& stream, std::size_t elementCount)
{
static_assert(std::is_pod<T>::value, "You can only use POD types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use POD types.");
static_assert(std::is_standard_layout_v<T>, "You can only use POD types.");

POMDOG_ASSERT(stream);
POMDOG_ASSERT(elementCount > 0);
Expand All @@ -32,7 +33,8 @@ struct POMDOG_EXPORT BinaryReader final {
template <typename T, std::size_t ElementCount, class Stream>
static std::array<T, ElementCount> ReadArray(Stream& stream)
{
static_assert(std::is_pod<T>::value, "You can only use POD types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use POD types.");
static_assert(std::is_standard_layout_v<T>, "You can only use POD types.");
POMDOG_ASSERT(stream);

std::array<T, ElementCount> result;
Expand All @@ -44,7 +46,8 @@ struct POMDOG_EXPORT BinaryReader final {
static T Read(Stream& stream)
{
POMDOG_ASSERT(stream);
static_assert(std::is_pod<T>::value, "You can only use POD types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use POD types.");
static_assert(std::is_standard_layout_v<T>, "You can only use POD types.");
return std::move(ReadArray<T, 1>(stream)[0]);
}

Expand All @@ -58,7 +61,8 @@ struct POMDOG_EXPORT BinaryReader final {
static T Read(const std::uint8_t* data)
{
POMDOG_ASSERT(data);
static_assert(std::is_pod<T>::value, "You can only use POD types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use POD types.");
static_assert(std::is_standard_layout_v<T>, "You can only use POD types.");
T value;
std::memcpy(&value, data, sizeof(value));
return value;
Expand Down
9 changes: 6 additions & 3 deletions include/Pomdog/Graphics/ConstantBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class POMDOG_EXPORT ConstantBuffer final {
template <typename T>
T GetValue() const
{
static_assert(std::is_pod<T>::value, "You can only use plain-old-data types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");
T result;
Detail::EffectBinaryParameter::Get<T>(*this, result);
return std::move(result);
Expand All @@ -59,15 +60,17 @@ class POMDOG_EXPORT ConstantBuffer final {
template <typename T>
void SetValue(const T& value)
{
static_assert(std::is_pod<T>::value, "You can only use plain-old-data types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");
Detail::EffectBinaryParameter::Set(*this, value);
}

/// Sets constant buffer data.
template <typename T>
void SetValue(const T* data, std::size_t count)
{
static_assert(std::is_pod<T>::value, "You can only use plain-old-data types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");
Detail::EffectBinaryParameter::Set(*this, data, count);
}

Expand Down
3 changes: 2 additions & 1 deletion include/Pomdog/Graphics/RenderTarget2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class POMDOG_EXPORT RenderTarget2D final : public Texture {
template <typename T>
void GetData(T* result, std::size_t startIndex, std::size_t elementCount) const
{
static_assert(std::is_pod_v<T>, "You can only use plain-old-data types.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");
static_assert(!std::is_void_v<T>);
this->GetData(static_cast<void*>(result), sizeof(T) * startIndex, sizeof(T) * elementCount);
}
Expand Down
6 changes: 4 additions & 2 deletions include/Pomdog/Graphics/detail/EffectBinaryParameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ void POMDOG_EXPORT Get(const ConstantBuffer& constantBuffer, double& result);
template <class T, class ConstantBuffer>
void Get(const ConstantBuffer& constantBuffer, T& result)
{
static_assert(std::is_pod<T>::value, "You can only use POD value.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use POD value.");
static_assert(std::is_standard_layout_v<T>, "You can only use POD value.");
constantBuffer.GetValue(sizeof(result), static_cast<void*>(&result));
}

Expand All @@ -48,7 +49,8 @@ template <typename T> void POMDOG_EXPORT Set(ConstantBuffer & constantBuffer, co
template <class T, class ConstantBuffer>
void Set(ConstantBuffer& constantBuffer, const T& value)
{
static_assert(std::is_pod<T>::value, "You can only use POD value.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use POD value.");
static_assert(std::is_standard_layout_v<T>, "You can only use POD value.");
constantBuffer.SetValue(static_cast<const void*>(&value), sizeof(value));
}

Expand Down
3 changes: 2 additions & 1 deletion include/Pomdog/Math/detail/TaggedArithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ template <typename T, class PhantomType>
class POMDOG_EXPORT TaggedArithmetic final {
public:
static_assert(std::is_arithmetic<T>::value, "T is arithmetic type.");
static_assert(std::is_pod<T>::value, "T is pod type.");
static_assert(std::is_trivially_copyable_v<T>, "You can only use POD type.");
static_assert(std::is_standard_layout_v<T>, "You can only use POD type.");

T value;

Expand Down
6 changes: 4 additions & 2 deletions src/Utility/Tagged.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Pomdog::Detail {
template <typename T, class Tag>
class POMDOG_EXPORT Tagged final {
public:
static_assert(std::is_pod<T>::value, "You can only use plain-old-data types");
static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");

typedef T value_type;
typedef Tag tag_type;
Expand Down Expand Up @@ -61,7 +62,8 @@ class POMDOG_EXPORT Tagged final {
template <typename T, class Tag, class... Arguments>
Tagged<T, Tag> MakeTagged(Arguments&&... arguments)
{
static_assert(std::is_pod<T>::value, "You can only use plain-old-data types");
static_assert(std::is_trivially_copyable_v<T>, "You can only use plain-old-data types.");
static_assert(std::is_standard_layout_v<T>, "You can only use plain-old-data types.");
return Tagged<T, Tag>(std::forward<T>(arguments)...);
}

Expand Down

0 comments on commit daa4917

Please sign in to comment.