2011-07-01 Lawrence Crowl <crowl@google.com>
* g++.dg/pph/a1dynarray-dcl1.hi: New.
* g++.dg/pph/a1dynarray-dcl2a.hi: New.
* g++.dg/pph/a1dynarray-dcl2b.hi: New.
* g++.dg/pph/a1dynarray-dcl3.hi: New.
* g++.dg/pph/a1dynarray-dcl4.hi: New.
* g++.dg/pph/a1dynarray-dfn1a.hi: New.
* g++.dg/pph/a1dynarray-dfn1b.hi: New.
* g++.dg/pph/a1dynarray-dfn2a.hi: New.
* g++.dg/pph/a1dynarray-dfn2b.hi: New.
* g++.dg/pph/a1dynarray-dfn2c.hi: New.
* g++.dg/pph/a1dynarray-dfn3a.hi: New.
* g++.dg/pph/a1dynarray-dfn3b.hi: New.
* g++.dg/pph/a1dynarray-dfn3c.hi: New.
* g++.dg/pph/a1dynarray-hlp1.cci: New.
* g++.dg/pph/a1dynarray-use1.cci: New.
* g++.dg/pph/a1dynarray-use2.cci: New.
* g++.dg/pph/a1dynarray-use3a.cci: New.
* g++.dg/pph/a1dynarray-use3b.cci: New.
* g++.dg/pph/a1dynarray-use4a.cci: New.
* g++.dg/pph/a1dynarray-use4b.cci: New.
* g++.dg/pph/a1integer.h: New.
* g++.dg/pph/x1dynarray0.cc: Removed.
* g++.dg/pph/x1dynarray1.cc: Removed.
* g++.dg/pph/x1dynarray1.h: Removed.
* g++.dg/pph/x1dynarray2.cc: Removed.
* g++.dg/pph/x1dynarray2.h: Removed.
* g++.dg/pph/x1dynarray1.cc: New. (Name reused.)
* g++.dg/pph/x1dynarray1.h: New. (Name reused.)
* g++.dg/pph/x1dynarray2.h: New. (Name reused.)
* g++.dg/pph/x1dynarray2a.cc: New.
* g++.dg/pph/x1dynarray2b.cc: New.
* g++.dg/pph/x1dynarray3.cc: New.
* g++.dg/pph/x1dynarray3.h: New.
* g++.dg/pph/x1dynarray4.cc: New.
* g++.dg/pph/x1dynarray4.h: New.
* g++.dg/pph/x1dynarray5.cc: New.
* g++.dg/pph/x1dynarray5.h: New.
* g++.dg/pph/x1dynarray6.cc: New.
* g++.dg/pph/x1dynarray6.h: New.
* g++.dg/pph/x1dynarray7.cc: New.
* g++.dg/pph/x1dynarray7.h: New.
===================================================================
@@ -0,0 +1,4 @@
+template< typename T >
+dynarray<T>::dynarray(const dynarray& d)
+: store( alloc( d.count ) ), count( d.count )
+{ memcpy( store, d.store, count * sizeof(T) ); }
===================================================================
@@ -1,111 +1,23 @@
-// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
-// { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, _WCHAR_H is" "" { xfail *-*-* } 0 }
-// { dg-bogus "unistd.h:1144:34: error: declaration of .* has a different exception specifier" "" { xfail *-*-* } 0 }
#ifndef X1DYNARRAY2_H
#define X1DYNARRAY2_H
-#include <stddef.h>
-#include <stdexcept>
-#include <memory>
-#include <new>
-#include <iterator>
-
-#define DefaultConstructible typename
-#define CPP0X( ignore )
+extern "C" void *memcpy(void *dest, const void *src, unsigned long n);
+extern "C" void exit(int) throw();
-namespace std {
+namespace tst {
-template< DefaultConstructible T >
+template< typename T >
struct dynarray
{
- // types:
- typedef T value_type;
- typedef T& reference;
- typedef const T& const_reference;
- typedef T* iterator;
- typedef const T* const_iterator;
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
-
- // fields:
-private:
- T* store;
- size_type count;
-
- // helper functions:
- void check(size_type n)
- { if ( n >= count ) throw out_of_range("dynarray"); }
- T* alloc(size_type n)
- { return reinterpret_cast<T*>( new char[ n*sizeof(T) ] ); }
-
-public:
- // construct and destruct:
- dynarray() CPP0X( = delete ) ;
- const dynarray operator=(const dynarray&) CPP0X( = delete ) ;
-
- explicit dynarray(size_type c)
- : store( alloc( c ) ), count( c )
- { size_type i;
- try {
- for ( size_type i = 0; i < count; ++i )
- new (store+i) T;
- } catch ( ... ) {
- for ( ; i > 0; --i )
- (store+(i-1))->~T();
- throw;
- } }
-
- dynarray(const dynarray& d)
- : store( alloc( d.count ) ), count( d.count )
- { try { uninitialized_copy( d.begin(), d.end(), begin() ); }
- catch ( ... ) { delete store; throw; } }
-
- ~dynarray()
- { for ( size_type i = 0; i < count; ++i )
- (store+i)->~T();
- delete[] store; }
-
- // iterators:
- iterator begin() { return store; }
- const_iterator begin() const { return store; }
- const_iterator cbegin() const { return store; }
- iterator end() { return store + count; }
- const_iterator end() const { return store + count; }
- const_iterator cend() const { return store + count; }
-
- reverse_iterator rbegin()
- { return reverse_iterator(end()); }
- const_reverse_iterator rbegin() const
- { return reverse_iterator(end()); }
- reverse_iterator rend()
- { return reverse_iterator(begin()); }
- const_reverse_iterator rend() const
- { return reverse_iterator(begin()); }
-
- // capacity:
- size_type size() const { return count; }
- size_type max_size() const { return count; }
- bool empty() const { return false; }
-
- // element access:
- reference operator[](size_type n) { return store[n]; }
- const_reference operator[](size_type n) const { return store[n]; }
-
- reference front() { return store[0]; }
- const_reference front() const { return store[0]; }
- reference back() { return store[count-1]; }
- const_reference back() const { return store[count-1]; }
-
- const_reference at(size_type n) const { check(n); return store[n]; }
- reference at(size_type n) { check(n); return store[n]; }
-
- // data access:
- T* data() { return store; }
- const T* data() const { return store; }
+ #include "a1dynarray-dcl1.hi"
+ #include "a1dynarray-dcl2a.hi"
+ #include "a1dynarray-dcl3.hi"
};
-} // namespace std
+#include "a1dynarray-dfn1a.hi"
+#include "a1dynarray-dfn2a.hi"
+#include "a1dynarray-dfn3a.hi"
+
+} // namespace tst
#endif
===================================================================
@@ -0,0 +1,28 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, _WCHAR_H" "" { xfail *-*-* } 0 }
+// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a different exception specifier" "" { xfail *-*-* } 0 }
+// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" "" { xfail *-*-* } 0 }
+
+#include <algorithm>
+#include <iostream>
+
+#include "x1dynarray7.h"
+
+#include "a1integer.h"
+typedef tst::dynarray< integer > integer_array;
+
+#include "a1dynarray-hlp1.cci"
+
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ dump( source );
+ dump( sorted );
+ std::sort( sorted.begin(), sorted.end() );
+ dump( sorted );
+ #include "a1dynarray-use2.cci"
+ dump( target );
+ #include "a1dynarray-use3b.cci"
+ #include "a1dynarray-use4b.cci"
+ return sum - 23;
+}
===================================================================
@@ -0,0 +1,23 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, _WCHAR_H" "" { xfail *-*-* } 0 }
+// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a different exception specifier" "" { xfail *-*-* } 0 }
+// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" "" { xfail *-*-* } 0 }
+
+#ifndef X1DYNARRAY6_H
+#define X1DYNARRAY6_H
+
+#include "x1dynarray4.h"
+
+#include <new>
+#include <memory>
+#include <stdexcept>
+
+namespace tst {
+
+#include "a1dynarray-dfn1b.hi"
+#include "a1dynarray-dfn2c.hi"
+#include "a1dynarray-dfn3c.hi"
+
+} // namespace tst
+
+#endif
===================================================================
@@ -0,0 +1,4 @@
+ integer_array source(3);
+ for ( integer_array::size_type ix = 0; ix < source.size(); ++ix )
+ source[ix] = integer(4 - ix);
+ integer_array sorted( source );
===================================================================
@@ -0,0 +1,8 @@
+ try {
+ integer t = target.at(32);
+ }
+ catch ( integer_array::size_type ) {
+ }
+ catch ( ... ) {
+ return 1;
+ }
===================================================================
@@ -1,48 +0,0 @@
-// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
-
-#include <iostream>
-#include <algorithm>
-#include "x1dynarray2.h"
-
-void dump( const std::dynarray< int > & source )
-{
- std::dynarray< int >::const_iterator src = source.begin();
- for ( ; src != source.end(); src++ )
- std::cout << " " << *src;
- std::cout << std::endl;
-}
-
-void lowrap( std::dynarray< int > & target,
- const std::dynarray< int > & source )
-{
- dump( source );
-
- std::dynarray< int > sorted( source );
- dump( sorted );
-
- std::sort( sorted.begin(), sorted.end() );
- dump( sorted );
-
- const int* srt = &sorted.front();
- std::dynarray< int >::iterator tgt( target.begin() );
- for ( ; tgt != target.end(); tgt++ ) {
- *tgt = *srt;
- if ( srt == &sorted.back() )
- srt = &sorted.front();
- else
- srt++;
- }
- dump( target );
-}
-
-int main() {
- std::dynarray< int > alpha(8);
- std::dynarray< int > gamma(3);
- for ( std::dynarray< int >::size_type i = 0; i < gamma.size(); i++ )
- gamma[i] = 4 - i;
- lowrap( alpha, gamma );
- int sum = 0;
- for ( std::dynarray< int >::size_type i = 0; i < alpha.size(); i++ )
- sum += alpha.at(i);
- return sum - 23;
-}
===================================================================
@@ -0,0 +1,5 @@
+ int sum = 0;
+ for ( integer_array::reverse_iterator it = target.rbegin();
+ it != target.rend();
+ ++it )
+ sum += *it;
===================================================================
@@ -0,0 +1,3 @@
+template< typename T >
+void dynarray<T>::check(size_type n)
+{ if ( n >= count ) throw std::out_of_range("dynarray"); }
===================================================================
@@ -0,0 +1,12 @@
+integer& operator<<(std::ostream& os, integer iv)
+{
+ os << (int)iv;
+}
+
+void dump( const integer_array& source )
+{
+ integer_array::const_iterator it = source.cbegin();
+ for ( ; it != source.end(); ++it )
+ std::cout << " " << *it;
+ std::cout << std::endl;
+}
===================================================================
@@ -0,0 +1,23 @@
+#ifndef X1DYNARRAY3_H
+#define X1DYNARRAY3_H
+
+#include <stddef.h>
+#include <new>
+
+namespace tst {
+
+template< typename T >
+struct dynarray
+{
+ #include "a1dynarray-dcl1.hi"
+ #include "a1dynarray-dcl2b.hi"
+ #include "a1dynarray-dcl3.hi"
+};
+
+#include "a1dynarray-dfn1b.hi"
+#include "a1dynarray-dfn2b.hi"
+#include "a1dynarray-dfn3b.hi"
+
+} // namespace tst
+
+#endif
===================================================================
@@ -0,0 +1,29 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, _WCHAR_H" "" { xfail *-*-* } 0 }
+// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a different exception specifier" "" { xfail *-*-* } 0 }
+// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" "" { xfail *-*-* } 0 }
+
+#include "x1dynarray4.h"
+#include "x1dynarray5.h"
+
+#include <algorithm>
+#include <iostream>
+
+#include "a1integer.h"
+typedef tst::dynarray< integer > integer_array;
+
+#include "a1dynarray-hlp1.cci"
+
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ dump( source );
+ dump( sorted );
+ std::sort( sorted.begin(), sorted.end() );
+ dump( sorted );
+ #include "a1dynarray-use2.cci"
+ dump( target );
+ #include "a1dynarray-use3a.cci"
+ #include "a1dynarray-use4a.cci"
+ return sum - 23;
+}
===================================================================
@@ -0,0 +1,32 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, _WCHAR_H" "" { xfail *-*-* } 0 }
+// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a different exception specifier" "" { xfail *-*-* } 0 }
+// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" "" { xfail *-*-* } 0 }
+
+#ifndef X1DYNARRAY7_H
+#define X1DYNARRAY7_H
+
+#include <stddef.h>
+#include <new>
+#include <memory>
+#include <stdexcept>
+#include <iterator>
+
+namespace tst {
+
+template< typename T >
+struct dynarray
+{
+ #include "a1dynarray-dcl1.hi"
+ #include "a1dynarray-dcl2b.hi"
+ #include "a1dynarray-dcl3.hi"
+ #include "a1dynarray-dcl4.hi"
+};
+
+#include "a1dynarray-dfn1b.hi"
+#include "a1dynarray-dfn2c.hi"
+#include "a1dynarray-dfn3c.hi"
+
+} // namespace tst
+
+#endif
===================================================================
@@ -0,0 +1,49 @@
+private:
+
+ // fields:
+ T* store;
+ size_type count;
+
+ // helper functions:
+ void check(size_type n);
+
+ T* alloc(size_type n)
+ { return reinterpret_cast<T*>( new char[ n*sizeof(T) ] ); }
+
+public:
+ // construct and destruct:
+ dynarray(); // undefined
+ const dynarray operator=(const dynarray&); // undefined
+
+ explicit dynarray(size_type c);
+ dynarray(const dynarray& d);
+ ~dynarray();
+
+ // capacity:
+ size_type size() const { return count; }
+ size_type max_size() const { return count; }
+ bool empty() const { return false; }
+
+ // element access:
+ reference operator[](size_type n) { return store[n]; }
+ const_reference operator[](size_type n) const { return store[n]; }
+
+ reference front() { return store[0]; }
+ const_reference front() const { return store[0]; }
+ reference back() { return store[count-1]; }
+ const_reference back() const { return store[count-1]; }
+
+ const_reference at(size_type n) const { check(n); return store[n]; }
+ reference at(size_type n) { check(n); return store[n]; }
+
+ // data access:
+ T* data() { return store; }
+ const T* data() const { return store; }
+
+ // iterators:
+ iterator begin() { return store; }
+ const_iterator begin() const { return store; }
+ const_iterator cbegin() const { return store; }
+ iterator end() { return store + count; }
+ const_iterator end() const { return store + count; }
+ const_iterator cend() const { return store + count; }
===================================================================
@@ -0,0 +1,15 @@
+template< typename T >
+dynarray<T>::dynarray(const dynarray& d)
+: store( alloc( d.count ) ), count( d.count )
+{
+ size_type i;
+ try {
+ for ( size_type i = 0; i < count; ++i )
+ new (store+i) T(d.store[i]);
+ }
+ catch ( ... ) {
+ for ( ; i > 0; --i )
+ (store+(i-1))->~T();
+ delete store; throw;
+ }
+}
===================================================================
@@ -0,0 +1,22 @@
+#ifndef A1INTEGER_H
+#define A1INTEGER_H
+
+class integer
+{
+ int value;
+public:
+ integer()
+ : value(0) { }
+ integer( int v )
+ : value(v) { }
+ integer( const integer& other )
+ : value( other.value ) { }
+ integer& operator=( const integer& other )
+ { value = other.value; return *this; }
+ operator int() const
+ { return value; }
+ bool operator <( const integer& other ) const
+ { return value < other.value; }
+};
+
+#endif
===================================================================
@@ -1,8 +0,0 @@
-// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
-
-#include "x1dynarray1.h"
-
-int main() {
- dynarray< int > alpha(8);
- return 0;
-}
===================================================================
@@ -0,0 +1,3 @@
+ // system-based types:
+ typedef unsigned long size_type;
+ typedef long difference_type;
===================================================================
@@ -0,0 +1,8 @@
+template< typename T >
+dynarray<T>::dynarray(size_type c)
+: store( alloc( c ) ), count( c )
+{ }
+
+template< typename T >
+dynarray<T>::~dynarray()
+{ delete[] store; }
===================================================================
@@ -0,0 +1,3 @@
+template< typename T >
+void dynarray<T>::check(size_type n)
+{ if ( n >= count ) exit(1); }
===================================================================
@@ -0,0 +1,15 @@
+// { dg-do run }
+
+#include "x1dynarray2.h"
+
+typedef int integer;
+using namespace tst;
+typedef dynarray< integer > integer_array;
+
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ #include "a1dynarray-use2.cci"
+ #include "a1dynarray-use4a.cci"
+ return sum - 25;
+}
===================================================================
@@ -0,0 +1,15 @@
+// { dg-do run }
+
+#include "x1dynarray3.h"
+
+#include "a1integer.h"
+typedef tst::dynarray< integer > integer_array;
+
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ #include "a1dynarray-use2.cci"
+ #include "a1dynarray-use3a.cci"
+ #include "a1dynarray-use4a.cci"
+ return sum - 25;
+}
===================================================================
@@ -0,0 +1,18 @@
+#ifndef X1DYNARRAY4_H
+#define X1DYNARRAY4_H
+
+#include <stddef.h>
+
+namespace tst {
+
+template< typename T >
+struct dynarray
+{
+ #include "a1dynarray-dcl1.hi"
+ #include "a1dynarray-dcl2b.hi"
+ #include "a1dynarray-dcl3.hi"
+};
+
+} // namespace tst
+
+#endif
===================================================================
@@ -0,0 +1,10 @@
+ integer_array target(8);
+ integer_array::iterator tgt( target.begin() );
+ const integer* srt = &sorted.front();
+ for ( ; tgt != target.end(); ++tgt ) {
+ *tgt = *srt;
+ if ( srt == &sorted.back() )
+ srt = &sorted.front();
+ else
+ ++srt;
+ }
===================================================================
@@ -0,0 +1,8 @@
+ try {
+ integer t = target.at(32);
+ }
+ catch ( std::out_of_range ) {
+ }
+ catch ( ... ) {
+ return 1;
+ }
===================================================================
@@ -0,0 +1,6 @@
+ // parameter-based types:
+ typedef T value_type;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef T* iterator;
+ typedef const T* const_iterator;
===================================================================
@@ -0,0 +1,28 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, _WCHAR_H" "" { xfail *-*-* } 0 }
+// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a different exception specifier" "" { xfail *-*-* } 0 }
+// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" "" { xfail *-*-* } 0 }
+
+#include <algorithm>
+#include <iostream>
+
+#include "x1dynarray6.h"
+
+#include "a1integer.h"
+typedef tst::dynarray< integer > integer_array;
+
+#include "a1dynarray-hlp1.cci"
+
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ dump( source );
+ dump( sorted );
+ std::sort( sorted.begin(), sorted.end() );
+ dump( sorted );
+ #include "a1dynarray-use2.cci"
+ dump( target );
+ #include "a1dynarray-use3b.cci"
+ #include "a1dynarray-use4a.cci"
+ return sum - 23;
+}
===================================================================
@@ -0,0 +1,5 @@
+ int sum = 0;
+ for ( integer_array::iterator it = target.begin();
+ it != target.end();
+ ++it )
+ sum += *it;
===================================================================
@@ -0,0 +1,11 @@
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ reverse_iterator rbegin()
+ { return reverse_iterator(end()); }
+ const_reverse_iterator rbegin() const
+ { return reverse_iterator(end()); }
+ reverse_iterator rend()
+ { return reverse_iterator(begin()); }
+ const_reverse_iterator rend() const
+ { return reverse_iterator(begin()); }
===================================================================
@@ -0,0 +1,11 @@
+template< typename T >
+dynarray<T>::dynarray(const dynarray& d)
+: store( alloc( d.count ) ), count( d.count )
+{
+ try {
+ std::uninitialized_copy( d.begin(), d.end(), begin() );
+ }
+ catch ( ... ) {
+ delete store; throw;
+ }
+}
===================================================================
@@ -1,30 +1,15 @@
+// { dg-do run }
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+
#include "x1dynarray1.h"
-#include <algorithm>
-void lowrap( dynarray< int > & target,
- const dynarray< int > & source )
-{
- dynarray< int > sorted( source );
- std::sort( sorted.begin(), sorted.end() );
- const int* srt = &sorted.front();
- dynarray< int >::iterator tgt( target.begin() );
- for ( ; tgt != target.end(); tgt++ ) {
- *tgt = *srt;
- if ( srt == &sorted.back() )
- srt = &sorted.front();
- else
- srt++;
- }
-}
+typedef int integer;
+typedef dynarray< integer > integer_array;
-int main() {
- dynarray< int > alpha(8);
- dynarray< int > gamma(3);
- for ( dynarray< int >::size_type i = 0; i < gamma.size(); i++ )
- gamma[i] = 4 - i;
- lowrap( alpha, gamma );
- int sum = 0;
- for ( dynarray< int >::size_type i = 0; i < alpha.size(); i++ )
- sum += alpha.at(i);
- return sum - 23;
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ #include "a1dynarray-use2.cci"
+ #include "a1dynarray-use4a.cci"
+ return sum - 25;
}
===================================================================
@@ -7,69 +7,13 @@ extern "C" void exit(int) throw();
template< typename T >
struct dynarray
{
- // types:
- typedef T value_type;
- typedef T& reference;
- typedef const T& const_reference;
- typedef T* iterator;
- typedef const T* const_iterator;
- typedef unsigned long size_type;
- typedef long difference_type;
-
- // fields:
-private:
- T* store;
- size_type count;
-
- // helper functions:
- void check(size_type n)
- { if ( n >= count ) exit(1); }
- T* alloc(size_type n)
- { return reinterpret_cast<T*>( new char[ n*sizeof(T) ] ); }
-
-public:
- // construct and destruct:
- dynarray(); // undefined
- const dynarray operator=(const dynarray&); // undefined
-
- explicit dynarray(size_type c)
- : store( alloc( c ) ), count( c ) { }
-
- dynarray(const dynarray& d)
- : store( alloc( d.count ) ), count( d.count )
- { memcpy( store, d.store, count * sizeof(T) ); }
-
- ~dynarray()
- { delete[] store; }
-
- // iterators:
- iterator begin() { return store; }
- const_iterator begin() const { return store; }
- const_iterator cbegin() const { return store; }
- iterator end() { return store + count; }
- const_iterator end() const { return store + count; }
- const_iterator cend() const { return store + count; }
-
- // capacity:
- size_type size() const { return count; }
- size_type max_size() const { return count; }
- bool empty() const { return false; }
-
- // element access:
- reference operator[](size_type n) { return store[n]; }
- const_reference operator[](size_type n) const { return store[n]; }
-
- reference front() { return store[0]; }
- const_reference front() const { return store[0]; }
- reference back() { return store[count-1]; }
- const_reference back() const { return store[count-1]; }
-
- const_reference at(size_type n) const { check(n); return store[n]; }
- reference at(size_type n) { check(n); return store[n]; }
-
- // data access:
- T* data() { return store; }
- const T* data() const { return store; }
+ #include "a1dynarray-dcl1.hi"
+ #include "a1dynarray-dcl2a.hi"
+ #include "a1dynarray-dcl3.hi"
};
+#include "a1dynarray-dfn1a.hi"
+#include "a1dynarray-dfn2a.hi"
+#include "a1dynarray-dfn3a.hi"
+
#endif
===================================================================
@@ -0,0 +1,17 @@
+#ifndef X1DYNARRAY5_H
+#define X1DYNARRAY5_H
+
+#include "x1dynarray4.h"
+
+#include <new>
+#include <memory>
+
+namespace tst {
+
+#include "a1dynarray-dfn1b.hi"
+#include "a1dynarray-dfn2c.hi"
+#include "a1dynarray-dfn3b.hi"
+
+} // namespace tst
+
+#endif
===================================================================
@@ -0,0 +1,3 @@
+ // system-based types:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
===================================================================
@@ -0,0 +1,23 @@
+template< typename T >
+dynarray<T>::dynarray(size_type c)
+: store( alloc( c ) ), count( c )
+{
+ size_type i;
+ try {
+ for ( size_type i = 0; i < count; ++i )
+ new (store+i) T;
+ }
+ catch ( ... ) {
+ for ( ; i > 0; --i )
+ (store+(i-1))->~T();
+ throw;
+ }
+}
+
+template< typename T >
+dynarray<T>::~dynarray()
+{
+ for ( size_type i = 0; i < count; ++i )
+ (store+i)->~T();
+ delete[] store;
+}
===================================================================
@@ -0,0 +1,3 @@
+template< typename T >
+void dynarray<T>::check(size_type n)
+{ if ( n >= count ) throw n; }
===================================================================
@@ -0,0 +1,14 @@
+// { dg-do run }
+
+#include "x1dynarray2.h"
+
+typedef int integer;
+typedef tst::dynarray< integer > integer_array;
+
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ #include "a1dynarray-use2.cci"
+ #include "a1dynarray-use4a.cci"
+ return sum - 25;
+}
===================================================================
@@ -0,0 +1,19 @@
+// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-bogus "cstdlib:42:0: error: PPH file stdlib.pph fails macro validation, __STDDEF_H__" "" { xfail *-*-* } 0 }
+
+#include "x1dynarray5.h"
+
+#include <algorithm>
+
+#include "a1integer.h"
+typedef tst::dynarray< integer > integer_array;
+
+int main()
+{
+ #include "a1dynarray-use1.cci"
+ std::sort( sorted.begin(), sorted.end() );
+ #include "a1dynarray-use2.cci"
+ #include "a1dynarray-use3a.cci"
+ #include "a1dynarray-use4a.cci"
+ return sum - 23;
+}