60 using Teuchos::arrayView;
61 using Teuchos::av_const_cast;
62 using Teuchos::av_reinterpret_cast;
80 Array<int> a = generateArray<int>(
n);
81 ArrayView<int> av = a;
88 ArrayView<const int> av_int1 =
null;
96 ArrayRCP<const int> arcp_int = arcp<int>(
n);
97 ArrayView<const int> av_int1 = arcp_int();
107 ArrayView<char> av_char =
null;
116 const int sizeOfInt =
sizeof(int);
117 const int sizeOfChar =
sizeof(char);
118 const int num_ints =
n;
119 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
120 out <<
"num_ints = " << num_ints <<
"\n";
121 out <<
"num_chars = " << num_chars <<
"\n";
123 ArrayRCP<char> arcp_char = arcp<char>(num_chars);
127 implicit_ptr_cast<void>(&arcp_char[0]));
128 TEST_EQUALITY(implicit_ptr_cast<void>((&av_int[num_ints-1])+1),
129 implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
137 const int sizeOfInt =
sizeof(int);
138 const int sizeOfChar =
sizeof(char);
139 const int num_ints =
n;
140 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
141 out <<
"num_ints = " << num_ints <<
"\n";
142 out <<
"num_chars = " << num_chars <<
"\n";
144 ArrayRCP<int> arcp_int = arcp<int>(num_ints);
148 implicit_ptr_cast<void>(&av_char[0]));
149 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
150 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
151 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
152 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
160 const ArrayView<T> av =
arrayView(a.getRawPtr(), a.size());
169 Array<T> a = generateArray<T>(
n);
170 const ArrayView<T> av =
arrayView(&a[0], a.size());
177 const ArrayView<T> av_0;
178 const ArrayView<T> av = av_0(0, 0);
185 const ArrayView<T> av_0;
186 const ArrayView<T> av = av_0.view(0, 0);
193 Array<T> a = generateArray<T>(
n);
215 typedef typename ArrayView<T>::iterator iter_t;
217 ECHO(Array<T> a = generateArray<T>(
n));
218 ECHO(ArrayView<T> av = a);
219 ECHO(
const iter_t av_begin = av.begin());
220 ECHO(
const iter_t av_end = av.end());
224 ECHO(std::fill(av_begin, av_end, ST::random()));
225 ECHO(Array<T> a2 = generateArray<T>(
n));
226 ECHO(ArrayView<T> av2 = a2);
227 ECHO(std::copy(av.begin(), av.end(), av2.begin()));
253 ArrayRCP<T> ap =
arcp(
rcp(
new std::vector<T>(
n)));
257 TEST_THROW(av.getRawPtr(), DanglingReferenceError);
264 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
267 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
276 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
278 # define DEBUG_UNIT_TEST_GROUP( T )
280 #else // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
282 # define DEBUG_UNIT_TEST_GROUP( T )
284 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
287 #define UNIT_TEST_GROUP( T ) \
288 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView_construct_zero_size, T ) \
289 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView, T ) \
290 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_operator, T ) \
291 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_func, T ) \
292 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, assignmentOperator, T ) \
293 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, iterators, T ) \
294 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_std_vector, T ) \
295 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_rcp_std_vector, T ) \
296 DEBUG_UNIT_TEST_GROUP( T )
Dangling reference error exception class.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define UNIT_TEST_GROUP(T)
#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 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)...
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
This structure defines some basic traits for a scalar field type.
ArrayView< T2 > av_reinterpret_cast(const ArrayView< T1 > &p1)
Reinterpret cast of underlying ArrayView type from T1* to T2*.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
ArrayView< T2 > av_const_cast(const ArrayView< T1 > &p1)
Const cast of underlying ArrayView type from const T* to T*.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
TypeTo * implicit_ptr_cast(TypeFrom *t)
Perform an implicit cast of pointer types with a pointer being returned.
Teuchos::Array< T > generateArray(const int n_in)
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
Smart reference counting pointer class for automatic garbage collection.
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.
Reference-counted smart pointer for managing arrays.
Memory-safe templated array class that encapsulates std::vector.