94 template<
typename T,
typename Op>
95 std::string
FormatArrayOp(
const T* data,
size_t count, Op op,
int numCols) {
98 for(
size_t row(0); row < numRows; ++row) {
99 size_t left = row * numCols;
102 for(
size_t col(left); col <
std::min(left + numCols, count); ++col) {
103 s.append(op(col, data[col]));
112 std::string
FormatArray(
const T* data,
size_t count,
const char* format,
118 std::string
FormatArray(
const std::vector<T>& data,
const char* format,
120 return FormatArray(&data[0], (
int)data.size(), format, numCols);
122 template<
typename T,
typename Op>
124 return FormatArrayOp(&data[0], (
int)data.size(), op, numCols);
128 void PrintArray(
const T* data,
size_t count,
const char* format,
int numCols) {
129 std::string s =
FormatArray(data, count, format, numCols);
130 printf(
"%s", s.c_str());
134 void PrintArray(
const std::vector<T>& data,
const char* format,
int numCols) {
135 std::string s =
FormatArray(data, format, numCols);
136 printf(
"%s", s.c_str());
139 template<
typename T,
typename Op>
142 printf(
"%s", s.c_str());