mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-26 12:35:32 +00:00
Refactor ranges
This commit is contained in:
parent
c2e84ee9cc
commit
83174f2a1f
@ -212,7 +212,7 @@ inline Dest bit_cast(const Source& source) {
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An implementation of iterator_t for pre-C++20 systems.
|
// An approximation of iterator_t for pre-C++20 systems.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using iterator_t = decltype(std::begin(std::declval<T&>()));
|
using iterator_t = decltype(std::begin(std::declval<T&>()));
|
||||||
|
|
||||||
@ -220,26 +220,11 @@ using iterator_t = decltype(std::begin(std::declval<T&>()));
|
|||||||
# define FMT_USE_GRISU 1
|
# define FMT_USE_GRISU 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename T> inline bool use_grisu() {
|
template <typename T> constexpr bool use_grisu() {
|
||||||
return FMT_USE_GRISU && std::numeric_limits<double>::is_iec559 &&
|
return FMT_USE_GRISU && std::numeric_limits<double>::is_iec559 &&
|
||||||
sizeof(T) <= sizeof(double);
|
sizeof(T) <= sizeof(double);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A range with an iterator appending to a buffer.
|
|
||||||
template <typename T> class buffer_range {
|
|
||||||
public:
|
|
||||||
using value_type = T;
|
|
||||||
using iterator = std::back_insert_iterator<buffer<T>>;
|
|
||||||
|
|
||||||
private:
|
|
||||||
iterator begin_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
buffer_range(buffer<T>& buf) : begin_(std::back_inserter(buf)) {}
|
|
||||||
explicit buffer_range(iterator it) : begin_(it) {}
|
|
||||||
iterator begin() const { return begin_; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// A range with the specified output iterator and value type.
|
// A range with the specified output iterator and value type.
|
||||||
template <typename OutputIt, typename T = typename OutputIt::value_type>
|
template <typename OutputIt, typename T = typename OutputIt::value_type>
|
||||||
class output_range {
|
class output_range {
|
||||||
@ -249,9 +234,22 @@ class output_range {
|
|||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
using iterator = OutputIt;
|
using iterator = OutputIt;
|
||||||
|
struct sentinel {};
|
||||||
|
|
||||||
explicit output_range(OutputIt it) : it_(it) {}
|
explicit output_range(OutputIt it) : it_(it) {}
|
||||||
OutputIt begin() const { return it_; }
|
OutputIt begin() const { return it_; }
|
||||||
|
sentinel end() const { return {}; } // Sentinel is not used yet.
|
||||||
|
};
|
||||||
|
|
||||||
|
// A range with an iterator appending to a buffer.
|
||||||
|
template <typename T>
|
||||||
|
class buffer_range
|
||||||
|
: public output_range<std::back_insert_iterator<buffer<T>>, T> {
|
||||||
|
public:
|
||||||
|
using iterator = std::back_insert_iterator<buffer<T>>;
|
||||||
|
using output_range<iterator, T>::output_range;
|
||||||
|
buffer_range(buffer<T>& buf)
|
||||||
|
: output_range<iterator, T>(std::back_inserter(buf)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _SECURE_SCL
|
#ifdef _SECURE_SCL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user