From db42a65989644e447e161a029237104f3ec519fc Mon Sep 17 00:00:00 2001 From: Michael Stevens Date: Mon, 20 Sep 2004 07:33:48 +0000 Subject: [PATCH] use expression size_type [SVN r25250] --- include/boost/numeric/ublas/io.hpp | 150 ++++++----------------------- 1 file changed, 32 insertions(+), 118 deletions(-) diff --git a/include/boost/numeric/ublas/io.hpp b/include/boost/numeric/ublas/io.hpp index d48df4b9..4b114785 100644 --- a/include/boost/numeric/ublas/io.hpp +++ b/include/boost/numeric/ublas/io.hpp @@ -29,7 +29,8 @@ namespace boost { namespace numeric { namespace ublas { // BOOST_UBLAS_INLINE std::basic_ostream &operator << (std::basic_ostream &os, const vector_expression &v) { - std::size_t size = v ().size (); + typedef typename VE::size_type size_type; + size_type size = v ().size (); std::basic_ostringstream > s; s.flags (os.flags ()); s.imbue (os.getloc ()); @@ -37,38 +38,20 @@ namespace boost { namespace numeric { namespace ublas { s << '[' << size << "]("; if (size > 0) s << v () (0); - for (std::size_t i = 1; i < size; ++ i) + for (size_type i = 1; i < size; ++ i) s << ',' << v () (i); s << ')'; return os << s.str ().c_str (); } - template - // This function seems to be big. So we do not let the compiler inline it. - // BOOST_UBLAS_INLINE - std::basic_ostream &operator << (std::basic_ostream &os, - const vector &v) { - std::size_t size = v.size (); - std::basic_ostringstream > s; - s.flags (os.flags ()); - s.imbue (os.getloc ()); - s.precision (os.precision ()); - s << '[' << size << "]("; - if (size > 0) - s << v (0); - for (std::size_t i = 1; i < size; ++ i) - s << ',' << v (i); - s << ')'; - return os << s.str ().c_str (); - } - template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE std::basic_istream &operator >> (std::basic_istream &is, vector &v) { + typedef typename vector::size_type size_type; E ch; - std::size_t size; + size_type size; if (is >> ch && ch != '[') { is.putback (ch); is.setstate (std::ios_base::failbit); @@ -81,7 +64,7 @@ namespace boost { namespace numeric { namespace ublas { is.putback (ch); is.setstate (std::ios_base::failbit); } else if (! is.fail ()) { - for (std::size_t i = 0; i < size; i ++) { + for (size_type i = 0; i < size; i ++) { if (is >> s (i) >> ch && ch != ',') { is.putback (ch); if (i < size - 1) @@ -105,8 +88,9 @@ namespace boost { namespace numeric { namespace ublas { // BOOST_UBLAS_INLINE std::basic_ostream &operator << (std::basic_ostream &os, const matrix_expression &m) { - std::size_t size1 = m ().size1 (); - std::size_t size2 = m ().size2 (); + typedef typename ME::size_type size_type; + size_type size1 = m ().size1 (); + size_type size2 = m ().size2 (); std::basic_ostringstream > s; s.flags (os.flags ()); s.imbue (os.getloc ()); @@ -116,15 +100,15 @@ namespace boost { namespace numeric { namespace ublas { s << '(' ; if (size2 > 0) s << m () (0, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (size_type j = 1; j < size2; ++ j) s << ',' << m () (0, j); s << ')'; } - for (std::size_t i = 1; i < size1; ++ i) { + for (size_type i = 1; i < size1; ++ i) { s << ",(" ; if (size2 > 0) s << m () (i, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (size_type j = 1; j < size2; ++ j) s << ',' << m () (i, j); s << ')'; } @@ -132,45 +116,14 @@ namespace boost { namespace numeric { namespace ublas { return os << s.str ().c_str (); } - template - // This function seems to be big. So we do not let the compiler inline it. - // BOOST_UBLAS_INLINE - std::basic_ostream &operator << (std::basic_ostream &os, - const matrix &m) { - std::size_t size1 = m.size1 (); - std::size_t size2 = m.size2 (); - std::basic_ostringstream > s; - s.flags (os.flags ()); - s.imbue (os.getloc ()); - s.precision (os.precision ()); - s << '[' << size1 << ',' << size2 << "]("; - if (size1 > 0) { - s << '(' ; - if (size2 > 0) - s << m (0, 0); - for (std::size_t j = 1; j < size2; ++ j) - s << ',' << m (0, j); - s << ')'; - } - for (std::size_t i = 1; i < size1; ++ i) { - s << ",(" ; - if (size2 > 0) - s << m (i, 0); - for (std::size_t j = 1; j < size2; ++ j) - s << ',' << m (i, j); - s << ')'; - } - s << ')'; - return os << s.str ().c_str (); - } - template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE std::basic_istream &operator >> (std::basic_istream &is, matrix &m) { + typedef typename matrix::size_type size_type; E ch; - std::size_t size1, size2; + size_type size1, size2; if (is >> ch && ch != '[') { is.putback (ch); is.setstate (std::ios_base::failbit); @@ -186,13 +139,13 @@ namespace boost { namespace numeric { namespace ublas { is.putback (ch); is.setstate (std::ios_base::failbit); } else if (! is.fail ()) { - for (std::size_t i = 0; i < size1; i ++) { + for (size_type i = 0; i < size1; i ++) { if (is >> ch && ch != '(') { is.putback (ch); is.setstate (std::ios_base::failbit); break; } - for (std::size_t j = 0; j < size2; j ++) { + for (size_type j = 0; j < size2; j ++) { if (is >> s (i, j) >> ch && ch != ',') { is.putback (ch); if (j < size2 - 1) { @@ -234,38 +187,25 @@ namespace boost { namespace numeric { namespace ublas { // BOOST_UBLAS_INLINE std::ostream &operator << (std::ostream &os, const vector_expression &v) { - std::size_t size = v ().size (); + typedef typename VE::size_type size_type; + size_type size = v ().size (); os << '[' << size << "]("; if (size > 0) os << v () (0); - for (std::size_t i = 1; i < size; ++ i) + for (size_type i = 1; i < size; ++ i) os << ',' << v () (i); os << ')'; return os; } - template - // This function seems to be big. So we do not let the compiler inline it. - // BOOST_UBLAS_INLINE - std::ostream &operator << (std::ostream &os, - const vector &v) { - std::size_t size = v.size (); - os << '[' << size << "]("; - if (size > 0) - os << v (0); - for (std::size_t i = 1; i < size; ++ i) - os << ',' << v (i); - os << ')'; - return os; - } - template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE std::istream &operator >> (std::istream &is, vector &v) { + typedef typename vector::size_type size_type; char ch; - std::size_t size; + size_type size; if (is >> ch && ch != '[') { is.putback (ch); is.setstate (std::ios::failbit); @@ -278,7 +218,7 @@ namespace boost { namespace numeric { namespace ublas { is.putback (ch); is.setstate (std::ios::failbit); } else if (! is.fail ()) { - for (std::size_t i = 0; i < size; i ++) { + for (size_type i = 0; i < size; i ++) { if (is >> s (i) >> ch && ch != ',') { is.putback (ch); if (i < size - 1) @@ -302,22 +242,23 @@ namespace boost { namespace numeric { namespace ublas { // BOOST_UBLAS_INLINE std::ostream &operator << (std::ostream &os, const matrix_expression &m) { - std::size_t size1 = m ().size1 (); - std::size_t size2 = m ().size2 (); + typedef typename ME::size_type size_type; + size_type size1 = m ().size1 (); + size_type size2 = m ().size2 (); os << '[' << size1 << ',' << size2 << "]("; if (size1 > 0) { os << '(' ; if (size2 > 0) os << m () (0, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (size_type j = 1; j < size2; ++ j) os << ',' << m () (0, j); os << ')'; } - for (std::size_t i = 1; i < size1; ++ i) { + for (size_type i = 1; i < size1; ++ i) { os << ",(" ; if (size2 > 0) os << m () (i, 0); - for (std::size_t j = 1; j < size2; ++ j) + for (size_type j = 1; j < size2; ++ j) os << ',' << m () (i, j); os << ')'; } @@ -325,41 +266,14 @@ namespace boost { namespace numeric { namespace ublas { return os; } - template - // This function seems to be big. So we do not let the compiler inline it. - // BOOST_UBLAS_INLINE - std::ostream &operator << (std::ostream &os, - const matrix &m) { - std::size_t size1 = m.size1 (); - std::size_t size2 = m.size2 (); - os << '[' << size1 << ',' << size2 << "]("; - if (size1 > 0) { - os << '(' ; - if (size2 > 0) - os << m (0, 0); - for (std::size_t j = 1; j < size2; ++ j) - os << ',' << m (0, j); - os << ')'; - } - for (std::size_t i = 1; i < size1; ++ i) { - os << ",(" ; - if (size2 > 0) - os << m (i, 0); - for (std::size_t j = 1; j < size2; ++ j) - os << ',' << m (i, j); - os << ')'; - } - os << ')'; - return os; - } - template // This function seems to be big. So we do not let the compiler inline it. // BOOST_UBLAS_INLINE std::istream &operator >> (std::istream &is, matrix &m) { + typedef typename matrix::size_type size_type; char ch; - std::size_t size1, size2; + size_type size1, size2; if (is >> ch && ch != '[') { is.putback (ch); is.setstate (std::ios::failbit); @@ -375,13 +289,13 @@ namespace boost { namespace numeric { namespace ublas { is.putback (ch); is.setstate (std::ios::failbit); } else if (! is.fail ()) { - for (std::size_t i = 0; i < size1; i ++) { + for (size_type i = 0; i < size1; i ++) { if (is >> ch && ch != '(') { is.putback (ch); is.setstate (std::ios::failbit); break; } - for (std::size_t j = 0; j < size2; j ++) { + for (size_type j = 0; j < size2; j ++) { if (is >> s (i, j) >> ch && ch != ',') { is.putback (ch); if (j < size2 - 1) {