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 #ifndef BOOST_NO_STD_LOCALE
49 #if defined(BOOST_NO_STDC_NAMESPACE)
51 using ::sprintf; using ::strcpy; using ::strcat; using ::strlen;
55 namespace boost{ namespace re_detail{
56 #ifdef BOOST_NO_STD_DISTANCE
58 std::ptrdiff_t distance(const T& x, const T& y)
66 #ifdef BOOST_REGEX_NO_BOOL
67 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false)
69 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x)
72 /*****************************************************************************
74 * Fix broken broken namespace support:
76 ****************************************************************************/
78 #if defined(BOOST_NO_STDC_NAMESPACE) && defined(__cplusplus)
90 /*****************************************************************************
92 * helper functions pointer_construct/pointer_destroy:
94 ****************************************************************************/
97 namespace boost{ namespace re_detail{
100 #pragma warning (push)
101 #pragma warning (disable : 4100)
105 inline void pointer_destroy(T* p)
106 { p->~T(); (void)p; }
109 #pragma warning (pop)
113 inline void pointer_construct(T* p, const T& t)
119 /*****************************************************************************
121 * helper function copy:
123 ****************************************************************************/
126 namespace boost{ namespace re_detail{
127 #if BOOST_WORKAROUND(BOOST_MSVC,>=1400) && defined(_CPPLIB_VER) && defined(BOOST_DINKUMWARE_STDLIB) && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION))
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:
134 template<class InputIterator, class OutputIterator>
135 inline OutputIterator copy(
141 return stdext::unchecked_copy(first, last, dest);
143 template<class InputIterator1, class InputIterator2>
145 InputIterator1 first,
150 return stdext::unchecked_equal(first, last, with);
157 #if BOOST_WORKAROUND(BOOST_MSVC,>=1400) && defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__
159 // use safe versions of strcpy etc:
163 inline std::size_t strcpy_s(
164 char *strDestination,
165 std::size_t sizeInBytes,
166 const char *strSource
169 if(std::strlen(strSource)+1 > sizeInBytes)
171 std::strcpy(strDestination, strSource);
174 inline std::size_t strcat_s(
175 char *strDestination,
176 std::size_t sizeInBytes,
177 const char *strSource
180 if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes)
182 std::strcat(strDestination, strSource);
188 inline void overflow_error_if_not_zero(std::size_t i)
192 std::overflow_error e("String buffer too small");
193 boost::throw_exception(e);
199 #endif // __cplusplus
201 #endif // include guard