Skip to content

Commit

Permalink
Enhance #952 based on the feedback from @yype
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Dec 17, 2023
1 parent e6d3f28 commit a900afb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions include/LIEF/iostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#ifndef LIEF_OSTREAM_H
#define LIEF_OSTREAM_H
#include <limits>
#include <istream>
#include <streambuf>
#include <cstdint>
Expand Down Expand Up @@ -52,8 +53,8 @@ class vector_iostream {
vector_iostream& write_sized_int(uint64_t value, size_t size);
vector_iostream& write(const vector_iostream& other);

template<class T, typename U = typename std::enable_if<!std::is_integral<T>::value>, T>
vector_iostream& write(const U& t) {
template<class T, typename std::enable_if<!std::numeric_limits<T>::is_integer, int>::type = 0>
vector_iostream& write(const T& t) {
const auto pos = static_cast<size_t>(tellp());
if (raw_.size() < (pos + sizeof(T))) {
raw_.resize(pos + sizeof(T));
Expand All @@ -71,7 +72,7 @@ class vector_iostream {

vector_iostream& align(size_t alignment, uint8_t fill = 0);

template<class Integer, typename = typename std::enable_if<std::is_integral<Integer>::value>>
template<class Integer, typename std::enable_if<std::numeric_limits<Integer>::is_integer, int>::type = 0>
vector_iostream& write(Integer integer) {
const auto pos = static_cast<size_t>(tellp());
if (raw_.size() < (pos + sizeof(Integer))) {
Expand All @@ -82,8 +83,9 @@ class vector_iostream {
return *this;
}

template<typename T, size_t size, typename = typename std::enable_if<std::is_integral<T>::value>>
template<typename T, size_t size>
vector_iostream& write(const std::array<T, size>& t) {
static_assert(std::numeric_limits<T>::is_integer, "Requires integer type");
for (T val : t) {
write<T>(val);
}
Expand Down

0 comments on commit a900afb

Please sign in to comment.