Skip to content

Commit

Permalink
Make headers compatible with C++11
Browse files Browse the repository at this point in the history
Remove is_signed_v and CTAD for std::array as they are in C++17

Remove remove_cv_t, remove_pointer_t, and make_unsigned_t as they are in
C++14

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jul 24, 2022
1 parent 9ca7f86 commit 02b0ff3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions include/exiv2/photoshop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class IptcData;
/// @brief Helper class, has methods to deal with %Photoshop "Information Resource Blocks" (IRBs).
struct EXIV2API Photoshop {
// Todo: Public for now
static constexpr std::array irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; //!< %Photoshop IRB markers
static constexpr auto ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker
static constexpr uint16_t iptc_ = 0x0404; //!< %Photoshop IPTC marker
static constexpr uint16_t preview_ = 0x040c; //!< %Photoshop preview marker
static constexpr std::array<const char*, 4> irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; //!< %Photoshop IRB markers
static constexpr auto ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker
static constexpr uint16_t iptc_ = 0x0404; //!< %Photoshop IPTC marker
static constexpr uint16_t preview_ = 0x040c; //!< %Photoshop preview marker

/// @brief Checks an IRB
/// @param pPsData Existing IRB buffer. It is expected to be of size 4.
Expand Down
8 changes: 4 additions & 4 deletions include/exiv2/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ struct ContainerStorage {

using const_iterator = typename container::const_iterator;

using value_type = std::remove_cv_t<typename container::value_type>;
using value_type = typename std::remove_cv<typename container::value_type>::type;

/*!
* @throw std::out_of_range when end is larger than the container's
Expand Down Expand Up @@ -324,7 +324,7 @@ struct ContainerStorage {
*/
template <typename storage_type>
struct PtrSliceStorage {
using value_type = std::remove_cv_t<std::remove_pointer_t<storage_type>>;
using value_type = typename std::remove_cv<typename std::remove_pointer<storage_type>::type>::type;
using iterator = value_type*;
using const_iterator = const value_type*;

Expand Down Expand Up @@ -423,7 +423,7 @@ struct Slice : public Internal::MutableSliceBase<Internal::ContainerStorage, con

using const_iterator = typename container::const_iterator;

using value_type = std::remove_cv_t<typename container::value_type>;
using value_type = typename std::remove_cv<typename container::value_type>::type;

/*!
* @brief Construct a slice of the container `cont` starting at `begin`
Expand Down Expand Up @@ -476,7 +476,7 @@ struct Slice<const container> : public Internal::ConstSliceBase<Internal::Contai

using const_iterator = typename container::const_iterator;

using value_type = std::remove_cv_t<typename container::value_type>;
using value_type = typename std::remove_cv<typename container::value_type>::type;

Slice(const container& cont, size_t begin, size_t end) :
Internal::ConstSliceBase<Internal::ContainerStorage, const container>(cont, begin, end) {
Expand Down
13 changes: 7 additions & 6 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,24 +1261,25 @@ class ValueType : public Value {
//! Utility for toInt64, toUint32, etc.
template <typename I>
inline I rational_to_integer_helper(size_t n) const {
auto&& [a, b] = value_.at(n);
auto a = value_.at(n).first;
auto b = value_.at(n).second;

// Protect against divide-by-zero.
if (b <= 0) {
return 0;
}

// Check for integer overflow.
if (std::is_signed_v<I> == std::is_signed_v<decltype(a)>) {
if (std::is_signed<I>::value == std::is_signed<decltype(a)>::value) {
// conversion does not change sign
const auto imin = std::numeric_limits<I>::min();
const auto imax = std::numeric_limits<I>::max();
if (imax < b || a < imin || imax < a) {
return 0;
}
} else if (std::is_signed_v<I>) {
} else if (std::is_signed<I>::value) {
// conversion is from unsigned to signed
const auto imax = std::make_unsigned_t<I>(std::numeric_limits<I>::max());
const auto imax = typename std::make_unsigned<I>::type(std::numeric_limits<I>::max());
if (imax < b || imax < a) {
return 0;
}
Expand All @@ -1289,8 +1290,8 @@ class ValueType : public Value {
return 0;
}
// Inputs are not negative so convert them to unsigned.
const auto a_u = std::make_unsigned_t<decltype(a)>(a);
const auto b_u = std::make_unsigned_t<decltype(b)>(b);
const auto a_u = typename std::make_unsigned<decltype(a)>::type(a);
const auto b_u = typename std::make_unsigned<decltype(b)>::type(b);
if (imax < b_u || imax < a_u) {
return 0;
}
Expand Down

0 comments on commit 02b0ff3

Please sign in to comment.