提交 e02f67ef 编写于 作者: S sneaxiy

rewrite unsafe_cast

test=develop
上级 600f6d82
......@@ -131,8 +131,6 @@ DDim slice_ddim(const DDim& dim, int begin, int end) {
int arity(const DDim& d) { return d.size(); }
/// \cond HIDDEN
struct DDimPrinter {
std::ostream& os;
explicit DDimPrinter(std::ostream& os_) : os(os_) {}
......@@ -143,8 +141,6 @@ struct DDimPrinter {
}
};
/// \endcond
std::ostream& operator<<(std::ostream& os, const DDim& ddim) {
ddim.apply_visitor(DDimPrinter(os));
return os;
......
......@@ -126,7 +126,9 @@ class DDim {
private:
template <int D>
inline Dim<D>& UnsafeCast() {
return const_cast<Dim<D>&>(const_cast<const DDim*>(this)->UnsafeCast<D>());
static_assert(D >= 0 && D <= kMaxRank, "Invalid rank");
auto* p = static_cast<void*>(&dim_);
return *reinterpret_cast<Dim<D>*>(p);
}
template <int D>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册