Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
21.string.append.stdcxx-438.cpp
Go to the documentation of this file.
1
29#include <cassert>
30#include <cstdlib>
31#include <cstring>
32#include <iterator>
33#include <new>
34#include <string>
35
36#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
37 // disabled for compilers that can't reliably replace the operators
38
39void* operator new (std::size_t n) throw (std::bad_alloc)
40{
41 void* const ptr = std::malloc (n + sizeof n);
42 if (!ptr)
43 throw std::bad_alloc ();
44
45 std::memset (ptr, -1, n);
46 *(std::size_t*)ptr = n;
47 return (std::size_t*)ptr + 1;
48}
49
50void operator delete (void *ptr) throw ()
51{
52 if (ptr) {
53 std::memset (ptr, -1, *((std::size_t*)ptr - 1));
54 std::free ((std::size_t*)ptr - 1);
55 }
56}
57
58#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
59
60struct InputIterator: std::iterator<std::input_iterator_tag, char>
61{
62 const char *p_;
63 InputIterator (const char *p): p_ (p) { }
64
65 char operator* () const { return *p_; }
66 InputIterator& operator++ () { return ++p_, *this; }
67 InputIterator operator++ (int) {
68 return ++p_, InputIterator (p_ - 1);
69 }
70
71 bool operator== (const InputIterator &rhs) const { return p_ == rhs.p_; }
72};
73
74
75int main ()
76{
77 const char s[] = "abc";
78
79 {
80 std::string str (s);
81
82 const char* p0 = s + 1;
83 const char* p1 = p0 + 1;
84
85 const InputIterator first (p0);
86 const InputIterator last (p1);
87
88 str.append (first, last);
89
90 assert ("abcb" == str);
91 }
92
93 {
94 std::string str (s);
95
96 const char* p0 = str.data () + 1;
97 const char* p1 = p0 + 1;
98
99 const InputIterator first (p0);
100 const InputIterator last (p1);
101
102 str.append (first, last);
103
104 assert ("abcb" == str);
105 }
106
107 return 0;
108}
#define rhs
Definition 17.names.cpp:536
#define p_
Definition 17.names.cpp:186
#define InputIterator
Definition 17.names.cpp:481
#define ptr
Definition 17.names.cpp:525
#define last
Definition 17.names.cpp:487
#define s
#define n
Definition 17.names.cpp:130
#define p1
Definition 17.names.cpp:239
#define p
Definition 17.names.cpp:132
const plus_asgn< T > & operator*(const plus_asgn< T > &lhs, const plus_asgn< T > &rhs)
#define assert(expr)
Definition _cassert.h:40
const char * str
Definition exec.cpp:170
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737