remove obsolete type traits
parent
ea6d3d4bbf
commit
c5dd6bb8c3
|
@ -781,7 +781,7 @@ struct MapRange: InputRange<
|
|||
> {
|
||||
private:
|
||||
T p_range;
|
||||
Decay<F> p_func;
|
||||
std::decay_t<F> p_func;
|
||||
|
||||
public:
|
||||
MapRange() = delete;
|
||||
|
@ -874,12 +874,12 @@ inline auto map(F &&func) {
|
|||
|
||||
template<typename T, typename F>
|
||||
struct FilterRange: InputRange<
|
||||
FilterRange<T, F>, CommonType<RangeCategory<T>, ForwardRangeTag>,
|
||||
FilterRange<T, F>, std::common_type_t<RangeCategory<T>, ForwardRangeTag>,
|
||||
RangeValue<T>, RangeReference<T>, RangeSize<T>
|
||||
> {
|
||||
private:
|
||||
T p_range;
|
||||
Decay<F> p_pred;
|
||||
std::decay_t<F> p_pred;
|
||||
|
||||
void advance_valid() {
|
||||
while (!p_range.empty() && !p_pred(front())) {
|
||||
|
@ -936,7 +936,7 @@ public:
|
|||
|
||||
namespace detail {
|
||||
template<typename R, typename P>
|
||||
using FilterPred = EnableIf<IsSame<
|
||||
using FilterPred = std::enable_if_t<std::is_same_v<
|
||||
decltype(std::declval<P>()(std::declval<RangeReference<R>>())), bool
|
||||
>, P>;
|
||||
}
|
||||
|
|
|
@ -112,7 +112,9 @@ namespace detail {
|
|||
/* retrieve width/precision */
|
||||
template<typename T>
|
||||
bool convert_arg_param(
|
||||
T const &val, int ¶m, EnableIf<IsIntegral<T>, bool> = true
|
||||
T const &val, int ¶m, std::enable_if_t<
|
||||
std::is_integral_v<T>, bool
|
||||
> = true
|
||||
) {
|
||||
param = int(val);
|
||||
return true;
|
||||
|
@ -120,7 +122,7 @@ namespace detail {
|
|||
|
||||
template<typename T>
|
||||
bool convert_arg_param(
|
||||
T const &, int &, EnableIf<!IsIntegral<T>, bool> = true
|
||||
T const &, int &, std::enable_if_t<!std::is_integral_v<T>, bool> = true
|
||||
) {
|
||||
assert(false && "invalid argument for width/precision");
|
||||
return false;
|
||||
|
@ -437,8 +439,8 @@ protected:
|
|||
/* for custom container formatting */
|
||||
|
||||
template<
|
||||
typename T, typename R, typename = EnableIf<
|
||||
IsSame<decltype(std::declval<T const &>().to_format(
|
||||
typename T, typename R, typename = std::enable_if_t<
|
||||
std::is_same_v<decltype(std::declval<T const &>().to_format(
|
||||
std::declval<R &>(), std::declval<FormatSpec const &>()
|
||||
)), bool>
|
||||
>
|
||||
|
@ -549,7 +551,7 @@ namespace detail {
|
|||
template<typename R, typename T>
|
||||
inline ptrdiff_t format_ritem(
|
||||
R &writer, size_t &fmtn, bool esc, bool, ConstCharRange fmt,
|
||||
T const &item, EnableIf<!is_tuple_like<T>, bool> = true
|
||||
T const &item, std::enable_if_t<!is_tuple_like<T>, bool> = true
|
||||
) {
|
||||
return format_impl(writer, fmtn, esc, fmt, item);
|
||||
}
|
||||
|
@ -557,7 +559,7 @@ namespace detail {
|
|||
template<typename R, typename T>
|
||||
inline ptrdiff_t format_ritem(
|
||||
R &writer, size_t &fmtn, bool esc, bool expandval, ConstCharRange fmt,
|
||||
T const &item, EnableIf<is_tuple_like<T>, bool> = true
|
||||
T const &item, std::enable_if_t<is_tuple_like<T>, bool> = true
|
||||
) {
|
||||
if (expandval) {
|
||||
return FmtTupleUnpacker<std::tuple_size<T>::value>::unpack(
|
||||
|
@ -570,7 +572,8 @@ namespace detail {
|
|||
template<typename R, typename T>
|
||||
inline ptrdiff_t write_range(
|
||||
R &writer, FormatSpec const *fl, bool escape, bool expandval,
|
||||
ConstCharRange sep, T const &val, EnableIf<detail::IterableTest<T>, bool> = true
|
||||
ConstCharRange sep, T const &val,
|
||||
std::enable_if_t<detail::IterableTest<T>, bool> = true
|
||||
) {
|
||||
auto range = ostd::iter(val);
|
||||
if (range.empty()) {
|
||||
|
@ -608,16 +611,18 @@ namespace detail {
|
|||
template<typename R, typename T>
|
||||
inline ptrdiff_t write_range(
|
||||
R &, FormatSpec const *, bool, bool, ConstCharRange,
|
||||
T const &, EnableIf<!detail::IterableTest<T>, bool> = true
|
||||
T const &, std::enable_if_t<!detail::IterableTest<T>, bool> = true
|
||||
) {
|
||||
assert(false && "invalid value for ranged format");
|
||||
return -1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static True test_fmt_tostr(decltype(ostd::to_string(std::declval<T>())) *);
|
||||
static std::true_type test_fmt_tostr(
|
||||
decltype(ostd::to_string(std::declval<T>())) *
|
||||
);
|
||||
template<typename>
|
||||
static False test_fmt_tostr(...);
|
||||
static std::false_type test_fmt_tostr(...);
|
||||
|
||||
template<typename T>
|
||||
constexpr bool FmtTostrTest = decltype(test_fmt_tostr<T>(0))::value;
|
||||
|
@ -661,13 +666,13 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename T, typename R>
|
||||
static True test_tofmt(decltype(to_format(
|
||||
static std::true_type test_tofmt(decltype(to_format(
|
||||
std::declval<T const &>(), std::declval<R &>(),
|
||||
std::declval<FormatSpec const &>()
|
||||
)) *);
|
||||
|
||||
template<typename, typename>
|
||||
static False test_tofmt(...);
|
||||
static std::false_type test_tofmt(...);
|
||||
|
||||
template<typename T, typename R>
|
||||
constexpr bool FmtTofmtTest = decltype(test_tofmt<T, R>(0))::value;
|
||||
|
@ -696,8 +701,8 @@ namespace detail {
|
|||
/* any string value */
|
||||
template<typename R, typename T>
|
||||
ptrdiff_t write(
|
||||
R &writer, bool escape, T const &val, EnableIf<
|
||||
IsConstructible<ConstCharRange, T const &>, bool
|
||||
R &writer, bool escape, T const &val, std::enable_if_t<
|
||||
std::is_constructible_v<ConstCharRange, T const &>, bool
|
||||
> = true
|
||||
) {
|
||||
if (this->spec() != 's') {
|
||||
|
@ -753,11 +758,11 @@ namespace detail {
|
|||
/* signed integers */
|
||||
template<typename R, typename T>
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T val, EnableIf<
|
||||
IsIntegral<T> && IsSigned<T>, bool
|
||||
R &writer, bool, T val, std::enable_if_t<
|
||||
std::is_integral_v<T> && std::is_signed_v<T>, bool
|
||||
> = true
|
||||
) {
|
||||
using UT = MakeUnsigned<T>;
|
||||
using UT = std::make_unsigned_t<T>;
|
||||
return detail::write_u(
|
||||
writer, this, val < 0,
|
||||
(val < 0) ? static_cast<UT>(-val) : static_cast<UT>(val)
|
||||
|
@ -767,16 +772,17 @@ namespace detail {
|
|||
/* unsigned integers */
|
||||
template<typename R, typename T>
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T val, EnableIf<
|
||||
IsIntegral<T> && IsUnsigned<T>, bool
|
||||
R &writer, bool, T val, std::enable_if_t<
|
||||
std::is_integral_v<T> && std::is_unsigned_v<T>, bool
|
||||
> = true
|
||||
) {
|
||||
return detail::write_u(writer, this, false, val);
|
||||
}
|
||||
|
||||
template<typename R, typename T, bool Long = IsSame<T, ldouble>>
|
||||
template<typename R, typename T, bool Long = std::is_same_v<T, ldouble>>
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T val, EnableIf<IsFloatingPoint<T>, bool> = true
|
||||
R &writer, bool, T val,
|
||||
std::enable_if_t<std::is_floating_point_v<T>, bool> = true
|
||||
) {
|
||||
char buf[16], rbuf[128];
|
||||
char fmtspec[Long + 1];
|
||||
|
@ -819,8 +825,8 @@ namespace detail {
|
|||
/* pointer value */
|
||||
template<typename R, typename T>
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T *val, EnableIf<
|
||||
!IsConstructible<ConstCharRange, T *>, bool
|
||||
R &writer, bool, T *val, std::enable_if_t<
|
||||
!std::is_constructible_v<ConstCharRange, T *>, bool
|
||||
> = true
|
||||
) {
|
||||
if (this->p_spec == 's') {
|
||||
|
@ -833,9 +839,9 @@ namespace detail {
|
|||
/* generic value */
|
||||
template<typename R, typename T>
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T const &val, EnableIf<
|
||||
!IsArithmetic<T> &&
|
||||
!IsConstructible<ConstCharRange, T const &> &&
|
||||
R &writer, bool, T const &val, std::enable_if_t<
|
||||
!std::is_arithmetic_v<T> &&
|
||||
!std::is_constructible_v<ConstCharRange, T const &> &&
|
||||
FmtTostrTest<T> && !FmtTofmtTest<T, TostrRange<R>>, bool
|
||||
> = true
|
||||
) {
|
||||
|
@ -850,7 +856,7 @@ namespace detail {
|
|||
template<typename R, typename T>
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T const &val,
|
||||
EnableIf<FmtTofmtTest<T, TostrRange<R>>, bool> = true
|
||||
std::enable_if_t<FmtTofmtTest<T, TostrRange<R>>, bool> = true
|
||||
) {
|
||||
TostrRange<R> sink(writer);
|
||||
if (!to_format(val, sink, *this)) {
|
||||
|
@ -862,9 +868,9 @@ namespace detail {
|
|||
/* generic failure case */
|
||||
template<typename R, typename T>
|
||||
ptrdiff_t write(
|
||||
R &, bool, T const &, EnableIf<
|
||||
!IsArithmetic<T> &&
|
||||
!IsConstructible<ConstCharRange, T const &> &&
|
||||
R &, bool, T const &, std::enable_if_t<
|
||||
!std::is_arithmetic_v<T> &&
|
||||
!std::is_constructible_v<ConstCharRange, T const &> &&
|
||||
!FmtTostrTest<T> && !FmtTofmtTest<T, TostrRange<R>>, bool
|
||||
> = true
|
||||
) {
|
||||
|
|
|
@ -159,8 +159,8 @@ namespace detail {
|
|||
|
||||
template<typename T>
|
||||
inline void write_impl(
|
||||
T const &v, EnableIf<
|
||||
!IsConstructible<ConstCharRange, T const &>, IoNat
|
||||
T const &v, std::enable_if_t<
|
||||
!std::is_constructible_v<ConstCharRange, T const &>, IoNat
|
||||
> = IoNat()
|
||||
) {
|
||||
write_impl(ostd::to_string(v));
|
||||
|
|
103
ostd/limits.hh
103
ostd/limits.hh
|
@ -1,103 +0,0 @@
|
|||
/* Type limits for OctaSTD.
|
||||
*
|
||||
* This file is part of OctaSTD. See COPYING.md for futher information.
|
||||
*/
|
||||
|
||||
#ifndef OSTD_LIMITS_HH
|
||||
#define OSTD_LIMITS_HH
|
||||
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "ostd/types.hh"
|
||||
#include "ostd/type_traits.hh"
|
||||
|
||||
namespace ostd {
|
||||
|
||||
namespace detail {
|
||||
template<typename T, bool I = IsIntegral<T>, bool F = IsFloatingPoint<T>>
|
||||
struct NumericLimitsBase {
|
||||
static constexpr T minv = T{};
|
||||
static constexpr T maxv = T{};
|
||||
static constexpr T lowv = T{};
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = false;
|
||||
};
|
||||
|
||||
/* signed integer types */
|
||||
template<typename T, bool S = IsSigned<T>>
|
||||
struct IntegerLimitsBase {
|
||||
using UT = MakeUnsigned<T>;
|
||||
static constexpr T minv = -(~(1ULL << (sizeof(T) * CHAR_BIT - 1))) - 1;
|
||||
static constexpr T maxv = T(UT(~UT(0)) >> 1);
|
||||
static constexpr T lowv = minv;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = true;
|
||||
};
|
||||
|
||||
/* unsigned integer types */
|
||||
template<typename T>
|
||||
struct IntegerLimitsBase<T, false> {
|
||||
static constexpr T minv = T(0);
|
||||
static constexpr T maxv = ~T(0);
|
||||
static constexpr T lowv = minv;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
};
|
||||
|
||||
/* all integer types */
|
||||
template<typename T>
|
||||
struct NumericLimitsBase<T, true, false>: IntegerLimitsBase<T> {};
|
||||
|
||||
/* floating point types */
|
||||
template<typename T>
|
||||
struct FloatLimitsBase;
|
||||
|
||||
template<>
|
||||
struct FloatLimitsBase<float> {
|
||||
static constexpr float minv = FLT_MIN;
|
||||
static constexpr float maxv = FLT_MAX;
|
||||
static constexpr float lowv = -maxv;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct FloatLimitsBase<double> {
|
||||
static constexpr double minv = DBL_MIN;
|
||||
static constexpr double maxv = DBL_MAX;
|
||||
static constexpr double lowv = -maxv;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct FloatLimitsBase<long double> {
|
||||
static constexpr long double minv = LDBL_MIN;
|
||||
static constexpr long double maxv = LDBL_MAX;
|
||||
static constexpr long double lowv = -maxv;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct NumericLimitsBase<T, false, true>: FloatLimitsBase<T> {
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = false;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T NumericLimitMin = detail::NumericLimitsBase<T>::minv;
|
||||
|
||||
template<typename T>
|
||||
constexpr T NumericLimitMax = detail::NumericLimitsBase<T>::maxv;
|
||||
|
||||
template<typename T>
|
||||
constexpr T NumericLimitLowest = detail::NumericLimitsBase<T>::lowv;
|
||||
|
||||
template<typename T>
|
||||
constexpr bool NumericLimitIsSigned = detail::NumericLimitsBase<T>::is_signed;
|
||||
|
||||
template<typename T>
|
||||
constexpr bool NumericLimitIsInteger = detail::NumericLimitsBase<T>::is_integer;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -13,10 +13,10 @@
|
|||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "ostd/types.hh"
|
||||
#include "ostd/utility.hh"
|
||||
#include "ostd/type_traits.hh"
|
||||
|
||||
namespace ostd {
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace detail { \
|
|||
template<typename T> \
|
||||
struct Range##Name##Test { \
|
||||
template<typename U> \
|
||||
static char test(RemoveReference<typename U::Name> *); \
|
||||
static char test(std::remove_reference_t<typename U::Name> *); \
|
||||
template<typename U> \
|
||||
static int test(...); \
|
||||
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char)); \
|
||||
|
@ -64,7 +64,7 @@ namespace detail {
|
|||
static char is_range_test(
|
||||
typename U::Category *, typename U::Size *,
|
||||
typename U::Difference *, typename U::Value *,
|
||||
RemoveReference<typename U::Reference> *
|
||||
std::remove_reference_t<typename U::Reference> *
|
||||
);
|
||||
template<typename U>
|
||||
static int is_range_test(...);
|
||||
|
@ -78,7 +78,7 @@ namespace detail {
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
constexpr bool IsInputRangeCore =
|
||||
IsConvertible<RangeCategory<T>, InputRangeTag>;
|
||||
std::is_convertible_v<RangeCategory<T>, InputRangeTag>;
|
||||
|
||||
template<typename T, bool = detail::IsRangeTest<T>>
|
||||
constexpr bool IsInputRangeBase = false;
|
||||
|
@ -95,7 +95,7 @@ constexpr bool IsInputRange = detail::IsInputRangeBase<T>;
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
constexpr bool IsForwardRangeCore =
|
||||
IsConvertible<RangeCategory<T>, ForwardRangeTag>;
|
||||
std::is_convertible_v<RangeCategory<T>, ForwardRangeTag>;
|
||||
|
||||
template<typename T, bool = detail::IsRangeTest<T>>
|
||||
constexpr bool IsForwardRangeBase = false;
|
||||
|
@ -112,7 +112,7 @@ constexpr bool IsForwardRange = detail::IsForwardRangeBase<T>;
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
constexpr bool IsBidirectionalRangeCore =
|
||||
IsConvertible<RangeCategory<T>, BidirectionalRangeTag>;
|
||||
std::is_convertible_v<RangeCategory<T>, BidirectionalRangeTag>;
|
||||
|
||||
template<typename T, bool = detail::IsRangeTest<T>>
|
||||
constexpr bool IsBidirectionalRangeBase = false;
|
||||
|
@ -130,7 +130,7 @@ template<typename T> constexpr bool IsBidirectionalRange =
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
constexpr bool IsRandomAccessRangeCore =
|
||||
IsConvertible<RangeCategory<T>, RandomAccessRangeTag>;
|
||||
std::is_convertible_v<RangeCategory<T>, RandomAccessRangeTag>;
|
||||
|
||||
template<typename T, bool = detail::IsRangeTest<T>>
|
||||
constexpr bool IsRandomAccessRangeBase = false;
|
||||
|
@ -148,7 +148,7 @@ template<typename T> constexpr bool IsRandomAccessRange =
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
constexpr bool IsFiniteRandomAccessRangeCore =
|
||||
IsConvertible<RangeCategory<T>, FiniteRandomAccessRangeTag>;
|
||||
std::is_convertible_v<RangeCategory<T>, FiniteRandomAccessRangeTag>;
|
||||
|
||||
template<typename T, bool = detail::IsRangeTest<T>>
|
||||
constexpr bool IsFiniteRandomAccessRangeBase = false;
|
||||
|
@ -171,7 +171,7 @@ template<typename T> constexpr bool IsInfiniteRandomAccessRange =
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
constexpr bool IsContiguousRangeCore =
|
||||
IsConvertible<RangeCategory<T>, ContiguousRangeTag>;
|
||||
std::is_convertible_v<RangeCategory<T>, ContiguousRangeTag>;
|
||||
|
||||
template<typename T, bool = detail::IsRangeTest<T>>
|
||||
constexpr bool IsContiguousRangeBase = false;
|
||||
|
@ -200,7 +200,7 @@ namespace detail {
|
|||
|
||||
template<typename T>
|
||||
constexpr bool IsOutputRangeCore =
|
||||
IsConvertible<RangeCategory<T>, OutputRangeTag> || (
|
||||
std::is_convertible_v<RangeCategory<T>, OutputRangeTag> || (
|
||||
IsInputRange<T> && (
|
||||
detail::OutputRangeTest<T, RangeValue<T> const &>::value ||
|
||||
detail::OutputRangeTest<T, RangeValue<T> &&>::value ||
|
||||
|
@ -271,7 +271,7 @@ namespace detail {
|
|||
p_init = false;
|
||||
}
|
||||
}
|
||||
AlignedStorage<sizeof(T), alignof(T)> p_range;
|
||||
std::aligned_storage_t<sizeof(T), alignof(T)> p_range;
|
||||
bool p_init;
|
||||
};
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ public:
|
|||
RangeHalf() = delete;
|
||||
RangeHalf(T const &range): p_range(range) {}
|
||||
|
||||
template<typename U, typename = EnableIf<IsConvertible<U, T>>>
|
||||
template<typename U, typename = std::enable_if_t<std::is_convertible_v<U, T>>>
|
||||
RangeHalf(RangeHalf<U> const &half): p_range(half.p_range) {}
|
||||
|
||||
RangeHalf(RangeHalf const &half): p_range(half.p_range) {}
|
||||
|
@ -622,7 +622,7 @@ struct InputRange {
|
|||
}
|
||||
|
||||
template<typename OR>
|
||||
EnableIf<IsOutputRange<OR>, Size> copy(OR &&orange, Size n = -1) {
|
||||
std::enable_if_t<IsOutputRange<OR>, Size> copy(OR &&orange, Size n = -1) {
|
||||
B r(*static_cast<B const *>(this));
|
||||
Size on = n;
|
||||
for (; n && !r.empty(); --n) {
|
||||
|
@ -634,7 +634,7 @@ struct InputRange {
|
|||
return (on - n);
|
||||
}
|
||||
|
||||
Size copy(RemoveCv<Value> *p, Size n = -1) {
|
||||
Size copy(std::remove_cv_t<Value> *p, Size n = -1) {
|
||||
B r(*static_cast<B const *>(this));
|
||||
Size on = n;
|
||||
for (; n && !r.empty(); --n) {
|
||||
|
@ -698,7 +698,7 @@ struct InputRange {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename R, typename F, typename = EnableIf<IsInputRange<R>>>
|
||||
template<typename R, typename F, typename = std::enable_if_t<IsInputRange<R>>>
|
||||
inline auto operator|(R &&range, F &&func) {
|
||||
return func(std::forward<R>(range));
|
||||
}
|
||||
|
@ -794,17 +794,17 @@ struct ranged_traits;
|
|||
|
||||
namespace detail {
|
||||
template<typename C>
|
||||
static True test_direct_iter(decltype(std::declval<C>().iter()) *);
|
||||
static std::true_type test_direct_iter(decltype(std::declval<C>().iter()) *);
|
||||
|
||||
template<typename>
|
||||
static False test_direct_iter(...);
|
||||
static std::false_type test_direct_iter(...);
|
||||
|
||||
template<typename C>
|
||||
constexpr bool direct_iter_test = decltype(test_direct_iter<C>(0))::value;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
struct ranged_traits<C, EnableIf<detail::direct_iter_test<C>>> {
|
||||
struct ranged_traits<C, std::enable_if_t<detail::direct_iter_test<C>>> {
|
||||
static auto iter(C &r) -> decltype(r.iter()) {
|
||||
return r.iter();
|
||||
}
|
||||
|
@ -944,7 +944,7 @@ public:
|
|||
|
||||
template<typename T>
|
||||
struct ReverseRange: InputRange<ReverseRange<T>,
|
||||
CommonType<RangeCategory<T>, FiniteRandomAccessRangeTag>,
|
||||
std::common_type_t<RangeCategory<T>, FiniteRandomAccessRangeTag>,
|
||||
RangeValue<T>, RangeReference<T>, RangeSize<T>, RangeDifference<T>
|
||||
> {
|
||||
private:
|
||||
|
@ -1018,7 +1018,7 @@ public:
|
|||
|
||||
template<typename T>
|
||||
struct MoveRange: InputRange<MoveRange<T>,
|
||||
CommonType<RangeCategory<T>, FiniteRandomAccessRangeTag>,
|
||||
std::common_type_t<RangeCategory<T>, FiniteRandomAccessRangeTag>,
|
||||
RangeValue<T>, RangeValue<T> &&, RangeSize<T>, RangeDifference<T>
|
||||
> {
|
||||
private:
|
||||
|
@ -1133,13 +1133,16 @@ public:
|
|||
PointerRange(): p_beg(nullptr), p_end(nullptr) {}
|
||||
|
||||
template<typename U>
|
||||
PointerRange(T *beg, U end, EnableIf<
|
||||
(IsPointer<U> || IsNullPointer<U>) && IsConvertible<U, T *>, Nat
|
||||
PointerRange(T *beg, U end, std::enable_if_t<
|
||||
(std::is_pointer_v<U> || std::is_null_pointer_v<U>) &&
|
||||
std::is_convertible_v<U, T *>, Nat
|
||||
> = Nat()): p_beg(beg), p_end(end) {}
|
||||
|
||||
PointerRange(T *beg, size_t n): p_beg(beg), p_end(beg + n) {}
|
||||
|
||||
template<typename U, typename = EnableIf<IsConvertible<U *, T *>>>
|
||||
template<typename U, typename = std::enable_if_t<
|
||||
std::is_convertible_v<U *, T *>
|
||||
>>
|
||||
PointerRange(PointerRange<U> const &v): p_beg(&v[0]), p_end(&v[v.size()]) {}
|
||||
|
||||
PointerRange &operator=(PointerRange const &v) {
|
||||
|
@ -1252,7 +1255,7 @@ public:
|
|||
if (n < ret) {
|
||||
ret = n;
|
||||
}
|
||||
if (IsPod<T>) {
|
||||
if constexpr(std::is_pod_v<T>) {
|
||||
memcpy(p_beg, p, ret * sizeof(T));
|
||||
p_beg += ret;
|
||||
return ret;
|
||||
|
@ -1264,7 +1267,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename R>
|
||||
EnableIf<IsOutputRange<R>, size_t> copy(R &&orange, size_t n = -1) {
|
||||
std::enable_if_t<IsOutputRange<R>, size_t> copy(R &&orange, size_t n = -1) {
|
||||
size_t c = size();
|
||||
if (n < c) {
|
||||
c = n;
|
||||
|
@ -1272,12 +1275,12 @@ public:
|
|||
return orange.put_n(p_beg, c);
|
||||
}
|
||||
|
||||
size_t copy(RemoveCv<T> *p, size_t n = -1) {
|
||||
size_t copy(std::remove_cv_t<T> *p, size_t n = -1) {
|
||||
size_t c = size();
|
||||
if (n < c) {
|
||||
c = n;
|
||||
}
|
||||
if (IsPod<T>) {
|
||||
if constexpr(std::is_pod_v<T>) {
|
||||
memcpy(p_beg, data(), c * sizeof(T));
|
||||
return c;
|
||||
}
|
||||
|
@ -1303,8 +1306,9 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
inline PointerRange<T> iter(T *a, U b, EnableIf<
|
||||
(IsPointer<U> || IsNullPointer<U>) && IsConvertible<U, T *>, detail::PtrNat
|
||||
inline PointerRange<T> iter(T *a, U b, std::enable_if_t<
|
||||
(std::is_pointer_v<U> || std::is_null_pointer_v<U>) &&
|
||||
std::is_convertible_v<U, T *>, detail::PtrNat
|
||||
> = detail::PtrNat()) {
|
||||
return PointerRange<T>(a, b);
|
||||
}
|
||||
|
@ -1322,7 +1326,7 @@ struct EnumeratedValue {
|
|||
|
||||
template<typename T>
|
||||
struct EnumeratedRange: InputRange<EnumeratedRange<T>,
|
||||
CommonType<RangeCategory<T>, ForwardRangeTag>, RangeValue<T>,
|
||||
std::common_type_t<RangeCategory<T>, ForwardRangeTag>, RangeValue<T>,
|
||||
EnumeratedValue<RangeReference<T>, RangeSize<T>>,
|
||||
RangeSize<T>
|
||||
> {
|
||||
|
@ -1394,7 +1398,7 @@ public:
|
|||
|
||||
template<typename T>
|
||||
struct TakeRange: InputRange<TakeRange<T>,
|
||||
CommonType<RangeCategory<T>, ForwardRangeTag>,
|
||||
std::common_type_t<RangeCategory<T>, ForwardRangeTag>,
|
||||
RangeValue<T>, RangeReference<T>, RangeSize<T>
|
||||
> {
|
||||
private:
|
||||
|
@ -1446,7 +1450,7 @@ public:
|
|||
|
||||
template<typename T>
|
||||
struct ChunksRange: InputRange<ChunksRange<T>,
|
||||
CommonType<RangeCategory<T>, ForwardRangeTag>,
|
||||
std::common_type_t<RangeCategory<T>, ForwardRangeTag>,
|
||||
TakeRange<T>, TakeRange<T>, RangeSize<T>
|
||||
> {
|
||||
private:
|
||||
|
@ -1567,9 +1571,9 @@ namespace detail {
|
|||
|
||||
template<typename ...R>
|
||||
struct JoinRange: InputRange<JoinRange<R...>,
|
||||
CommonType<ForwardRangeTag, RangeCategory<R>...>,
|
||||
CommonType<RangeValue<R>...>, CommonType<RangeReference<R>...>,
|
||||
CommonType<RangeSize<R>...>, CommonType<RangeDifference<R>...>> {
|
||||
std::common_type_t<ForwardRangeTag, RangeCategory<R>...>,
|
||||
std::common_type_t<RangeValue<R>...>, std::common_type_t<RangeReference<R>...>,
|
||||
std::common_type_t<RangeSize<R>...>, std::common_type_t<RangeDifference<R>...>> {
|
||||
private:
|
||||
std::tuple<R...> p_ranges;
|
||||
public:
|
||||
|
@ -1603,9 +1607,9 @@ public:
|
|||
return detail::JoinRangePop<0, sizeof...(R)>::pop(p_ranges);
|
||||
}
|
||||
|
||||
CommonType<RangeReference<R>...> front() const {
|
||||
std::common_type_t<RangeReference<R>...> front() const {
|
||||
return detail::JoinRangeFront<
|
||||
0, sizeof...(R), CommonType<RangeReference<R>...>
|
||||
0, sizeof...(R), std::common_type_t<RangeReference<R>...>
|
||||
>::front(p_ranges);
|
||||
}
|
||||
};
|
||||
|
@ -1679,10 +1683,11 @@ namespace detail {
|
|||
|
||||
template<typename ...R>
|
||||
struct ZipRange: InputRange<ZipRange<R...>,
|
||||
CommonType<ForwardRangeTag, RangeCategory<R>...>,
|
||||
std::common_type_t<ForwardRangeTag, RangeCategory<R>...>,
|
||||
detail::ZipValue<RangeValue<R>...>,
|
||||
detail::ZipValue<RangeReference<R>...>,
|
||||
CommonType<RangeSize<R>...>, CommonType<RangeDifference<R>...>> {
|
||||
std::common_type_t<RangeSize<R>...>,
|
||||
std::common_type_t<RangeDifference<R>...>> {
|
||||
private:
|
||||
std::tuple<R...> p_ranges;
|
||||
public:
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
#define OSTD_STREAM_HH
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#include "ostd/platform.hh"
|
||||
#include "ostd/types.hh"
|
||||
#include "ostd/range.hh"
|
||||
#include "ostd/type_traits.hh"
|
||||
#include "ostd/string.hh"
|
||||
#include "ostd/utility.hh"
|
||||
#include "ostd/format.hh"
|
||||
|
@ -32,7 +30,7 @@ enum class StreamSeek {
|
|||
set = SEEK_SET
|
||||
};
|
||||
|
||||
template<typename T = char, bool = IsPod<T>>
|
||||
template<typename T = char, bool = std::is_pod_v<T>>
|
||||
struct StreamRange;
|
||||
|
||||
struct Stream {
|
||||
|
@ -45,8 +43,8 @@ private:
|
|||
|
||||
template<typename T>
|
||||
inline bool write_impl(
|
||||
T const &v, EnableIf<
|
||||
!IsConstructible<ConstCharRange, T const &>, StNat
|
||||
T const &v, std::enable_if_t<
|
||||
!std::is_constructible_v<ConstCharRange, T const &>, StNat
|
||||
> = StNat()
|
||||
) {
|
||||
return write(ostd::to_string(v));
|
||||
|
@ -189,7 +187,7 @@ struct StreamRange<T, true>: InputRange<
|
|||
return p_stream->put(p, n);
|
||||
}
|
||||
|
||||
size_t copy(RemoveCv<T> *p, size_t n = -1) {
|
||||
size_t copy(std::remove_cv_t<T> *p, size_t n = -1) {
|
||||
if (n == size_t(-1)) {
|
||||
n = p_stream->size() / sizeof(T);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "ostd/utility.hh"
|
||||
#include "ostd/range.hh"
|
||||
#include "ostd/vector.hh"
|
||||
#include "ostd/type_traits.hh"
|
||||
#include "ostd/algorithm.hh"
|
||||
|
||||
namespace ostd {
|
||||
|
@ -34,8 +33,9 @@ public:
|
|||
CharRangeBase(): p_beg(nullptr), p_end(nullptr) {};
|
||||
|
||||
template<typename U>
|
||||
CharRangeBase(T *beg, U end, EnableIf<
|
||||
(IsPointer<U> || IsNullPointer<U>) && IsConvertible<U, T *>, Nat
|
||||
CharRangeBase(T *beg, U end, std::enable_if_t<
|
||||
(std::is_pointer_v<U> || std::is_null_pointer_v<U>) &&
|
||||
std::is_convertible_v<U, T *>, Nat
|
||||
> = Nat()): p_beg(beg), p_end(end) {}
|
||||
|
||||
CharRangeBase(T *beg, size_t n): p_beg(beg), p_end(beg + n) {}
|
||||
|
@ -43,24 +43,30 @@ public:
|
|||
/* TODO: traits for utf-16/utf-32 string lengths, for now assume char */
|
||||
template<typename U>
|
||||
CharRangeBase(
|
||||
U beg, EnableIf<IsConvertible<U, T *> && !IsArray<U>, Nat> = Nat()
|
||||
U beg, std::enable_if_t<
|
||||
std::is_convertible_v<U, T *> && !std::is_array_v<U>, Nat
|
||||
> = Nat()
|
||||
): p_beg(beg), p_end(static_cast<T *>(beg) + (beg ? strlen(beg) : 0)) {}
|
||||
|
||||
CharRangeBase(std::nullptr_t): p_beg(nullptr), p_end(nullptr) {}
|
||||
|
||||
template<typename U, size_t N>
|
||||
CharRangeBase(U (&beg)[N], EnableIf<IsConvertible<U *, T *>, Nat> = Nat()):
|
||||
CharRangeBase(U (&beg)[N], std::enable_if_t<
|
||||
std::is_convertible_v<U *, T *>, Nat
|
||||
> = Nat()):
|
||||
p_beg(beg), p_end(beg + N - (beg[N - 1] == '\0'))
|
||||
{}
|
||||
|
||||
template<typename U, typename TR, typename A>
|
||||
CharRangeBase(std::basic_string<U, TR, A> const &s, EnableIf<
|
||||
IsConvertible<U *, T *>, Nat
|
||||
CharRangeBase(std::basic_string<U, TR, A> const &s, std::enable_if_t<
|
||||
std::is_convertible_v<U *, T *>, Nat
|
||||
> = Nat()):
|
||||
p_beg(s.data()), p_end(s.data() + s.size())
|
||||
{}
|
||||
|
||||
template<typename U, typename = EnableIf<IsConvertible<U *, T *>>>
|
||||
template<typename U, typename = std::enable_if_t<
|
||||
std::is_convertible_v<U *, T *>
|
||||
>>
|
||||
CharRangeBase(CharRangeBase<U> const &v):
|
||||
p_beg(&v[0]), p_end(&v[v.size()])
|
||||
{}
|
||||
|
@ -194,19 +200,19 @@ diffsize:
|
|||
}
|
||||
|
||||
template<typename R>
|
||||
EnableIf<IsOutputRange<R>, size_t> copy(R &&orange, size_t n = -1) {
|
||||
std::enable_if_t<IsOutputRange<R>, size_t> copy(R &&orange, size_t n = -1) {
|
||||
return orange.put_n(data(), ostd::min(n, size()));
|
||||
}
|
||||
|
||||
size_t copy(RemoveCv<T> *p, size_t n = -1) {
|
||||
size_t copy(std::remove_cv_t<T> *p, size_t n = -1) {
|
||||
size_t c = ostd::min(n, size());
|
||||
memcpy(p, data(), c * sizeof(T));
|
||||
return c;
|
||||
}
|
||||
|
||||
/* that way we can assign, append etc to std::string */
|
||||
operator std::basic_string_view<RemoveCv<T>>() const {
|
||||
return std::basic_string_view<RemoveCv<T>>{data(), size()};
|
||||
operator std::basic_string_view<std::remove_cv_t<T>>() const {
|
||||
return std::basic_string_view<std::remove_cv_t<T>>{data(), size()};
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -283,13 +289,15 @@ inline std::basic_string<T, TR, A> make_string(R range, A const &alloc = A{}) {
|
|||
}
|
||||
|
||||
template<
|
||||
typename R, typename TR = std::char_traits<RemoveCv<RangeValue<R>>>,
|
||||
typename A = std::allocator<RemoveCv<RangeValue<R>>>
|
||||
typename R, typename TR = std::char_traits<std::remove_cv_t<RangeValue<R>>>,
|
||||
typename A = std::allocator<std::remove_cv_t<RangeValue<R>>>
|
||||
>
|
||||
inline std::basic_string<RemoveCv<RangeValue<R>>, TR, A> make_string(
|
||||
inline std::basic_string<std::remove_cv_t<RangeValue<R>>, TR, A> make_string(
|
||||
R range, A const &alloc = A{}
|
||||
) {
|
||||
return make_string<RemoveCv<RangeValue<R>>, TR, A>(std::move(range), alloc);
|
||||
return make_string<std::remove_cv_t<RangeValue<R>>, TR, A>(
|
||||
std::move(range), alloc
|
||||
);
|
||||
}
|
||||
|
||||
/* string literals */
|
||||
|
@ -304,8 +312,8 @@ inline namespace string_literals {
|
|||
|
||||
namespace detail {
|
||||
template<
|
||||
typename T, bool = IsConvertible<T, ConstCharRange>,
|
||||
bool = IsConvertible<T, char>
|
||||
typename T, bool = std::is_convertible_v<T, ConstCharRange>,
|
||||
bool = std::is_convertible_v<T, char>
|
||||
>
|
||||
struct ConcatPut;
|
||||
|
||||
|
@ -402,23 +410,25 @@ namespace detail {
|
|||
};
|
||||
|
||||
template<typename T, typename R>
|
||||
static auto test_stringify(int) ->
|
||||
BoolConstant<IsSame<decltype(std::declval<T>().stringify()), std::string>>;
|
||||
static auto test_stringify(int) -> std::integral_constant<
|
||||
bool, std::is_same_v<decltype(std::declval<T>().stringify()), std::string>
|
||||
>;
|
||||
|
||||
template<typename T, typename R>
|
||||
static True test_stringify(decltype(std::declval<T const &>().to_string
|
||||
(std::declval<R &>())) *);
|
||||
static std::true_type test_stringify(
|
||||
decltype(std::declval<T const &>().to_string(std::declval<R &>())) *
|
||||
);
|
||||
|
||||
template<typename, typename>
|
||||
static False test_stringify(...);
|
||||
static std::false_type test_stringify(...);
|
||||
|
||||
template<typename T, typename R>
|
||||
constexpr bool StringifyTest = decltype(test_stringify<T, R>(0))::value;
|
||||
|
||||
template<typename T>
|
||||
static True test_iterable(decltype(ostd::iter(std::declval<T>())) *);
|
||||
static std::true_type test_iterable(decltype(ostd::iter(std::declval<T>())) *);
|
||||
template<typename>
|
||||
static False test_iterable(...);
|
||||
static std::false_type test_iterable(...);
|
||||
|
||||
template<typename T>
|
||||
constexpr bool IterableTest = decltype(test_iterable<T>(0))::value;
|
||||
|
@ -428,15 +438,15 @@ template<typename T, typename = void>
|
|||
struct ToString;
|
||||
|
||||
template<typename T>
|
||||
struct ToString<T, EnableIf<detail::IterableTest<T>>> {
|
||||
using Argument = RemoveCv<RemoveReference<T>>;
|
||||
struct ToString<T, std::enable_if_t<detail::IterableTest<T>>> {
|
||||
using Argument = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||
using Result = std::string;
|
||||
|
||||
std::string operator()(T const &v) const {
|
||||
std::string ret("{");
|
||||
auto x = appender<std::string>();
|
||||
if (concat(x, ostd::iter(v), ", ", ToString<
|
||||
RemoveConst<RemoveReference<
|
||||
std::remove_const_t<std::remove_reference_t<
|
||||
RangeReference<decltype(ostd::iter(v))>
|
||||
>>
|
||||
>())) {
|
||||
|
@ -448,10 +458,10 @@ struct ToString<T, EnableIf<detail::IterableTest<T>>> {
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
struct ToString<T, EnableIf<
|
||||
struct ToString<T, std::enable_if_t<
|
||||
detail::StringifyTest<T, detail::TostrRange<AppenderRange<std::string>>>
|
||||
>> {
|
||||
using Argument = RemoveCv<RemoveReference<T>>;
|
||||
using Argument = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||
using Result = std::string;
|
||||
|
||||
std::string operator()(T const &v) const {
|
||||
|
@ -573,9 +583,9 @@ struct ToString<std::pair<T, U>> {
|
|||
using Result = std::string;
|
||||
std::string operator()(Argument const &v) {
|
||||
std::string ret{"{"};
|
||||
ret += ToString<RemoveCv<RemoveReference<T>>>()(v.first);
|
||||
ret += ToString<std::remove_cv_t<std::remove_reference_t<T>>>()(v.first);
|
||||
ret += ", ";
|
||||
ret += ToString<RemoveCv<RemoveReference<U>>>()(v.second);
|
||||
ret += ToString<std::remove_cv_t<std::remove_reference_t<U>>>()(v.second);
|
||||
ret += "}";
|
||||
return ret;
|
||||
}
|
||||
|
@ -587,7 +597,7 @@ namespace detail {
|
|||
template<typename T>
|
||||
static void append(std::string &ret, T const &tup) {
|
||||
ret += ", ";
|
||||
ret += ToString<RemoveCv<RemoveReference<
|
||||
ret += ToString<std::remove_cv_t<std::remove_reference_t<
|
||||
decltype(std::get<I>(tup))
|
||||
>>>()(std::get<I>(tup));
|
||||
TupleToString<I + 1, N>::append(ret, tup);
|
||||
|
@ -604,7 +614,7 @@ namespace detail {
|
|||
struct TupleToString<0, N> {
|
||||
template<typename T>
|
||||
static void append(std::string &ret, T const &tup) {
|
||||
ret += ToString<RemoveCv<RemoveReference<
|
||||
ret += ToString<std::remove_cv_t<std::remove_reference_t<
|
||||
decltype(std::get<0>(tup))
|
||||
>>>()(std::get<0>(tup));
|
||||
TupleToString<1, N>::append(ret, tup);
|
||||
|
@ -626,7 +636,7 @@ struct ToString<std::tuple<T...>> {
|
|||
|
||||
template<typename T>
|
||||
typename ToString<T>::Result to_string(T const &v) {
|
||||
return ToString<RemoveCv<RemoveReference<T>>>()(v);
|
||||
return ToString<std::remove_cv_t<std::remove_reference_t<T>>>()(v);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -637,7 +647,7 @@ std::string to_string(std::initializer_list<T> init) {
|
|||
template<typename R>
|
||||
struct TempCString {
|
||||
private:
|
||||
RemoveCv<RangeValue<R>> *p_buf;
|
||||
std::remove_cv_t<RangeValue<R>> *p_buf;
|
||||
bool p_allocated;
|
||||
|
||||
public:
|
||||
|
@ -647,13 +657,13 @@ public:
|
|||
s.p_buf = nullptr;
|
||||
s.p_allocated = false;
|
||||
}
|
||||
TempCString(R input, RemoveCv<RangeValue<R>> *sbuf, size_t bufsize)
|
||||
TempCString(R input, std::remove_cv_t<RangeValue<R>> *sbuf, size_t bufsize)
|
||||
: p_buf(nullptr), p_allocated(false) {
|
||||
if (input.empty()) {
|
||||
return;
|
||||
}
|
||||
if (input.size() >= bufsize) {
|
||||
p_buf = new RemoveCv<RangeValue<R>>[input.size() + 1];
|
||||
p_buf = new std::remove_cv_t<RangeValue<R>>[input.size() + 1];
|
||||
p_allocated = true;
|
||||
} else {
|
||||
p_buf = sbuf;
|
||||
|
@ -672,8 +682,8 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
operator RemoveCv<RangeValue<R>> const *() const { return p_buf; }
|
||||
RemoveCv<RangeValue<R>> const *get() const { return p_buf; }
|
||||
operator std::remove_cv_t<RangeValue<R>> const *() const { return p_buf; }
|
||||
std::remove_cv_t<RangeValue<R>> const *get() const { return p_buf; }
|
||||
|
||||
void swap(TempCString &s) {
|
||||
using std::swap;
|
||||
|
@ -689,7 +699,7 @@ inline void swap(TempCString<R> &a, TempCString<R> &b) {
|
|||
|
||||
template<typename R>
|
||||
inline TempCString<R> to_temp_cstr(
|
||||
R input, RemoveCv<RangeValue<R>> *buf, size_t bufsize
|
||||
R input, std::remove_cv_t<RangeValue<R>> *buf, size_t bufsize
|
||||
) {
|
||||
return TempCString<R>(input, buf, bufsize);
|
||||
}
|
||||
|
|
1618
ostd/type_traits.hh
1618
ostd/type_traits.hh
File diff suppressed because it is too large
Load Diff
|
@ -10,15 +10,16 @@
|
|||
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
#include "ostd/type_traits.hh"
|
||||
#include "ostd/types.hh"
|
||||
|
||||
namespace ostd {
|
||||
|
||||
namespace detail {
|
||||
template<typename T, typename U,
|
||||
bool = IsSame<RemoveCv<T>, RemoveCv<U>>,
|
||||
bool = IsEmpty<T>, bool = IsEmpty<U>
|
||||
bool = std::is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>,
|
||||
bool = std::is_empty_v<T>, bool = std::is_empty_v<U>
|
||||
>
|
||||
constexpr size_t CompressedPairSwitch = detail::Undefined<T>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue