Fix one last dynarray test

llvm-svn: 245528
This commit is contained in:
Eric Fiselier 2015-08-20 00:20:05 +00:00
parent 36efd3883d
commit 25dd3a699c
1 changed files with 25 additions and 20 deletions

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
// dynarray.overview
// reference front();
@ -14,10 +16,6 @@
// reference back();
// const_reference back() const;
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <experimental/dynarray>
#include <cassert>
@ -29,40 +27,47 @@
using std::experimental::dynarray;
template <class T>
void dyn_test_const ( const dynarray<T> &dyn ) {
void dyn_test_const ( const dynarray<T> &dyn, bool CheckValues = true ) {
const T *data = dyn.data ();
assert ( *data == dyn.front ());
assert ( *(data + dyn.size() - 1 ) == dyn.back ());
assert(data == &dyn.front());
assert((data + dyn.size() - 1) == &dyn.back());
if (CheckValues) {
assert ( *data == dyn.front ());
assert ( *(data + dyn.size() - 1 ) == dyn.back ());
}
}
template <class T>
void dyn_test ( dynarray<T> &dyn ) {
void dyn_test ( dynarray<T> &dyn, bool CheckValues = true ) {
T *data = dyn.data ();
assert ( *data == dyn.front ());
assert ( *(data + dyn.size() - 1 ) == dyn.back ());
assert(data == &dyn.front());
assert((data + dyn.size() - 1) == &dyn.back());
if (CheckValues) {
assert ( *data == dyn.front ());
assert ( *(data + dyn.size() - 1 ) == dyn.back ());
}
}
template <class T>
void test ( const T &val ) {
void test ( const T &val, bool DefaultValueIsIndeterminate = false) {
typedef dynarray<T> dynA;
const bool CheckDefaultValues = ! DefaultValueIsIndeterminate;
dynA d1 ( 4 );
dyn_test ( d1 );
dyn_test_const ( d1 );
dyn_test ( d1, CheckDefaultValues );
dyn_test_const ( d1, CheckDefaultValues );
dynA d2 ( 7, val );
dyn_test ( d2 );
dyn_test_const ( d2 );
}
}
int main()
{
test<int> ( 14 );
test<double> ( 14.0 );
test<int> ( 14, /* DefaultValueIsIndeterminate */ true);
test<double> ( 14.0, true );
test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
test<std::string> ( "fourteen" );
}
#else
int main() {}
#endif