]> git.lyx.org Git - lyx.git/blob - boost/boost/regex/v4/regex_workaround.hpp
update boost to 1.43: remove obsolete files, update .cpp
[lyx.git] / boost / boost / regex / v4 / regex_workaround.hpp
1 /*
2  *
3  * Copyright (c) 1998-2005
4  * John Maddock
5  *
6  * Use, modification and distribution are subject to the 
7  * Boost Software License, Version 1.0. (See accompanying file 
8  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9  *
10  */
11
12  /*
13   *   LOCATION:    see http://www.boost.org for most recent version.
14   *   FILE         regex_workarounds.cpp
15   *   VERSION      see <boost/version.hpp>
16   *   DESCRIPTION: Declares Misc workarounds.
17   */
18
19 #ifndef BOOST_REGEX_WORKAROUND_HPP
20 #define BOOST_REGEX_WORKAROUND_HPP
21
22
23 #include <new>
24 #include <cstring>
25 #include <cstdlib>
26 #include <cstddef>
27 #include <cassert>
28 #include <cstdio>
29 #include <climits>
30 #include <string>
31 #include <stdexcept>
32 #include <iterator>
33 #include <algorithm>
34 #include <iosfwd>
35 #include <vector>
36 #include <map>
37 #include <boost/limits.hpp>
38 #include <boost/assert.hpp>
39 #include <boost/cstdint.hpp>
40 #include <boost/throw_exception.hpp>
41 #include <boost/scoped_ptr.hpp>
42 #include <boost/scoped_array.hpp>
43 #include <boost/shared_ptr.hpp>
44 #include <boost/mpl/bool_fwd.hpp>
45 #ifndef BOOST_NO_STD_LOCALE
46 #   include <locale>
47 #endif
48
49 #if defined(BOOST_NO_STDC_NAMESPACE)
50 namespace std{
51    using ::sprintf; using ::strcpy; using ::strcat; using ::strlen;
52 }
53 #endif
54
55 namespace boost{ namespace re_detail{
56 #ifdef BOOST_NO_STD_DISTANCE
57 template <class T>
58 std::ptrdiff_t distance(const T& x, const T& y)
59 { return y - x; }
60 #else
61 using std::distance;
62 #endif
63 }}
64
65
66 #ifdef BOOST_REGEX_NO_BOOL
67 #  define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false)
68 #else
69 #  define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x)
70 #endif
71
72 /*****************************************************************************
73  *
74  *  Fix broken broken namespace support:
75  *
76  ****************************************************************************/
77
78 #if defined(BOOST_NO_STDC_NAMESPACE) && defined(__cplusplus)
79
80 namespace std{
81    using ::ptrdiff_t;
82    using ::size_t;
83    using ::abs;
84    using ::memset;
85    using ::memcpy;
86 }
87
88 #endif
89
90 /*****************************************************************************
91  *
92  *  helper functions pointer_construct/pointer_destroy:
93  *
94  ****************************************************************************/
95
96 #ifdef __cplusplus
97 namespace boost{ namespace re_detail{
98
99 #ifdef BOOST_MSVC
100 #pragma warning (push)
101 #pragma warning (disable : 4100)
102 #endif
103
104 template <class T>
105 inline void pointer_destroy(T* p)
106 { p->~T(); (void)p; }
107
108 #ifdef BOOST_MSVC
109 #pragma warning (pop)
110 #endif
111
112 template <class T>
113 inline void pointer_construct(T* p, const T& t)
114 { new (p) T(t); }
115
116 }} // namespaces
117 #endif
118
119 /*****************************************************************************
120  *
121  *  helper function copy:
122  *
123  ****************************************************************************/
124
125 #ifdef __cplusplus
126 namespace boost{ namespace re_detail{
127 #if BOOST_WORKAROUND(BOOST_MSVC,>=1400) && BOOST_WORKAROUND(BOOST_MSVC, <1600) && defined(_CPPLIB_VER) && defined(BOOST_DINKUMWARE_STDLIB) && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION))
128    //
129    // MSVC 8 will either emit warnings or else refuse to compile
130    // code that makes perfectly legitimate use of std::copy, when
131    // the OutputIterator type is a user-defined class (apparently all user 
132    // defined iterators are "unsafe").  This code works around that:
133    //
134    template<class InputIterator, class OutputIterator>
135    inline OutputIterator copy(
136       InputIterator first, 
137       InputIterator last, 
138       OutputIterator dest
139    )
140    {
141       return stdext::unchecked_copy(first, last, dest);
142    }
143    template<class InputIterator1, class InputIterator2>
144    inline bool equal(
145       InputIterator1 first, 
146       InputIterator1 last, 
147       InputIterator2 with
148    )
149    {
150       return stdext::unchecked_equal(first, last, with);
151    }
152 #elif BOOST_WORKAROUND(BOOST_MSVC, > 1500)
153    //
154    // MSVC 10 will either emit warnings or else refuse to compile
155    // code that makes perfectly legitimate use of std::copy, when
156    // the OutputIterator type is a user-defined class (apparently all user 
157    // defined iterators are "unsafe").  What's more Microsoft have removed their
158    // non-standard "unchecked" versions, even though their still in the MS
159    // documentation!! Work around this as best we can: 
160    //
161    template<class InputIterator, class OutputIterator>
162    inline OutputIterator copy(
163       InputIterator first, 
164       InputIterator last, 
165       OutputIterator dest
166    )
167    {
168       while(first != last)
169          *dest++ = *first++;
170       return dest;
171    }
172    template<class InputIterator1, class InputIterator2>
173    inline bool equal(
174       InputIterator1 first, 
175       InputIterator1 last, 
176       InputIterator2 with
177    )
178    {
179       while(first != last)
180          if(*first++ != *with++) return false;
181       return true;
182    }
183 #else 
184    using std::copy; 
185    using std::equal; 
186 #endif 
187 #if BOOST_WORKAROUND(BOOST_MSVC,>=1400) && defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__ 
188
189    // use safe versions of strcpy etc:
190    using ::strcpy_s;
191    using ::strcat_s;
192 #else
193    inline std::size_t strcpy_s(
194       char *strDestination,
195       std::size_t sizeInBytes,
196       const char *strSource 
197    )
198    {
199       if(std::strlen(strSource)+1 > sizeInBytes)
200          return 1;
201       std::strcpy(strDestination, strSource);
202       return 0;
203    }
204    inline std::size_t strcat_s(
205       char *strDestination,
206       std::size_t sizeInBytes,
207       const char *strSource 
208    )
209    {
210       if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes)
211          return 1;
212       std::strcat(strDestination, strSource);
213       return 0;
214    }
215
216 #endif
217
218    inline void overflow_error_if_not_zero(std::size_t i)
219    {
220       if(i)
221       {
222          std::overflow_error e("String buffer too small");
223          boost::throw_exception(e);
224       }
225    }
226
227 }} // namespaces
228
229 #endif // __cplusplus
230
231 #endif // include guard
232