/* */ #ifndef D_ARRAY_FUN_H #define D_ARRAY_FUN_H #include "common.h" #include #include namespace aria2 { template constexpr size_t arraySize(T (&)[N]) { return N; } template class array_wrapper { private: T array_[N]; public: array_wrapper() {} operator T*() { return array_; } operator const T*() const { return array_; } size_t size() const { return N; } }; // Expression Template for array namespace expr { template struct BinExpr { typedef typename Op::result_type value_type; BinExpr(L lhs, R rhs, Op op) : lhs(std::move(lhs)), rhs(std::move(rhs)), op(std::move(op)) {} value_type operator[](size_t i) const { return op(lhs[i], rhs[i]); } L lhs; R rhs; Op op; }; template> BinExpr operator&(L lhs, R rhs) { return BinExpr(std::forward(lhs), std::forward(rhs), Op()); } template> BinExpr operator|(L lhs, R rhs) { return BinExpr(std::forward(lhs), std::forward(rhs), Op()); } template struct UnExpr { typedef typename Op::result_type value_type; UnExpr(Arg arg, Op op) : arg(std::move(arg)), op(std::move(op)) {} value_type operator[](size_t i) const { return op(arg[i]); } Arg arg; Op op; }; template struct bit_neg : std::function { T operator()(T t) const { return ~t; } }; template> UnExpr operator~(Arg arg) { return UnExpr(std::forward(arg), Op()); } template struct Array { typedef T value_type; Array(T* t) : t(t) {} T operator[](size_t i) const { return t[i]; } T* t; }; template Array array(T *t) { return Array(t); } } // namespace expr } // namespace aria2 #endif // D_ARRAY_FUN_H