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
38 #include <boost/limits.hpp>
39 #include <boost/assert.hpp>
40 #include <boost/cstdint.hpp>
41 #include <boost/throw_exception.hpp>
42 #include <boost/scoped_ptr.hpp>
43 #include <boost/scoped_array.hpp>
44 #include <boost/shared_ptr.hpp>
45 #include <boost/mpl/bool_fwd.hpp>
46 #include <boost/regex/config.hpp>
47 #ifndef BOOST_NO_STD_LOCALE
51 #if defined(BOOST_NO_STDC_NAMESPACE)
53 using ::sprintf; using ::strcpy; using ::strcat; using ::strlen;
57 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
58 #ifdef BOOST_NO_STD_DISTANCE
60 std::ptrdiff_t distance(const T& x, const T& y)
68 #ifdef BOOST_REGEX_NO_BOOL
69 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false)
71 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x)
74 /*****************************************************************************
76 * Fix broken namespace support:
78 ****************************************************************************/
80 #if defined(BOOST_NO_STDC_NAMESPACE) && defined(__cplusplus)
92 /*****************************************************************************
94 * helper functions pointer_construct/pointer_destroy:
96 ****************************************************************************/
99 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
102 #pragma warning (push)
103 #pragma warning (disable : 4100)
107 inline void pointer_destroy(T* p)
108 { p->~T(); (void)p; }
111 #pragma warning (pop)
115 inline void pointer_construct(T* p, const T& t)
121 /*****************************************************************************
123 * helper function copy:
125 ****************************************************************************/
128 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
129 #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))
131 // MSVC 8 will either emit warnings or else refuse to compile
132 // code that makes perfectly legitimate use of std::copy, when
133 // the OutputIterator type is a user-defined class (apparently all user
134 // defined iterators are "unsafe"). This code works around that:
136 template<class InputIterator, class OutputIterator>
137 inline OutputIterator copy(
143 return stdext::unchecked_copy(first, last, dest);
145 template<class InputIterator1, class InputIterator2>
147 InputIterator1 first,
152 return stdext::unchecked_equal(first, last, with);
154 #elif BOOST_WORKAROUND(BOOST_MSVC, > 1500)
156 // MSVC 10 will either emit warnings or else refuse to compile
157 // code that makes perfectly legitimate use of std::copy, when
158 // the OutputIterator type is a user-defined class (apparently all user
159 // defined iterators are "unsafe"). What's more Microsoft have removed their
160 // non-standard "unchecked" versions, even though their still in the MS
161 // documentation!! Work around this as best we can:
163 template<class InputIterator, class OutputIterator>
164 inline OutputIterator copy(
174 template<class InputIterator1, class InputIterator2>
176 InputIterator1 first,
182 if(*first++ != *with++) return false;
189 #if BOOST_WORKAROUND(BOOST_MSVC,>=1400) && defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__
191 // use safe versions of strcpy etc:
195 inline std::size_t strcpy_s(
196 char *strDestination,
197 std::size_t sizeInBytes,
198 const char *strSource
201 if(std::strlen(strSource)+1 > sizeInBytes)
203 std::strcpy(strDestination, strSource);
206 inline std::size_t strcat_s(
207 char *strDestination,
208 std::size_t sizeInBytes,
209 const char *strSource
212 if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes)
214 std::strcat(strDestination, strSource);
220 inline void overflow_error_if_not_zero(std::size_t i)
224 std::overflow_error e("String buffer too small");
225 boost::throw_exception(e);
231 #endif // __cplusplus
233 #endif // include guard