strict 2-phase ADL fixes.

[SVN r19152]
This commit is contained in:
Dave Abrahams 2003-07-16 15:16:21 +00:00
parent 632f682292
commit f1aff5670c

View File

@ -14,6 +14,7 @@
#include <list> #include <list>
#include <algorithm> #include <algorithm>
#include <boost/detail/binary_search.hpp> #include <boost/detail/binary_search.hpp>
#include <boost/detail/workaround.hpp>
#if defined(__SGI_STL_PORT) ? defined(__SGI_STL_OWN_IOSTREAMS) : (!defined(__GNUC__) || __GNUC__ > 2) #if defined(__SGI_STL_PORT) ? defined(__SGI_STL_OWN_IOSTREAMS) : (!defined(__GNUC__) || __GNUC__ > 2)
# define USE_SSTREAM # define USE_SSTREAM
@ -27,7 +28,16 @@
namespace { namespace {
typedef std::vector<std::string> string_vector; // In order to get ADL to find the comparison operators defined below, they have
struct mystring : std::string
{
typedef std::string base;
mystring(std::string const& x)
: base(x) {}
};
typedef std::vector<mystring> string_vector;
const std::size_t sequence_length = 1000; const std::size_t sequence_length = 1000;
@ -74,20 +84,21 @@ struct cmp
} }
}; };
inline bool operator<(const std::string& x, const unsigned y) inline bool operator<(const mystring& x, const unsigned y)
{ {
return to_int(x) < y; return to_int(x) < y;
} }
inline bool operator<(const unsigned y, const std::string& x) inline bool operator<(const unsigned y, const mystring& x)
{ {
return y < to_int(x); return y < to_int(x);
} }
template <class T> void sort_by_value(T&); template <class T>
void sort_by_value(T& x);
template <> template <class T>
void sort_by_value(std::vector<std::string>& v) void sort_by_value_(T& v, ...)
{ {
std::sort(v.begin(), v.end(), cmp()); std::sort(v.begin(), v.end(), cmp());
} }
@ -103,28 +114,26 @@ void random_sorted_sequence(T& seq)
sort_by_value(seq); sort_by_value(seq);
} }
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300 && !defined(__SGI_STL_PORT) template <class T, class A>
void sort_by_value_(std::list<T,A>& l, int)
{
# if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) && !defined(__SGI_STL_PORT)
// VC6's standard lib doesn't have a template member function for list::sort() // VC6's standard lib doesn't have a template member function for list::sort()
template <> std::vector<T> seq;
void random_sorted_sequence(std::list<std::string>& result)
{
std::vector<std::string> seq;
seq.reserve(sequence_length); seq.reserve(sequence_length);
for (std::size_t i = 0; i < sequence_length; ++i) std::copy(l.begin(), l.end(), std::back_inserter(seq));
{
push_back_random_number_string(seq);
}
sort_by_value(seq); sort_by_value(seq);
result.resize(seq.size()); std::copy(seq.begin(), seq.end(), l.begin());
std::copy(seq.begin(), seq.end(), result.begin()); # else
}
#else
template <>
void sort_by_value(std::list<std::string>& l)
{
l.sort(cmp()); l.sort(cmp());
}
# endif # endif
}
template <class T>
void sort_by_value(T& x)
{
(sort_by_value_)(x, 1);
}
// A way to select the comparisons with/without a Compare parameter for testing. // A way to select the comparisons with/without a Compare parameter for testing.
template <class Compare> struct searches template <class Compare> struct searches
@ -233,13 +242,13 @@ void test_loop(Sequence& x, Compare cmp, unsigned long test_count)
int main() int main()
{ {
std::vector<std::string> x; string_vector x;
std::cout << "=== testing random-access iterators with <: ===\n"; std::cout << "=== testing random-access iterators with <: ===\n";
test_loop(x, no_compare(), 25); test_loop(x, no_compare(), 25);
std::cout << "=== testing random-access iterators with compare: ===\n"; std::cout << "=== testing random-access iterators with compare: ===\n";
test_loop(x, cmp(), 25); test_loop(x, cmp(), 25);
std::list<std::string> y; std::list<mystring> y;
std::cout << "=== testing bidirectional iterators with <: ===\n"; std::cout << "=== testing bidirectional iterators with <: ===\n";
test_loop(y, no_compare(), 25); test_loop(y, no_compare(), 25);
std::cout << "=== testing bidirectional iterators with compare: ===\n"; std::cout << "=== testing bidirectional iterators with compare: ===\n";