for_each.hpp
来自「矩阵运算源码最新版本」· HPP 代码 · 共 61 行
HPP
61 行
// Software License for MTL// // Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.// Authors: Peter Gottschling and Andrew Lumsdaine// // This file is part of the Matrix Template Library// // See also license.mtl.txt in the distribution.#ifndef MTL_FOR_EACH_INCLUDE#define MTL_FOR_EACH_INCLUDEnamespace mtl { namespace recursion {// Go recursively down to base case and apply function on ittemplate <typename Matrix, typename Function, typename BaseCaseTest>void for_each(matrix_recursator<Matrix> const& recursator, Function const& f, BaseCaseTest const& is_base){ if (recursator.is_empty()) return; if (is_base(recursator)) { f(*recursator); return; } for_each(recursator.north_west(), f, is_base); for_each(recursator.south_west(), f, is_base); for_each(recursator.north_east(), f, is_base); for_each(recursator.south_east(), f, is_base);}// Non-const versiontemplate <typename Matrix, typename Function, typename BaseCaseTest>void for_each(matrix_recursator<Matrix>& recursator, Function const& f, BaseCaseTest const& is_base){ typedef matrix_recursator<Matrix> recursator_type; if (recursator.is_empty()) return; if (is_base(recursator)) { f(recursator.get_value()); return; } recursator_type tmp_nw(recursator.north_west()), tmp_sw(recursator.south_west()), tmp_ne(recursator.north_east()), tmp_se(recursator.south_east()); for_each(tmp_nw, f, is_base); for_each(tmp_sw, f, is_base); for_each(tmp_ne, f, is_base); for_each(tmp_se, f, is_base);}}} // namespace mtl::recursion#endif // MTL_FOR_EACH_INCLUDE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?