don't use classic style casts
parent
85b7602654
commit
47ed1a700c
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
OSTD_CXXFLAGS = -O2 -g -std=c++14 -Wall -Wextra -Wshadow -I.
|
||||
OSTD_CXXFLAGS = -O2 -g -std=c++14 -Wall -Wextra -Wshadow -Wold-style-cast -I.
|
||||
|
||||
EXAMPLES_OBJ = \
|
||||
examples/format \
|
||||
|
|
|
@ -56,9 +56,9 @@ namespace detail {
|
|||
!CanAtomicAssign<AtomicBase<T> volatile *, T> &&
|
||||
CanAtomicAssign<AtomicBase<T> *, T>
|
||||
> atomic_init(AtomicBase<T> volatile *a, T v) {
|
||||
char volatile *to = (char volatile *)(&a->p_value);
|
||||
char volatile *to = reinterpret_cast<char volatile *>(&a->p_value);
|
||||
char volatile *end = to + sizeof(T);
|
||||
char *from = (char *)(&v);
|
||||
char *from = reinterpret_cast<char *>(&v);
|
||||
while (to != end) *to++ =*from++;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ namespace detail {
|
|||
SignalBase(SignalBase const &ev): p_class(ev.p_class),
|
||||
p_nfuncs(ev.p_nfuncs) {
|
||||
using Func = Function<void(C &, A...)>;
|
||||
Func *nbuf = (Func *)new byte[sizeof(Func) * p_nfuncs];
|
||||
byte *bufp = new byte[sizeof(Func) * p_nfuncs];
|
||||
Func *nbuf = reinterpret_cast<Func *>(bufp);
|
||||
for (Size i = 0; i < p_nfuncs; ++i)
|
||||
new (&nbuf[i]) Func(ev.p_funcs[i]);
|
||||
p_funcs = nbuf;
|
||||
|
@ -34,7 +35,8 @@ namespace detail {
|
|||
using Func = Function<void(C &, A...)>;
|
||||
p_class = ev.p_class;
|
||||
p_nfuncs = ev.p_nfuncs;
|
||||
Func *nbuf = (Func *)new byte[sizeof(Func) * p_nfuncs];
|
||||
byte *bufp = new byte[sizeof(Func) * p_nfuncs];
|
||||
Func *nbuf = reinterpret_cast<Func *>(bufp);
|
||||
for (Size i = 0; i < p_nfuncs; ++i)
|
||||
new (&nbuf[i]) Func(ev.p_funcs[i]);
|
||||
p_funcs = nbuf;
|
||||
|
@ -51,7 +53,7 @@ namespace detail {
|
|||
void clear() {
|
||||
for (Size i = 0; i < p_nfuncs; ++i)
|
||||
p_funcs[i].~Function<void(C &, A...)>();
|
||||
delete[] (byte *)p_funcs;
|
||||
delete[] reinterpret_cast<byte *>(p_funcs);
|
||||
p_funcs = nullptr;
|
||||
p_nfuncs = 0;
|
||||
}
|
||||
|
@ -59,18 +61,20 @@ namespace detail {
|
|||
template<typename F>
|
||||
Size connect(F &&func) {
|
||||
using Func = Function<void(C &, A...)>;
|
||||
for (Size i = 0; i < p_nfuncs; ++i)
|
||||
for (Size i = 0; i < p_nfuncs; ++i) {
|
||||
if (!p_funcs[i]) {
|
||||
p_funcs[i] = forward<F>(func);
|
||||
return i;
|
||||
}
|
||||
Func *nbuf = (Func *)new byte[sizeof(Func) * (p_nfuncs + 1)];
|
||||
}
|
||||
byte *bufp = new byte[sizeof(Func) * (p_nfuncs + 1)];
|
||||
Func *nbuf = reinterpret_cast<Func *>(bufp);
|
||||
for (Size i = 0; i < p_nfuncs; ++i) {
|
||||
new (&nbuf[i]) Func(move(p_funcs[i]));
|
||||
p_funcs[i].~Func();
|
||||
}
|
||||
new (&nbuf[p_nfuncs]) Func(forward<F>(func));
|
||||
delete[] (byte *)p_funcs;
|
||||
delete[] reinterpret_cast<byte *>(p_funcs);
|
||||
p_funcs = nbuf;
|
||||
return p_nfuncs++;
|
||||
}
|
||||
|
|
|
@ -31,23 +31,23 @@ inline SDL_RWops *stream_to_rwops(Stream &s) {
|
|||
}
|
||||
rwr->hidden.unknown.data1 = &s;
|
||||
rwr->size = [](SDL_RWops *rw) -> SDLRWopsOffset {
|
||||
Stream *is = (Stream *)rw->hidden.unknown.data1;
|
||||
return (SDLRWopsOffset)is->size();
|
||||
Stream *is = static_cast<Stream *>(rw->hidden.unknown.data1);
|
||||
return static_cast<SDLRWopsOffset>(is->size());
|
||||
};
|
||||
rwr->seek = [](SDL_RWops *rw, SDLRWopsOffset pos, int whence) -> SDLRWopsOffset {
|
||||
Stream *is = (Stream *)rw->hidden.unknown.data1;
|
||||
Stream *is = static_cast<Stream *>(rw->hidden.unknown.data1);
|
||||
if (!pos && whence == SEEK_CUR)
|
||||
return (SDLRWopsOffset)is->tell();
|
||||
return static_cast<SDLRWopsOffset>(is->tell());
|
||||
if (is->seek(((StreamOffset)pos, (StreamSeek)whence))
|
||||
return (SDLRWopsOffset)is->tell();
|
||||
return static_cast<SDLRWopsOffset>(is->tell());
|
||||
return -1;
|
||||
};
|
||||
rwr->read = [](SDL_RWops *rw, void *buf, Size size, Size nb) -> Size {
|
||||
Stream *is = (Stream *)rw->hidden.unknown.data1;
|
||||
Stream *is = static_cast<Stream *>(rw->hidden.unknown.data1);
|
||||
return is->read_bytes(buf, size * nb) / size;
|
||||
};
|
||||
rwr->write = [](SDL_RWops *rw, const void *buf, Size size, Size nb) -> Size {
|
||||
Stream *is = (Stream *)rw->hidden.unknown.data1;
|
||||
Stream *is = static_cast<Stream *>(rw->hidden.unknown.data1);
|
||||
return is->write_bytes(buf, size * nb) / size;
|
||||
};
|
||||
rwr->close = [](SDL_RWops *) -> int { return 0; };
|
||||
|
|
|
@ -325,7 +325,7 @@ private:
|
|||
return FileInfo();
|
||||
String ap = p_path;
|
||||
ap += PathSeparator;
|
||||
ap += (char const *)p_de->d_name;
|
||||
ap += static_cast<char const *>(p_de->d_name);
|
||||
return FileInfo(ap);
|
||||
}
|
||||
|
||||
|
|
|
@ -650,7 +650,9 @@ namespace detail {
|
|||
Size elen = strlen(esc);
|
||||
memcpy(buf + 1, esc, elen);
|
||||
buf[elen + 1] = '\'';
|
||||
return write(writer, false, (char const *)buf, elen + 2);
|
||||
/* invoke proper overload via ptr */
|
||||
char const *bufp = buf;
|
||||
return write(writer, false, bufp, elen + 2);
|
||||
}
|
||||
}
|
||||
Ptrdiff r = 1 + escape * 2;
|
||||
|
@ -680,7 +682,7 @@ namespace detail {
|
|||
> = true) {
|
||||
using UT = MakeUnsigned<T>;
|
||||
return detail::write_u(writer, this, val < 0,
|
||||
(val < 0) ? (UT)(-val) : (UT)(val));
|
||||
(val < 0) ? static_cast<UT>(-val) : static_cast<UT>(val));
|
||||
}
|
||||
|
||||
/* unsigned integers */
|
||||
|
@ -714,11 +716,11 @@ namespace detail {
|
|||
char *dbuf = nullptr;
|
||||
if (Size(ret) >= sizeof(rbuf)) {
|
||||
/* this should typically never happen */
|
||||
dbuf = (char *)malloc(ret + 1);
|
||||
dbuf = new char[ret + 1];
|
||||
ret = snprintf(dbuf, ret + 1, buf, this->width(),
|
||||
this->has_precision() ? this->precision() : 6, val);
|
||||
writer.put_n(dbuf, ret);
|
||||
free(dbuf);
|
||||
delete[] dbuf;
|
||||
} else writer.put_n(rbuf, ret);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ namespace detail {
|
|||
|
||||
inline Size mem_hash(void const *p, Size l) {
|
||||
using Consts = FnvConstants<sizeof(Size)>;
|
||||
byte const *d = (byte const *)p;
|
||||
byte const *d = static_cast<byte const *>(p);
|
||||
Size h = Consts::offset;
|
||||
for (byte const *it = d, *end = d + l; it != end; ++it) {
|
||||
h ^= *it;
|
||||
|
@ -306,7 +306,7 @@ namespace detail {
|
|||
Size operator()(T v) const {
|
||||
union { T v; struct { Size h1, h2; }; } u;
|
||||
u.v = v;
|
||||
return mem_hash((void const *)&u, sizeof(u));
|
||||
return mem_hash(static_cast<void const *>(&u), sizeof(u));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -317,7 +317,7 @@ namespace detail {
|
|||
Size operator()(T v) const {
|
||||
union { T v; struct { Size h1, h2, h3; }; } u;
|
||||
u.v = v;
|
||||
return mem_hash((void const *)&u, sizeof(u));
|
||||
return mem_hash(static_cast<void const *>(&u), sizeof(u));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -328,7 +328,7 @@ namespace detail {
|
|||
Size operator()(T v) const {
|
||||
union { T v; struct { Size h1, h2, h3, h4; }; } u;
|
||||
u.v = v;
|
||||
return mem_hash((void const *)&u, sizeof(u));
|
||||
return mem_hash(static_cast<void const *>(&u), sizeof(u));
|
||||
}
|
||||
};
|
||||
} /* namespace detail */
|
||||
|
@ -379,7 +379,7 @@ namespace detail {
|
|||
Size operator()(T *v) const {
|
||||
union { T *v; Size h; } u;
|
||||
u.v = v;
|
||||
return detail::mem_hash((void const *)&u, sizeof(u));
|
||||
return detail::mem_hash(static_cast<void const *>(&u), sizeof(u));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -544,7 +544,8 @@ namespace detail {
|
|||
struct FunctorDataManager {
|
||||
template<typename R, typename ...Args>
|
||||
static R call(FunctorData const &s, Args ...args) {
|
||||
return ((T &)s)(forward<Args>(args)...);
|
||||
return (*reinterpret_cast<T *>(&const_cast<FunctorData &>(s)))(
|
||||
forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static void store_f(FmStorage &s, T v) {
|
||||
|
@ -573,7 +574,8 @@ namespace detail {
|
|||
struct FunctorDataManager<T, A, EnableIf<!FunctorInPlace<T>>> {
|
||||
template<typename R, typename ...Args>
|
||||
static R call(FunctorData const &s, Args ...args) {
|
||||
return (*(AllocatorPointer<A> &)s)(forward<Args>(args)...);
|
||||
return (*reinterpret_cast<AllocatorPointer<A> &>(
|
||||
const_cast<FunctorData &>(s)))(forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static void store_f(FmStorage &s, T v) {
|
||||
|
@ -601,11 +603,11 @@ namespace detail {
|
|||
}
|
||||
|
||||
static AllocatorPointer<A> &get_ptr_ref(FmStorage &s) {
|
||||
return (AllocatorPointer<A> &)(s.data);
|
||||
return reinterpret_cast<AllocatorPointer<A> &>(s.data);
|
||||
}
|
||||
|
||||
static AllocatorPointer<A> &get_ptr_ref(FmStorage const &s) {
|
||||
return (AllocatorPointer<A> &)(s.data);
|
||||
return reinterpret_cast<AllocatorPointer<A> &>(s.data);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
template<typename U>
|
||||
HashRange(const HashRange<U> &v, EnableIf<
|
||||
IsSame<RemoveCv<T>, RemoveCv<U>> && IsConvertible<U *, T *>, bool
|
||||
> = true): p_node((Chain *)v.p_node) {}
|
||||
> = true): p_node(const_cast<Chain *>(v.p_node)) {}
|
||||
|
||||
HashRange &operator=(const HashRange &v) {
|
||||
p_node = v.p_node;
|
||||
|
@ -95,7 +95,8 @@ public:
|
|||
template<typename U>
|
||||
BucketRange(const BucketRange<U> &v, EnableIf<
|
||||
IsSame<RemoveCv<T>, RemoveCv<U>> && IsConvertible<U *, T *>, bool
|
||||
> = true): p_node((Chain *)v.p_node), p_end((Chain *)v.p_end) {}
|
||||
> = true): p_node(const_cast<Chain *>(v.p_node)),
|
||||
p_end(const_cast<Chain *>(v.p_end)) {}
|
||||
|
||||
BucketRange &operator=(const BucketRange &v) {
|
||||
p_node = v.p_node;
|
||||
|
@ -581,7 +582,7 @@ public:
|
|||
|
||||
ConstRange find(const K &key) const {
|
||||
Size h = 0;
|
||||
return ConstRange((detail::HashChain<const E> *)find(key, h));
|
||||
return ConstRange(reinterpret_cast<detail::HashChain<const E> *>(find(key, h)));
|
||||
}
|
||||
|
||||
float load_factor() const { return float(p_len) / p_size; }
|
||||
|
@ -622,12 +623,12 @@ public:
|
|||
ConstRange iter() const {
|
||||
using Chain = detail::HashChain<const E>;
|
||||
if (!p_len) return ConstRange();
|
||||
return ConstRange((Chain *)*p_data.first());
|
||||
return ConstRange(reinterpret_cast<Chain *>(*p_data.first()));
|
||||
}
|
||||
ConstRange citer() const {
|
||||
using Chain = detail::HashChain<const E>;
|
||||
if (!p_len) return ConstRange();
|
||||
return ConstRange((Chain *)*p_data.first());
|
||||
return ConstRange(reinterpret_cast<Chain *>(*p_data.first()));
|
||||
}
|
||||
|
||||
LocalRange iter(Size n) {
|
||||
|
@ -637,14 +638,14 @@ public:
|
|||
ConstLocalRange iter(Size n) const {
|
||||
using Chain = detail::HashChain<const E>;
|
||||
if (n >= p_size) return ConstLocalRange();
|
||||
return ConstLocalRange((Chain *)p_data.first()[n],
|
||||
(Chain *)p_data.first()[n + 1]);
|
||||
return ConstLocalRange(reinterpret_cast<Chain *>(p_data.first()[n]),
|
||||
reinterpret_cast<Chain *>(p_data.first()[n + 1]));
|
||||
}
|
||||
ConstLocalRange citer(Size n) const {
|
||||
using Chain = detail::HashChain<const E>;
|
||||
if (n >= p_size) return ConstLocalRange();
|
||||
return ConstLocalRange((Chain *)p_data.first()[n],
|
||||
(Chain *)p_data.first()[n + 1]);
|
||||
return ConstLocalRange(reinterpret_cast<Chain *>(p_data.first()[n]),
|
||||
reinterpret_cast<Chain *>(p_data.first()[n + 1]));
|
||||
}
|
||||
};
|
||||
} /* namespace detail */
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace detail {
|
|||
allocator_construct(alloc, &e, forward<U>(key), move(T()));
|
||||
}
|
||||
static inline void swap_elem(Element &a, Element &b) {
|
||||
swap_adl(*((K *)&a.first), *((K *)&b.first));
|
||||
swap_adl(*((T *)&a.second), *((T *)&b.second));
|
||||
swap_adl(const_cast<K &>(a.first), const_cast<K &>(b.first));
|
||||
swap_adl(a.second, b.second);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -532,14 +532,14 @@ template<typename T> struct Allocator {
|
|||
Size max_size() const { return Size(~0) / sizeof(T); }
|
||||
|
||||
Pointer allocate(Size n, Allocator<void>::ConstPointer = nullptr) {
|
||||
return (Pointer) ::new byte[n * sizeof(T)];
|
||||
return reinterpret_cast<Pointer>(::new byte[n * sizeof(T)]);
|
||||
}
|
||||
|
||||
void deallocate(Pointer p, Size) { ::delete[] (byte *) p; }
|
||||
void deallocate(Pointer p, Size) { ::delete[] reinterpret_cast<byte *>(p); }
|
||||
|
||||
template<typename U, typename ...A>
|
||||
void construct(U *p, A &&...args) {
|
||||
::new((void *)p) U(forward<A>(args)...);
|
||||
::new(p) U(forward<A>(args)...);
|
||||
}
|
||||
|
||||
void destroy(Pointer p) { p->~T(); }
|
||||
|
@ -566,14 +566,14 @@ template<typename T> struct Allocator<T const> {
|
|||
Size max_size() const { return Size(~0) / sizeof(T); }
|
||||
|
||||
Pointer allocate(Size n, Allocator<void>::ConstPointer = nullptr) {
|
||||
return (Pointer) ::new byte[n * sizeof(T)];
|
||||
return reinterpret_cast<Pointer>(::new byte[n * sizeof(T)]);
|
||||
}
|
||||
|
||||
void deallocate(Pointer p, Size) { ::delete[] (byte *) p; }
|
||||
void deallocate(Pointer p, Size) { ::delete[] reinterpret_cast<byte *>(p); }
|
||||
|
||||
template<typename U, typename ...A>
|
||||
void construct(U *p, A &&...args) {
|
||||
::new((void *)p) U(forward<A>(args)...);
|
||||
::new(p) U(forward<A>(args)...);
|
||||
}
|
||||
|
||||
void destroy(Pointer p) { p->~T(); }
|
||||
|
@ -927,7 +927,7 @@ namespace detail {
|
|||
|
||||
template<typename A, typename T, typename ...Args>
|
||||
inline void construct(False, A &, T *p, Args &&...args) {
|
||||
::new ((void *)p) T(forward<Args>(args)...);
|
||||
::new (p) T(forward<Args>(args)...);
|
||||
}
|
||||
} /* namespace detail */
|
||||
|
||||
|
|
|
@ -220,8 +220,8 @@ namespace detail {
|
|||
}
|
||||
bool operator!=(RangeIterator) const { return !get_ref().empty(); }
|
||||
private:
|
||||
T &get_ref() { return *((T *)&p_range); }
|
||||
T const &get_ref() const { return *((T *)&p_range); }
|
||||
T &get_ref() { return *reinterpret_cast<T *>(&p_range); }
|
||||
T const &get_ref() const { return *reinterpret_cast<T const *>(&p_range); }
|
||||
AlignedStorage<sizeof(T), alignof(T)> p_range;
|
||||
};
|
||||
}
|
||||
|
@ -438,30 +438,30 @@ template<typename B, typename C, typename V, typename R = V &,
|
|||
using Reference = R;
|
||||
|
||||
detail::RangeIterator<B> begin() const {
|
||||
return detail::RangeIterator<B>((B const &)*this);
|
||||
return detail::RangeIterator<B>(*static_cast<B const *>(this));
|
||||
}
|
||||
detail::RangeIterator<B> end() const {
|
||||
return detail::RangeIterator<B>();
|
||||
}
|
||||
|
||||
Size pop_front_n(Size n) {
|
||||
return detail::pop_front_n<B>(*((B *)this), n);
|
||||
return detail::pop_front_n<B>(*static_cast<B *>(this), n);
|
||||
}
|
||||
|
||||
Size pop_back_n(Size n) {
|
||||
return detail::pop_back_n<B>(*((B *)this), n);
|
||||
return detail::pop_back_n<B>(*static_cast<B *>(this), n);
|
||||
}
|
||||
|
||||
Size push_front_n(Size n) {
|
||||
return detail::push_front_n<B>(*((B *)this), n);
|
||||
return detail::push_front_n<B>(*static_cast<B *>(this), n);
|
||||
}
|
||||
|
||||
Size push_back_n(Size n) {
|
||||
return detail::push_back_n<B>(*((B *)this), n);
|
||||
return detail::push_back_n<B>(*static_cast<B *>(this), n);
|
||||
}
|
||||
|
||||
B iter() const {
|
||||
return B(*((B *)this));
|
||||
return B(*static_cast<B const *>(this));
|
||||
}
|
||||
|
||||
ReverseRange<B> reverse() const {
|
||||
|
@ -499,7 +499,7 @@ template<typename B, typename C, typename V, typename R = V &,
|
|||
}
|
||||
|
||||
Size put_n(Value const *p, Size n) {
|
||||
B &r = *((B *)this);
|
||||
B &r = *static_cast<B *>(this);
|
||||
Size on = n;
|
||||
for (; n && r.put(*p++); --n);
|
||||
return (on - n);
|
||||
|
@ -507,7 +507,7 @@ template<typename B, typename C, typename V, typename R = V &,
|
|||
|
||||
template<typename OR>
|
||||
EnableIf<IsOutputRange<OR>, Size> copy(OR &&orange, Size n = -1) {
|
||||
B r(*((B *)this));
|
||||
B r(*static_cast<B const *>(this));
|
||||
Size on = n;
|
||||
for (; n && !r.empty(); --n) {
|
||||
if (!orange.put(r.front()))
|
||||
|
@ -518,7 +518,7 @@ template<typename B, typename C, typename V, typename R = V &,
|
|||
}
|
||||
|
||||
Size copy(RemoveCv<Value> *p, Size n = -1) {
|
||||
B r(*((B *)this));
|
||||
B r(*static_cast<B const *>(this));
|
||||
Size on = n;
|
||||
for (; n && !r.empty(); --n) {
|
||||
*p++ = r.front();
|
||||
|
@ -531,52 +531,54 @@ template<typename B, typename C, typename V, typename R = V &,
|
|||
* this is sometimes convenient as it can be used within expressions */
|
||||
|
||||
Reference operator*() const {
|
||||
return ((B *)this)->front();
|
||||
return static_cast<B const *>(this)->front();
|
||||
}
|
||||
|
||||
B &operator++() {
|
||||
((B *)this)->pop_front();
|
||||
return *((B *)this);
|
||||
static_cast<B *>(this)->pop_front();
|
||||
return *static_cast<B *>(this);
|
||||
}
|
||||
B operator++(int) {
|
||||
B tmp(*((B const *)this));
|
||||
((B *)this)->pop_front();
|
||||
B tmp(*static_cast<B const *>(this));
|
||||
static_cast<B *>(this)->pop_front();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
B &operator--() {
|
||||
((B *)this)->push_front();
|
||||
return *((B *)this);
|
||||
static_cast<B *>(this)->push_front();
|
||||
return *static_cast<B *>(this);
|
||||
}
|
||||
B operator--(int) {
|
||||
B tmp(*((B const *)this));
|
||||
((B *)this)->push_front();
|
||||
B tmp(*static_cast<B const *>(this));
|
||||
static_cast<B *>(this)->push_front();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
B operator+(Difference n) const {
|
||||
B tmp(*((B const *)this));
|
||||
B tmp(*static_cast<B const *>(this));
|
||||
tmp.pop_front_n(n);
|
||||
return tmp;
|
||||
}
|
||||
B operator-(Difference n) const {
|
||||
B tmp(*((B const *)this));
|
||||
B tmp(*static_cast<B const *>(this));
|
||||
tmp.push_front_n(n);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
B &operator+=(Difference n) {
|
||||
((B *)this)->pop_front_n(n);
|
||||
return *((B *)this);
|
||||
static_cast<B *>(this)->pop_front_n(n);
|
||||
return *static_cast<B *>(this);
|
||||
}
|
||||
B &operator-=(Difference n) {
|
||||
((B *)this)->push_front_n(n);
|
||||
return *((B *)this);
|
||||
static_cast<B *>(this)->push_front_n(n);
|
||||
return *static_cast<B *>(this);
|
||||
}
|
||||
|
||||
/* universal bool operator */
|
||||
|
||||
explicit operator bool() const { return !((B *)this)->empty(); }
|
||||
explicit operator bool() const {
|
||||
return !(static_cast<B const *>(this)->empty());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename R, typename F, typename = EnableIf<IsInputRange<R>>>
|
||||
|
@ -677,7 +679,7 @@ template<typename B, typename V, typename R = V &,
|
|||
using Reference = R;
|
||||
|
||||
Size put_n(Value const *p, Size n) {
|
||||
B &r = *((B *)this);
|
||||
B &r = *static_cast<B *>(this);
|
||||
Size on = n;
|
||||
for (; n && r.put(*p++); --n);
|
||||
return (on - n);
|
||||
|
|
|
@ -40,7 +40,8 @@ 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()): p_beg(beg), p_end((T *)beg + (beg ? strlen(beg) : 0)) {}
|
||||
= Nat()): p_beg(beg), p_end(static_cast<T *>(beg)
|
||||
+ (beg ? strlen(beg) : 0)) {}
|
||||
|
||||
CharRangeBase(Nullptr): p_beg(nullptr), p_end(nullptr) {}
|
||||
|
||||
|
@ -262,7 +263,7 @@ public:
|
|||
using Allocator = A;
|
||||
|
||||
StringBase(A const &a = A()): p_len(0), p_cap(0),
|
||||
p_buf((Pointer)&p_len, a) {}
|
||||
p_buf(reinterpret_cast<Pointer>(&p_len), a) {}
|
||||
|
||||
explicit StringBase(Size n, T val = T(), A const &al = A()):
|
||||
StringBase(al) {
|
||||
|
@ -275,14 +276,15 @@ public:
|
|||
}
|
||||
|
||||
StringBase(StringBase const &s): p_len(0), p_cap(0),
|
||||
p_buf((Pointer)&p_len, allocator_container_copy(s.p_buf.second())) {
|
||||
p_buf(reinterpret_cast<Pointer>(&p_len),
|
||||
allocator_container_copy(s.p_buf.second())) {
|
||||
if (!s.p_len) return;
|
||||
reserve(s.p_len);
|
||||
p_len = s.p_len;
|
||||
memcpy(p_buf.first(), s.p_buf.first(), (p_len + 1) * sizeof(T));
|
||||
}
|
||||
StringBase(StringBase const &s, A const &a): p_len(0), p_cap(0),
|
||||
p_buf((Pointer)&p_len, a) {
|
||||
p_buf(reinterpret_cast<Pointer>(&p_len), a) {
|
||||
if (!s.p_len) return;
|
||||
reserve(s.p_len);
|
||||
p_len = s.p_len;
|
||||
|
@ -291,10 +293,10 @@ public:
|
|||
StringBase(StringBase &&s): p_len(s.p_len), p_cap(s.p_cap),
|
||||
p_buf(s.p_buf.first(), move(s.p_buf.second())) {
|
||||
s.p_len = s.p_cap = 0;
|
||||
s.p_buf.first() = (Pointer)&s.p_len;
|
||||
s.p_buf.first() = reinterpret_cast<Pointer>(&s.p_len);
|
||||
}
|
||||
StringBase(StringBase &&s, A const &a): p_len(0), p_cap(0),
|
||||
p_buf((Pointer)&p_len, a) {
|
||||
p_buf(reinterpret_cast<Pointer>(&p_len), a) {
|
||||
if (!s.p_len) return;
|
||||
if (a != s.p_buf.second()) {
|
||||
reserve(s.p_cap);
|
||||
|
@ -362,7 +364,7 @@ public:
|
|||
if ((p_buf.second() != v.p_buf.second()) && p_cap) {
|
||||
allocator_deallocate(p_buf.second(), p_buf.first(), p_cap);
|
||||
p_cap = 0;
|
||||
p_buf.first() = (Pointer)&p_len;
|
||||
p_buf.first() = reinterpret_cast<Pointer>(&p_len);
|
||||
}
|
||||
p_buf.second() = v.p_buf.second();
|
||||
}
|
||||
|
@ -371,7 +373,7 @@ public:
|
|||
if (p_len) {
|
||||
memcpy(p_buf.first(), v.p_buf.first(), p_len);
|
||||
p_buf.first()[p_len] = '\0';
|
||||
} else p_buf.first() = (Pointer)&p_len;
|
||||
} else p_buf.first() = reinterpret_cast<Pointer>(&p_len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -384,7 +386,7 @@ public:
|
|||
p_cap = v.p_cap;
|
||||
p_buf.~StrPair();
|
||||
new (&p_buf) StrPair(v.disown(), move(v.p_buf.second()));
|
||||
if (!p_cap) p_buf.first() = (Pointer)&p_len;
|
||||
if (!p_cap) p_buf.first() = reinterpret_cast<Pointer>(&p_len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -483,7 +485,7 @@ public:
|
|||
Pointer r = p_buf.first();
|
||||
p_buf.first() = nullptr;
|
||||
p_len = p_cap = 0;
|
||||
return (Value *)r;
|
||||
return reinterpret_cast<Value *>(r);
|
||||
}
|
||||
|
||||
void push(T v) {
|
||||
|
@ -736,14 +738,14 @@ namespace detail {
|
|||
int n = snprintf(buf, sizeof(buf), fmt, v);
|
||||
s.clear();
|
||||
s.reserve(n);
|
||||
if (n >= (int)sizeof(buf))
|
||||
if (n >= int(sizeof(buf)))
|
||||
snprintf(s.data(), n + 1, fmt, v);
|
||||
else if (n > 0)
|
||||
memcpy(s.data(), buf, n + 1);
|
||||
else {
|
||||
s.clear();
|
||||
}
|
||||
*((Size *)&s) = n;
|
||||
*reinterpret_cast<Size *>(&s) = n;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace detail {
|
|||
|
||||
template<typename F>
|
||||
inline void *thread_proxy(void *ptr) {
|
||||
Box<F> fptr((F *)ptr);
|
||||
Box<F> fptr(static_cast<F *>(ptr));
|
||||
using Index = detail::MakeTupleIndices<TupleSize<F>, 1>;
|
||||
detail::thread_exec(*fptr, Index());
|
||||
return nullptr;
|
||||
|
|
|
@ -163,8 +163,8 @@ namespace detail {
|
|||
swap_adl(get(), t.get());
|
||||
}
|
||||
|
||||
H &get() { return (H &)*this; }
|
||||
H const &get() const { return (H const &)*this; }
|
||||
H &get() { return *static_cast<H *>(this); }
|
||||
H const &get() const { return *static_cast<H const *>(this); }
|
||||
|
||||
private:
|
||||
TupleLeaf &operator=(TupleLeaf const &);
|
||||
|
@ -246,19 +246,19 @@ namespace detail {
|
|||
TupleBase(TupleBase &&) = default;
|
||||
|
||||
TupleBase &operator=(TupleBase const &t) {
|
||||
tuple_swallow(TupleLeaf<I, A>::operator=(((TupleLeaf<I,A>
|
||||
const &)t).get())...);
|
||||
tuple_swallow(TupleLeaf<I, A>::operator=((
|
||||
static_cast<TupleLeaf<I, A> const &>(t)).get())...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TupleBase &operator=(TupleBase &&t) {
|
||||
tuple_swallow(TupleLeaf<I, A>::operator=(forward<A>
|
||||
(((TupleLeaf<I, A> const &)t).get()))...);
|
||||
((static_cast<TupleLeaf<I, A> &>(t)).get()))...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(TupleBase &t) {
|
||||
tuple_swallow(TupleLeaf<I, A>::swap((TupleLeaf<I, A> &)t)...);
|
||||
tuple_swallow(TupleLeaf<I, A>::swap(static_cast<TupleLeaf<I, A> &>(t))...);
|
||||
}
|
||||
};
|
||||
} /* namespace detail */
|
||||
|
@ -412,25 +412,27 @@ public:
|
|||
template<Size I, typename ...A>
|
||||
inline TupleElement<I, Tuple<A...>> &get(Tuple<A...> &t) {
|
||||
using Type = TupleElement<I, Tuple<A...>>;
|
||||
return ((detail::TupleLeaf<I, Type> &)t.p_base).get();
|
||||
return static_cast<detail::TupleLeaf<I, Type> &>(t.p_base).get();
|
||||
}
|
||||
|
||||
template<Size I, typename ...A>
|
||||
inline TupleElement<I, Tuple<A...>> const &get(Tuple<A...> const &t) {
|
||||
using Type = TupleElement<I, Tuple<A...>>;
|
||||
return ((detail::TupleLeaf<I, Type> const &)t.p_base).get();
|
||||
return static_cast<detail::TupleLeaf<I, Type> const &>(t.p_base).get();
|
||||
}
|
||||
|
||||
template<Size I, typename ...A>
|
||||
inline TupleElement<I, Tuple<A...>> &&get(Tuple<A...> &&t) {
|
||||
using Type = TupleElement<I, Tuple<A...>>;
|
||||
return (Type &&)(((detail::TupleLeaf<I, Type> &&)t.p_base).get());
|
||||
return static_cast<Type &&>(
|
||||
static_cast<detail::TupleLeaf<I, Type> &&>(t.p_base).get());
|
||||
}
|
||||
|
||||
template<Size I, typename ...A>
|
||||
inline TupleElement<I, Tuple<A...>> const &&get(Tuple<A...> const &&t) {
|
||||
using Type = TupleElement<I, Tuple<A...>>;
|
||||
return (Type const &&)(((detail::TupleLeaf<I, Type> const &&)t.p_base).get());
|
||||
return static_cast<Type const &&>(
|
||||
static_cast<detail::TupleLeaf<I, Type> const &&>(t.p_base).get());
|
||||
}
|
||||
|
||||
/* tie */
|
||||
|
|
|
@ -335,8 +335,10 @@ public:
|
|||
T &back() { return p_buf.first()[p_len - 1]; }
|
||||
T const &back() const { return p_buf.first()[p_len - 1]; }
|
||||
|
||||
Value *data() { return (Value *)p_buf.first(); }
|
||||
Value const *data() const { return (Value const *)p_buf.first(); }
|
||||
Value *data() { return reinterpret_cast<Value *>(p_buf.first()); }
|
||||
Value const *data() const {
|
||||
return reinterpret_cast<Value const *>(p_buf.first());
|
||||
}
|
||||
|
||||
Size size() const { return p_len; }
|
||||
Size capacity() const { return p_cap; }
|
||||
|
@ -357,7 +359,7 @@ public:
|
|||
Pointer r = p_buf.first();
|
||||
p_buf.first() = nullptr;
|
||||
p_len = p_cap = 0;
|
||||
return (Value *)r;
|
||||
return reinterpret_cast<Value *>(r);
|
||||
}
|
||||
|
||||
Range insert(Size idx, T &&v) {
|
||||
|
|
|
@ -25,7 +25,7 @@ int main() {
|
|||
/* configurable section */
|
||||
|
||||
auto compiler = environ::get("CXX").value_or("c++");
|
||||
auto cxxflags = "-std=c++14 -I. -Wall -Wextra -Wshadow "
|
||||
auto cxxflags = "-std=c++14 -I. -Wall -Wextra -Wshadow -Wold-style-cast "
|
||||
"-Wno-missing-braces"; /* clang false positive */
|
||||
auto testdir = environ::get("TESTDIR").value_or("tests");
|
||||
auto srcext = ".cc";
|
||||
|
|
Loading…
Reference in New Issue