coding style

master
Daniel Kolesa 2015-05-03 23:44:48 +01:00
parent 6a9d3b8ea7
commit 98e7566ad9
6 changed files with 106 additions and 106 deletions

View File

@ -13,15 +13,15 @@
namespace octa { namespace octa {
template<typename T, size_t N> template<typename T, size_t N>
struct Array { struct Array {
typedef size_t size_type; typedef size_t SizeType;
typedef ptrdiff_t difference_type; typedef ptrdiff_t DiffType;
typedef T value_type; typedef T ValType;
typedef T &reference; typedef T &RefType;
typedef const T &const_reference; typedef const T &ConstRefType;
typedef T *pointer; typedef T *PtrType;
typedef const T *const_pointer; typedef const T *ConstPtrType;
typedef PointerRange< T> range; typedef PointerRange< T> RangeType;
typedef PointerRange<const T> const_range; typedef PointerRange<const T> ConstRangeType;
T &operator[](size_t i) noexcept { return p_buf[i]; } T &operator[](size_t i) noexcept { return p_buf[i]; }
const T &operator[](size_t i) const noexcept { return p_buf[i]; } const T &operator[](size_t i) const noexcept { return p_buf[i]; }
@ -45,10 +45,10 @@ namespace octa {
swap(p_buf, v.p_buf); swap(p_buf, v.p_buf);
} }
range each() noexcept { RangeType each() noexcept {
return PointerRange<T>(p_buf, p_buf + N); return PointerRange<T>(p_buf, p_buf + N);
} }
const_range each() const noexcept { ConstRangeType each() const noexcept {
return PointerRange<const T>(p_buf, p_buf + N); return PointerRange<const T>(p_buf, p_buf + N);
} }

View File

@ -19,9 +19,9 @@ namespace octa {
bool operator()(const T &x, const T &y) const noexcept( \ bool operator()(const T &x, const T &y) const noexcept( \
noexcept(x op y) \ noexcept(x op y) \
) { return x op y; } \ ) { return x op y; } \
typedef T first_argument_type; \ typedef T FirstArgType; \
typedef T second_argument_type; \ typedef T SecondArgType; \
typedef rettype result_type; \ typedef rettype ResultType; \
}; };
__OCTA_DEFINE_BINARY_OP(Less, <, bool) __OCTA_DEFINE_BINARY_OP(Less, <, bool)
@ -45,27 +45,27 @@ namespace octa {
template<typename T> struct LogicalNot { template<typename T> struct LogicalNot {
bool operator()(const T &x) const noexcept(noexcept(!x)) { return !x; } bool operator()(const T &x) const noexcept(noexcept(!x)) { return !x; }
typedef T argument_type; typedef T ArgType;
typedef bool result_type; typedef bool ResultType;
}; };
template<typename T> struct Negate { template<typename T> struct Negate {
bool operator()(const T &x) const noexcept(noexcept(-x)) { return -x; } bool operator()(const T &x) const noexcept(noexcept(-x)) { return -x; }
typedef T argument_type; typedef T ArgType;
typedef T result_type; typedef T ResultType;
}; };
template<typename T> struct BinaryNegate { template<typename T> struct BinaryNegate {
typedef typename T::first_argument_type first_argument_type; typedef typename T::FirstArgType FirstArgType;
typedef typename T::second_argument_type second_argument_type; typedef typename T::SecondArgType SecondArgType;
typedef bool result_type; typedef bool ResultType;
explicit BinaryNegate(const T &f) noexcept( explicit BinaryNegate(const T &f) noexcept(
IsNothrowCopyConstructible<T>::value IsNothrowCopyConstructible<T>::value
): p_fn(f) {} ): p_fn(f) {}
bool operator()(const first_argument_type &x, bool operator()(const FirstArgType &x,
const second_argument_type &y) noexcept( const SecondArgType &y) noexcept(
noexcept(p_fn(x, y)) noexcept(p_fn(x, y))
) { ) {
return !p_fn(x, y); return !p_fn(x, y);
@ -75,13 +75,13 @@ namespace octa {
}; };
template<typename T> struct UnaryNegate { template<typename T> struct UnaryNegate {
typedef typename T::argument_type argument_type; typedef typename T::ArgType ArgType;
typedef bool result_type; typedef bool ResultType;
explicit UnaryNegate(const T &f) noexcept( explicit UnaryNegate(const T &f) noexcept(
IsNothrowCopyConstructible<T>::value IsNothrowCopyConstructible<T>::value
): p_fn(f) {} ): p_fn(f) {}
bool operator()(const argument_type &x) noexcept(noexcept(p_fn(x))) { bool operator()(const ArgType &x) noexcept(noexcept(p_fn(x))) {
return !p_fn(x); return !p_fn(x);
} }
private: private:
@ -144,25 +144,25 @@ namespace octa {
template<typename, typename> struct __OctaMemTypes; template<typename, typename> struct __OctaMemTypes;
template<typename T, typename R, typename ...A> template<typename T, typename R, typename ...A>
struct __OctaMemTypes<T, R(A...)> { struct __OctaMemTypes<T, R(A...)> {
typedef R result_type; typedef R ResultType;
typedef T argument_type; typedef T ArgType;
}; };
template<typename T, typename R, typename A> template<typename T, typename R, typename A>
struct __OctaMemTypes<T, R(A)> { struct __OctaMemTypes<T, R(A)> {
typedef R result_type; typedef R ResultType;
typedef T first_argument_type; typedef T FirstArgType;
typedef A second_argument_type; typedef A SecondArgType;
}; };
template<typename T, typename R, typename ...A> template<typename T, typename R, typename ...A>
struct __OctaMemTypes<T, R(A...) const> { struct __OctaMemTypes<T, R(A...) const> {
typedef R result_type; typedef R ResultType;
typedef const T argument_type; typedef const T ArgType;
}; };
template<typename T, typename R, typename A> template<typename T, typename R, typename A>
struct __OctaMemTypes<T, R(A) const> { struct __OctaMemTypes<T, R(A) const> {
typedef R result_type; typedef R ResultType;
typedef const T first_argument_type; typedef const T FirstArgType;
typedef A second_argument_type; typedef A SecondArgType;
}; };
template<typename R, typename T> template<typename R, typename T>
@ -333,20 +333,20 @@ namespace octa {
template<typename R, typename...> template<typename R, typename...>
struct __OctaFunction { struct __OctaFunction {
typedef R result_type; typedef R ResultType;
}; };
template<typename R, typename T> template<typename R, typename T>
struct __OctaFunction<R, T> { struct __OctaFunction<R, T> {
typedef R result_type; typedef R ResultType;
typedef T argument_type; typedef T ArgType;
}; };
template<typename R, typename T, typename U> template<typename R, typename T, typename U>
struct __OctaFunction<R, T, U> { struct __OctaFunction<R, T, U> {
typedef R result_type; typedef R ResultType;
typedef T first_argument_type; typedef T FirstArgType;
typedef U second_argument_type; typedef U SecondArgType;
}; };
template<typename, typename> template<typename, typename>

View File

@ -19,13 +19,13 @@ namespace std {
initializer_list(const T *v, size_t n) noexcept: p_buf(v), p_len(n) {} initializer_list(const T *v, size_t n) noexcept: p_buf(v), p_len(n) {}
public: public:
typedef size_t size_type; typedef size_t SizeType;
typedef ptrdiff_t difference_type; typedef ptrdiff_t DiffType;
typedef T value_type; typedef T ValType;
typedef T &reference; typedef T &RefType;
typedef const T &const_reference; typedef const T &ConstRefType;
typedef T *pointer; typedef T *PtrType;
typedef const T *const_pointer; typedef const T *ConstPtrType;
initializer_list() noexcept: p_buf(nullptr), p_len(0) {} initializer_list() noexcept: p_buf(nullptr), p_len(0) {}

View File

@ -47,7 +47,7 @@ namespace octa {
}; };
template<typename T> template<typename T>
struct __OctaHasDifferenceType { struct __OctaHasDiffType {
template<typename U> template<typename U>
static int __octa_test(...); static int __octa_test(...);
template<typename U> template<typename U>
@ -56,12 +56,12 @@ namespace octa {
static constexpr bool value = (sizeof(__octa_test<T>(0)) == 1); static constexpr bool value = (sizeof(__octa_test<T>(0)) == 1);
}; };
template<typename T, bool = __OctaHasDifferenceType<T>::value> template<typename T, bool = __OctaHasDiffType<T>::value>
struct __OctaPtrTraitsDifferenceType { struct __OctaPtrTraitsDiffType {
typedef ptrdiff_t type; typedef ptrdiff_t type;
}; };
template<typename T> struct __OctaPtrTraitsDifferenceType<T, true> { template<typename T> struct __OctaPtrTraitsDiffType<T, true> {
typedef typename T::difference_type type; typedef typename T::difference_type type;
}; };
@ -105,7 +105,7 @@ namespace octa {
}; };
template<typename T> template<typename T>
using PointerType = typename __OctaPtrTraitsPointer<T>::type; using PtrType = typename __OctaPtrTraitsPointer<T>::type;
template<typename T> template<typename T>
struct __OctaPtrTraitsElement { struct __OctaPtrTraitsElement {
@ -122,7 +122,7 @@ namespace octa {
template<typename T> template<typename T>
struct __OctaPtrTraitsDifference { struct __OctaPtrTraitsDifference {
typedef typename __OctaPtrTraitsDifferenceType<T>::type type; typedef typename __OctaPtrTraitsDiffType<T>::type type;
}; };
@ -242,7 +242,7 @@ namespace octa {
template<typename T> template<typename T>
static int __octa_ptr_test(...); static int __octa_ptr_test(...);
template<typename T> template<typename T>
static char __octa_ptr_test(typename T::PointerType * = 0); static char __octa_ptr_test(typename T::PtrType * = 0);
template<typename T> struct __OctaHasPtr: IntegralConstant<bool, template<typename T> struct __OctaHasPtr: IntegralConstant<bool,
(sizeof(__octa_ptr_test<T>(0)) == 1) (sizeof(__octa_ptr_test<T>(0)) == 1)
@ -250,7 +250,7 @@ namespace octa {
template<typename T, typename D, bool = __OctaHasPtr<D>::value> template<typename T, typename D, bool = __OctaHasPtr<D>::value>
struct __OctaPtrTypeBase { struct __OctaPtrTypeBase {
typedef typename D::PointerType type; typedef typename D::PtrType type;
}; };
template<typename T, typename D> struct __OctaPtrTypeBase<T, D, false> { template<typename T, typename D> struct __OctaPtrTypeBase<T, D, false> {
@ -265,7 +265,7 @@ namespace octa {
struct Box { struct Box {
typedef T ElementType; typedef T ElementType;
typedef D DeleterType; typedef D DeleterType;
typedef typename __OctaPtrType<T, D>::type PointerType; typedef typename __OctaPtrType<T, D>::type PtrType;
private: private:
struct __OctaNat { int x; }; struct __OctaNat { int x; };
@ -283,16 +283,16 @@ namespace octa {
"Box constructed with null fptr deleter"); "Box constructed with null fptr deleter");
} }
explicit Box(PointerType p) noexcept: p_stor(p, D()) { explicit Box(PtrType p) noexcept: p_stor(p, D()) {
static_assert(!IsPointer<D>::value, static_assert(!IsPointer<D>::value,
"Box constructed with null fptr deleter"); "Box constructed with null fptr deleter");
} }
Box(PointerType p, Conditional<IsReference<D>::value, Box(PtrType p, Conditional<IsReference<D>::value,
D, AddLvalueReference<const D> D, AddLvalueReference<const D>
> d) noexcept: p_stor(p, d) {} > d) noexcept: p_stor(p, d) {}
Box(PointerType p, RemoveReference<D> &&d) noexcept: p_stor(p, move(d)) { Box(PtrType p, RemoveReference<D> &&d) noexcept: p_stor(p, move(d)) {
static_assert(!IsReference<D>::value, static_assert(!IsReference<D>::value,
"rvalue deleter cannot be a ref"); "rvalue deleter cannot be a ref");
} }
@ -301,7 +301,7 @@ namespace octa {
template<typename TT, typename DD> template<typename TT, typename DD>
Box(Box<TT, DD> &&u, EnableIf<!IsArray<TT>::value Box(Box<TT, DD> &&u, EnableIf<!IsArray<TT>::value
&& IsConvertible<typename Box<TT, DD>::PointerType, PointerType>::value && IsConvertible<typename Box<TT, DD>::PtrType, PtrType>::value
&& IsConvertible<DD, D>::value && IsConvertible<DD, D>::value
&& (!IsReference<D>::value || IsSame<D, DD>::value) && (!IsReference<D>::value || IsSame<D, DD>::value)
> = __OctaNat()) noexcept: p_stor(u.release(), > = __OctaNat()) noexcept: p_stor(u.release(),
@ -315,7 +315,7 @@ namespace octa {
template<typename TT, typename DD> template<typename TT, typename DD>
EnableIf<!IsArray<TT>::value EnableIf<!IsArray<TT>::value
&& IsConvertible<typename Box<TT, DD>::PointerType, PointerType>::value && IsConvertible<typename Box<TT, DD>::PtrType, PtrType>::value
&& IsAssignable<D &, DD &&>::value, && IsAssignable<D &, DD &&>::value,
Box & Box &
> operator=(Box<TT, DD> &&u) noexcept { > operator=(Box<TT, DD> &&u) noexcept {
@ -332,25 +332,25 @@ namespace octa {
~Box() { reset(); } ~Box() { reset(); }
AddLvalueReference<T> operator*() const { return *p_stor.i_ptr; } AddLvalueReference<T> operator*() const { return *p_stor.i_ptr; }
PointerType operator->() const noexcept { return p_stor.i_ptr; } PtrType operator->() const noexcept { return p_stor.i_ptr; }
explicit operator bool() const noexcept { explicit operator bool() const noexcept {
return p_stor.i_ptr != nullptr; return p_stor.i_ptr != nullptr;
} }
PointerType get() const noexcept { return p_stor.i_ptr; } PtrType get() const noexcept { return p_stor.i_ptr; }
D_ref get_deleter() noexcept { return p_stor.get_deleter(); } D_ref get_deleter() noexcept { return p_stor.get_deleter(); }
D_cref get_deleter() const noexcept { return p_stor.get_deleter(); } D_cref get_deleter() const noexcept { return p_stor.get_deleter(); }
PointerType release() noexcept { PtrType release() noexcept {
PointerType p = p_stor.i_ptr; PtrType p = p_stor.i_ptr;
p_stor.i_ptr = nullptr; p_stor.i_ptr = nullptr;
return p; return p;
} }
void reset(PointerType p = nullptr) noexcept { void reset(PtrType p = nullptr) noexcept {
PointerType tmp = p_stor.i_ptr; PtrType tmp = p_stor.i_ptr;
p_stor.i_ptr = p; p_stor.i_ptr = p;
if (tmp) p_stor.get_deleter()(tmp); if (tmp) p_stor.get_deleter()(tmp);
} }
@ -382,7 +382,7 @@ namespace octa {
struct Box<T[], D> { struct Box<T[], D> {
typedef T ElementType; typedef T ElementType;
typedef D DeleterType; typedef D DeleterType;
typedef typename __OctaPtrType<T, D>::type PointerType; typedef typename __OctaPtrType<T, D>::type PtrType;
private: private:
struct __OctaNat { int x; }; struct __OctaNat { int x; };
@ -401,7 +401,7 @@ namespace octa {
} }
template<typename U> explicit Box(U p, EnableIf< template<typename U> explicit Box(U p, EnableIf<
__OctaSameOrLessCvQualified<U, PointerType>::value, __OctaNat __OctaSameOrLessCvQualified<U, PtrType>::value, __OctaNat
> = __OctaNat()) noexcept: p_stor(p, D()) { > = __OctaNat()) noexcept: p_stor(p, D()) {
static_assert(!IsPointer<D>::value, static_assert(!IsPointer<D>::value,
"Box constructed with null fptr deleter"); "Box constructed with null fptr deleter");
@ -409,7 +409,7 @@ namespace octa {
template<typename U> Box(U p, Conditional<IsReference<D>::value, template<typename U> Box(U p, Conditional<IsReference<D>::value,
D, AddLvalueReference<const D> D, AddLvalueReference<const D>
> d, EnableIf<__OctaSameOrLessCvQualified<U, PointerType>::value, __OctaNat > d, EnableIf<__OctaSameOrLessCvQualified<U, PtrType>::value, __OctaNat
> = __OctaNat()) noexcept: p_stor(p, d) {} > = __OctaNat()) noexcept: p_stor(p, d) {}
Box(nullptr_t, Conditional<IsReference<D>::value, Box(nullptr_t, Conditional<IsReference<D>::value,
@ -417,7 +417,7 @@ namespace octa {
> d) noexcept: p_stor(nullptr, d) {} > d) noexcept: p_stor(nullptr, d) {}
template<typename U> Box(U p, RemoveReference<D> &&d, EnableIf< template<typename U> Box(U p, RemoveReference<D> &&d, EnableIf<
__OctaSameOrLessCvQualified<U, PointerType>::value, __OctaNat __OctaSameOrLessCvQualified<U, PtrType>::value, __OctaNat
> = __OctaNat()) noexcept: p_stor(p, move(d)) { > = __OctaNat()) noexcept: p_stor(p, move(d)) {
static_assert(!IsReference<D>::value, static_assert(!IsReference<D>::value,
"rvalue deleter cannot be a ref"); "rvalue deleter cannot be a ref");
@ -432,8 +432,8 @@ namespace octa {
template<typename TT, typename DD> template<typename TT, typename DD>
Box(Box<TT, DD> &&u, EnableIf<IsArray<TT>::value Box(Box<TT, DD> &&u, EnableIf<IsArray<TT>::value
&& __OctaSameOrLessCvQualified<typename Box<TT, DD>::PointerType, && __OctaSameOrLessCvQualified<typename Box<TT, DD>::PtrType,
PointerType>::value PtrType>::value
&& IsConvertible<DD, D>::value && IsConvertible<DD, D>::value
&& (!IsReference<D>::value || IsSame<D, DD>::value)> = __OctaNat() && (!IsReference<D>::value || IsSame<D, DD>::value)> = __OctaNat()
) noexcept: p_stor(u.release(), forward<DD>(u.get_deleter())) {} ) noexcept: p_stor(u.release(), forward<DD>(u.get_deleter())) {}
@ -446,8 +446,8 @@ namespace octa {
template<typename TT, typename DD> template<typename TT, typename DD>
EnableIf<IsArray<TT>::value EnableIf<IsArray<TT>::value
&& __OctaSameOrLessCvQualified<typename Box<TT, DD>::PointerType, && __OctaSameOrLessCvQualified<typename Box<TT, DD>::PtrType,
PointerType>::value PtrType>::value
&& IsAssignable<D &, DD &&>::value, && IsAssignable<D &, DD &&>::value,
Box & Box &
> operator=(Box<TT, DD> &&u) noexcept { > operator=(Box<TT, DD> &&u) noexcept {
@ -471,27 +471,27 @@ namespace octa {
return p_stor.i_ptr != nullptr; return p_stor.i_ptr != nullptr;
} }
PointerType get() const noexcept { return p_stor.i_ptr; } PtrType get() const noexcept { return p_stor.i_ptr; }
D_ref get_deleter() noexcept { return p_stor.get_deleter(); } D_ref get_deleter() noexcept { return p_stor.get_deleter(); }
D_cref get_deleter() const noexcept { return p_stor.get_deleter(); } D_cref get_deleter() const noexcept { return p_stor.get_deleter(); }
PointerType release() noexcept { PtrType release() noexcept {
PointerType p = p_stor.i_ptr; PtrType p = p_stor.i_ptr;
p_stor.i_ptr = nullptr; p_stor.i_ptr = nullptr;
return p; return p;
} }
template<typename U> EnableIf< template<typename U> EnableIf<
__OctaSameOrLessCvQualified<U, PointerType>::value, void __OctaSameOrLessCvQualified<U, PtrType>::value, void
> reset(U p) noexcept { > reset(U p) noexcept {
PointerType tmp = p_stor.i_ptr; PtrType tmp = p_stor.i_ptr;
p_stor.i_ptr = p; p_stor.i_ptr = p;
if (tmp) p_stor.get_deleter()(tmp); if (tmp) p_stor.get_deleter()(tmp);
} }
void reset(nullptr_t) noexcept { void reset(nullptr_t) noexcept {
PointerType tmp = p_stor.i_ptr; PtrType tmp = p_stor.i_ptr;
p_stor.i_ptr = nullptr; p_stor.i_ptr = nullptr;
if (tmp) p_stor.get_deleter()(tmp); if (tmp) p_stor.get_deleter()(tmp);
} }

View File

@ -19,10 +19,10 @@ namespace octa {
struct BidirectionalRangeTag {}; struct BidirectionalRangeTag {};
struct RandomAccessRangeTag {}; struct RandomAccessRangeTag {};
template<typename T> using RangeCategory = typename T::range_category; template<typename T> using RangeCategory = typename T::Category;
template<typename T> using RangeSize = typename T::size_type; template<typename T> using RangeSize = typename T::SizeType;
template<typename T> using RangeValue = typename T::value_type; template<typename T> using RangeValue = typename T::ValType;
template<typename T> using RangeReference = typename T::reference; template<typename T> using RangeReference = typename T::RefType;
template<typename T> template<typename T>
struct __OctaRangeIterator { struct __OctaRangeIterator {
@ -47,10 +47,10 @@ namespace octa {
template<typename B, typename C, typename V, typename R = V &, template<typename B, typename C, typename V, typename R = V &,
typename S = size_t typename S = size_t
> struct InputRange { > struct InputRange {
typedef C range_category; typedef C Category;
typedef S size_type; typedef S SizeType;
typedef V value_type; typedef V ValType;
typedef R reference; typedef R RefType;
__OctaRangeIterator<B> begin() noexcept( __OctaRangeIterator<B> begin() noexcept(
IsNothrowCopyConstructible<B>::value IsNothrowCopyConstructible<B>::value
@ -66,10 +66,10 @@ namespace octa {
template<typename V, typename R = V &, typename S = size_t> template<typename V, typename R = V &, typename S = size_t>
struct OutputRange { struct OutputRange {
typedef OutputRangeTag range_category; typedef OutputRangeTag Category;
typedef S size_type; typedef S SizeType;
typedef V value_type; typedef V ValType;
typedef R reference; typedef R RefType;
}; };
template<typename T> template<typename T>

View File

@ -37,15 +37,15 @@ namespace octa {
public: public:
enum { MIN_SIZE = 8 }; enum { MIN_SIZE = 8 };
typedef size_t size_type; typedef size_t SizeType;
typedef ptrdiff_t difference_type; typedef ptrdiff_t DiffType;
typedef T value_type; typedef T ValType;
typedef T &reference; typedef T &RefType;
typedef const T &const_reference; typedef const T &ConstRefType;
typedef T *pointer; typedef T *PtrType;
typedef const T *const_pointer; typedef const T *ConstPtrType;
typedef PointerRange< T> range; typedef PointerRange< T> RangeType;
typedef PointerRange<const T> const_range; typedef PointerRange<const T> ConstRangeType;
Vector() noexcept: p_buf(nullptr), p_len(0), p_cap(0) {} Vector() noexcept: p_buf(nullptr), p_len(0), p_cap(0) {}
@ -319,10 +319,10 @@ namespace octa {
return insert_range(idx, il.range()); return insert_range(idx, il.range());
} }
range each() noexcept { RangeType each() noexcept {
return PointerRange<T>(p_buf, p_buf + p_len); return PointerRange<T>(p_buf, p_buf + p_len);
} }
const_range each() const noexcept { ConstRangeType each() const noexcept {
return PointerRange<const T>(p_buf, p_buf + p_len); return PointerRange<const T>(p_buf, p_buf + p_len);
} }