Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ArrayView.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include <Teuchos_ArrayView.hpp>
11 
12 namespace Teuchos {
13 
14 template<>
17 {
18  using Teuchos::as;
19  std::ostringstream ss;
20 
21  debug_assert_valid_ptr();
22 
23  ss.setf (std::ios::scientific);
24  // 8 = round(23 * log10(2)) + 1. That's one decimal digit more
25  // than the binary precision justifies, which should be plenty.
26  // Guy Steele et al. have a better algorithm for floating-point
27  // I/O, but using a lot of digits is the lazy approach.
28  ss.precision (8);
29  ss << "{";
30  for (size_type i = 0; i < size (); ++i) {
31  ss << operator[] (i);
32  if (i + 1 < size ()) {
33  ss << ", ";
34  }
35  }
36  ss << "}";
37  return ss.str ();
38 }
39 
40 template<>
43 {
44  using Teuchos::as;
45  std::ostringstream ss;
46 
47  debug_assert_valid_ptr();
48 
49  ss.setf (std::ios::scientific);
50  // 8 = round(23 * log10(2)) + 1. That's one decimal digit more
51  // than the binary precision justifies, which should be plenty.
52  // Guy Steele et al. have a better algorithm for floating-point
53  // I/O, but using a lot of digits is the lazy approach.
54  ss.precision (8);
55  ss << "{";
56  for (size_type i = 0; i < size (); ++i) {
57  ss << operator[] (i);
58  if (i + 1 < size ()) {
59  ss << ", ";
60  }
61  }
62  ss << "}";
63  return ss.str ();
64 }
65 
66 template<>
69 {
70  using Teuchos::as;
71  std::ostringstream ss;
72 
73  debug_assert_valid_ptr();
74 
75  ss.setf (std::ios::scientific);
76  // 17 = round(52 * log10(2)) + 1. That's one decimal digit more
77  // than the binary precision justifies, which should be plenty. Guy
78  // Steele et al. have a better algorithm for floating-point I/O, but
79  // using a lot of digits is the lazy approach.
80  ss.precision (17);
81  ss << "{";
82  for (size_type i = 0; i < size (); ++i) {
83  ss << operator[] (i);
84  if (i + 1 < size ()) {
85  ss << ", ";
86  }
87  }
88  ss << "}";
89  return ss.str ();
90 }
91 
92 template<>
95 {
96  using Teuchos::as;
97  std::ostringstream ss;
98 
99  debug_assert_valid_ptr();
100 
101  ss.setf (std::ios::scientific);
102  // 17 = round(52 * log10(2)) + 1. That's one decimal digit more
103  // than the binary precision justifies, which should be plenty. Guy
104  // Steele et al. have a better algorithm for floating-point I/O, but
105  // using a lot of digits is the lazy approach.
106  ss.precision (17);
107  ss << "{";
108  for (size_type i = 0; i < size (); ++i) {
109  ss << operator[] (i);
110  if (i + 1 < size ()) {
111  ss << ", ";
112  }
113  }
114  ss << "}";
115  return ss.str ();
116 }
117 
118 } // namespace Teuchos
std::string toString() const
Convert an ArrayView&lt;T&gt; to an std::string
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
#define TEUCHOSCORE_LIB_DLL_EXPORT
TypeTo as(const TypeFrom &t)
Convert from one value type to another.