3 * Copyright (c) 1998-2005
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)
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.
19 #ifndef BOOST_REGEX_WORKAROUND_HPP
20 #define BOOST_REGEX_WORKAROUND_HPP
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 #include <boost/regex/config.hpp>
46 #ifndef BOOST_NO_STD_LOCALE
50 #if defined(BOOST_NO_STDC_NAMESPACE)
52 using ::sprintf; using ::strcpy; using ::strcat; using ::strlen;
56 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
57 #ifdef BOOST_NO_STD_DISTANCE
59 std::ptrdiff_t distance(const T& x, const T& y)
67 #ifdef BOOST_REGEX_NO_BOOL
68 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false)
70 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x)
73 /*****************************************************************************
75 * Fix broken namespace support:
77 ****************************************************************************/
79 #if defined(BOOST_NO_STDC_NAMESPACE) && defined(__cplusplus)
91 /*****************************************************************************
93 * helper functions pointer_construct/pointer_destroy:
95 ****************************************************************************/
98 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
101 #pragma warning (push)
102 #pragma warning (disable : 4100)
106 inline void pointer_destroy(T* p)
107 { p->~T(); (void)p; }
110 #pragma warning (pop)
114 inline void pointer_construct(T* p, const T& t)
120 /*****************************************************************************
122 * helper function copy:
124 ****************************************************************************/
127 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
128 #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))
130 // MSVC 8 will either emit warnings or else refuse to compile
131 // code that makes perfectly legitimate use of std::copy, when
132 // the OutputIterator type is a user-defined class (apparently all user
133 // defined iterators are "unsafe"). This code works around that:
135 template<class InputIterator, class OutputIterator>
136 inline OutputIterator copy(
142 return stdext::unchecked_copy(first, last, dest);
144 template<class InputIterator1, class InputIterator2>
146 InputIterator1 first,
151 return stdext::unchecked_equal(first, last, with);
153 #elif BOOST_WORKAROUND(BOOST_MSVC, > 1500)
155 // MSVC 10 will either emit warnings or else refuse to compile
156 // code that makes perfectly legitimate use of std::copy, when
157 // the OutputIterator type is a user-defined class (apparently all user
158 // defined iterators are "unsafe"). What's more Microsoft have removed their
159 // non-standard "unchecked" versions, even though their still in the MS
160 // documentation!! Work around this as best we can:
162 template<class InputIterator, class OutputIterator>
163 inline OutputIterator copy(
173 template<class InputIterator1, class InputIterator2>
175 InputIterator1 first,
181 if(*first++ != *with++) return false;
188 #if BOOST_WORKAROUND(BOOST_MSVC,>=1400) && defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__
190 // use safe versions of strcpy etc:
194 inline std::size_t strcpy_s(
195 char *strDestination,
196 std::size_t sizeInBytes,
197 const char *strSource
200 if(std::strlen(strSource)+1 > sizeInBytes)
202 std::strcpy(strDestination, strSource);
205 inline std::size_t strcat_s(
206 char *strDestination,
207 std::size_t sizeInBytes,
208 const char *strSource
211 if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes)
213 std::strcat(strDestination, strSource);
219 inline void overflow_error_if_not_zero(std::size_t i)
223 std::overflow_error e("String buffer too small");
224 boost::throw_exception(e);
230 #endif // __cplusplus
232 #endif // include guard