60using Teuchos::arrayView;
61using Teuchos::av_const_cast;
62using Teuchos::av_reinterpret_cast;
80 Array<int> a = generateArray<int>(n);
81 ArrayView<int> av = a;
88 ArrayView<const int> av_int1 =
null;
89 ArrayView<int> av_int2 = av_const_cast<int>(av_int1);
96 ArrayRCP<const int> arcp_int = arcp<int>(n);
97 ArrayView<const int> av_int1 = arcp_int();
98 ArrayView<int> av_int2 = av_const_cast<int>(av_int1);
109 ArrayView<char> av_char =
null;
110 ArrayView<int> av_int = av_reinterpret_cast<int>(av_char);
118 const int sizeOfInt =
sizeof(int);
119 const int sizeOfChar =
sizeof(char);
120 const int num_ints =
n;
121 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
122 out <<
"num_ints = " << num_ints <<
"\n";
123 out <<
"num_chars = " << num_chars <<
"\n";
125 ArrayRCP<char> arcp_char = arcp<char>(num_chars);
126 ArrayView<int> av_int = av_reinterpret_cast<int>(arcp_char());
129 implicit_ptr_cast<void>(&arcp_char[0]));
130 TEST_EQUALITY(implicit_ptr_cast<void>((&av_int[num_ints-1])+1),
131 implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
139 const int sizeOfInt =
sizeof(int);
140 const int sizeOfChar =
sizeof(char);
141 const int num_ints =
n;
142 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
143 out <<
"num_ints = " << num_ints <<
"\n";
144 out <<
"num_chars = " << num_chars <<
"\n";
146 ArrayRCP<int> arcp_int = arcp<int>(num_ints);
147 ArrayView<char> av_char = av_reinterpret_cast<char>(arcp_int());
150 implicit_ptr_cast<void>(&av_char[0]));
151 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
152 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
153 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
154 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
162 const ArrayView<T> av = arrayView(a.getRawPtr(), a.size());
171 Array<T> a = generateArray<T>(n);
172 const ArrayView<T> av = arrayView(&a[0], a.size());
179 const ArrayView<T> av_0;
180 const ArrayView<T> av = av_0(0, 0);
187 const ArrayView<T> av_0;
188 const ArrayView<T> av = av_0.view(0, 0);
196 ArrayView<T> view(data, 10);
201 ArrayView<const T> cview = view.getConst();
202 TEST_EQUALITY(cview.getRawPtr(),
const_cast<const T*
>(data));
205#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
206 ArrayRCP<const T> cview_arcp = cview.access_private_arcp();
207 TEST_EQUALITY(cview_arcp.getRawPtr(),
const_cast<const T*
>(data));
216 T
const * data =
new T[10];
217 ArrayView<const T> view(data, 10);
222 ArrayView<const T> cview = view.getConst();
226#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
227 ArrayRCP<const T> cview_arcp = cview.access_private_arcp();
240 if (view_inout.
size() == 0 && size == 0) {
return; }
241#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
242 const T &next_to_last = view_inout[offset+size-1];
245 view_inout = arrayView<T>(&view_inout[offset], size);
252 ArrayView<T> view(data, 10);
253 resizeRawView(view, 0, 5);
265 Array<T> a = generateArray<T>(n);
295 typedef typename ArrayView<T>::iterator iter_t;
297 ECHO(Array<T> a = generateArray<T>(n));
298 ECHO(ArrayView<T> av = a);
299 ECHO(
const iter_t av_begin = av.begin());
300 ECHO(
const iter_t av_end = av.end());
304 ECHO(std::fill(av_begin, av_end, ST::random()));
305 ECHO(Array<T> a2 = generateArray<T>(n));
306 ECHO(ArrayView<T> av2 = a2);
307 ECHO(std::copy(av.begin(), av.end(), av2.begin()));
319 ArrayView<const T> av1 = arrayView<T>(&t[0], nsize);
348 ArrayRCP<T> ap = arcp(
rcp(
new std::vector<T>(n)));
352 TEST_THROW(av.getRawPtr(), DanglingReferenceError);
353 TEST_THROW(av.data(), DanglingReferenceError);
360#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
372#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
374# define DEBUG_UNIT_TEST_GROUP( T )
378# define DEBUG_UNIT_TEST_GROUP( T )
383#define UNIT_TEST_GROUP( T ) \
384 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView_construct_zero_size, T ) \
385 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView, T ) \
386 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_operator, T ) \
387 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_func, T ) \
388 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, raw_ptr_self_view, T ) \
389 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, raw_ptr_self_view_const, T ) \
390 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, resize_raw_ptr_self_view, T ) \
391 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, assignmentOperator, T ) \
392 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, iterators, T ) \
393 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView_convertToConst, T ) \
394 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_std_vector, T ) \
395 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_rcp_std_vector, T ) \
396 DEBUG_UNIT_TEST_GROUP( T )
#define UNIT_TEST_GROUP(T)
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails).
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
#define ECHO(statement)
Echo the given statement before it is executed.
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Reference-counted smart pointer for managing arrays.
size_type size() const
The total number of items in the managed array.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Dangling reference error exception class.
Smart reference counting pointer class for automatic garbage collection.
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool nonnull(const boost::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
Teuchos::Array< T > generateArray(const int n_in)
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
TypeTo * implicit_ptr_cast(TypeFrom *t)
Perform an implicit cast of pointer types with a pointer being returned.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
This structure defines some basic traits for a scalar field type.