Fix a regression failure on MSVC 8 and 9; thanks to Eric Niebler for the fix

[SVN r81711]
This commit is contained in:
Marshall Clow
2012-12-04 22:12:47 +00:00
parent a7190c0044
commit 6afae475fe

View File

@ -16,6 +16,7 @@
#define BOOST_STRING_REF_HPP #define BOOST_STRING_REF_HPP
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
@ -144,11 +145,16 @@ namespace boost {
// basic_string_ref string operations // basic_string_ref string operations
BOOST_CONSTEXPR BOOST_CONSTEXPR
basic_string_ref substr(size_type pos, size_type n=npos) const { basic_string_ref substr(size_type pos, size_type n=npos) const {
// if ( pos > size()) throw std::out_of_range ( "string_ref::substr" ); #if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
// if ( n == npos || pos + n > size()) n = size () - pos; // Looks like msvc 8 and 9 have a codegen bug when one branch of
// return basic_string_ref ( data() + pos, n ); // a conditional operator is a throw expression. -EAN 2012/12/04
if ( pos > size()) throw std::out_of_range ( "string_ref::substr" );
if ( n == npos || pos + n > size()) n = size () - pos;
return basic_string_ref ( data() + pos, n );
#else
return pos > size() ? throw std::out_of_range ( "string_ref::substr" ) : return pos > size() ? throw std::out_of_range ( "string_ref::substr" ) :
basic_string_ref ( data() + pos, n == npos || pos + n > size() ? size() - pos : n ); basic_string_ref ( data() + pos, n == npos || pos + n > size() ? size() - pos : n );
#endif
} }
int compare(basic_string_ref x) const { int compare(basic_string_ref x) const {