mirror of
https://github.com/boostorg/function.git
synced 2025-07-23 09:27:14 +02:00
Fix tests for compilers that actually have a real is_stateless
[SVN r28784]
This commit is contained in:
@ -41,11 +41,20 @@ struct counting_allocator : public std::allocator<T>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct plus_int
|
||||||
|
{
|
||||||
|
int operator()(int x, int y) const { return x + y; }
|
||||||
|
|
||||||
|
int unused_state_data;
|
||||||
|
};
|
||||||
|
|
||||||
static int do_minus(int x, int y) { return x-y; }
|
static int do_minus(int x, int y) { return x-y; }
|
||||||
|
|
||||||
struct DoNothing
|
struct DoNothing
|
||||||
{
|
{
|
||||||
void operator()() const {}
|
void operator()() const {}
|
||||||
|
|
||||||
|
int unused_state_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void do_nothing() {}
|
static void do_nothing() {}
|
||||||
@ -54,7 +63,7 @@ int
|
|||||||
test_main(int, char*[])
|
test_main(int, char*[])
|
||||||
{
|
{
|
||||||
function2<int, int, int, counting_allocator<int> > f;
|
function2<int, int, int, counting_allocator<int> > f;
|
||||||
f = plus<int>();
|
f = plus_int();
|
||||||
f.clear();
|
f.clear();
|
||||||
BOOST_CHECK(alloc_count == 1);
|
BOOST_CHECK(alloc_count == 1);
|
||||||
BOOST_CHECK(dealloc_count == 1);
|
BOOST_CHECK(dealloc_count == 1);
|
||||||
@ -63,6 +72,8 @@ test_main(int, char*[])
|
|||||||
dealloc_count = 0;
|
dealloc_count = 0;
|
||||||
f = &do_minus;
|
f = &do_minus;
|
||||||
f.clear();
|
f.clear();
|
||||||
|
BOOST_CHECK(alloc_count == 0);
|
||||||
|
BOOST_CHECK(dealloc_count == 0);
|
||||||
|
|
||||||
function0<void, counting_allocator<int> > fv;
|
function0<void, counting_allocator<int> > fv;
|
||||||
alloc_count = 0;
|
alloc_count = 0;
|
||||||
@ -76,6 +87,8 @@ test_main(int, char*[])
|
|||||||
dealloc_count = 0;
|
dealloc_count = 0;
|
||||||
fv = &do_nothing;
|
fv = &do_nothing;
|
||||||
fv.clear();
|
fv.clear();
|
||||||
|
BOOST_CHECK(alloc_count == 0);
|
||||||
|
BOOST_CHECK(dealloc_count == 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -630,70 +630,6 @@ test_ref()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int alloc_count = 0;
|
|
||||||
static int dealloc_count = 0;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct counting_allocator : public allocator<T>
|
|
||||||
{
|
|
||||||
template<typename U>
|
|
||||||
struct rebind
|
|
||||||
{
|
|
||||||
typedef counting_allocator<U> other;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
T* allocate(size_t n)
|
|
||||||
{
|
|
||||||
alloc_count++;
|
|
||||||
return allocator<T>::allocate(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deallocate(T* p, size_t n)
|
|
||||||
{
|
|
||||||
dealloc_count++;
|
|
||||||
allocator<T>::deallocate(p, n);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static int do_minus(int x, int y) { return x-y; }
|
|
||||||
|
|
||||||
struct DoNothing
|
|
||||||
{
|
|
||||||
void operator()() const {}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void do_nothing() {}
|
|
||||||
|
|
||||||
static void test_allocator()
|
|
||||||
{
|
|
||||||
#ifndef BOOST_NO_STD_ALLOCATOR
|
|
||||||
boost::function<int (int, int), counting_allocator<int> > f;
|
|
||||||
f = plus<int>();
|
|
||||||
f.clear();
|
|
||||||
BOOST_CHECK(alloc_count == 1);
|
|
||||||
BOOST_CHECK(dealloc_count == 1);
|
|
||||||
|
|
||||||
alloc_count = 0;
|
|
||||||
dealloc_count = 0;
|
|
||||||
f = &do_minus;
|
|
||||||
f.clear();
|
|
||||||
|
|
||||||
boost::function<void (), counting_allocator<int> > fv;
|
|
||||||
alloc_count = 0;
|
|
||||||
dealloc_count = 0;
|
|
||||||
fv = DoNothing();
|
|
||||||
fv.clear();
|
|
||||||
BOOST_CHECK(alloc_count == 1);
|
|
||||||
BOOST_CHECK(dealloc_count == 1);
|
|
||||||
|
|
||||||
alloc_count = 0;
|
|
||||||
dealloc_count = 0;
|
|
||||||
fv = &do_nothing;
|
|
||||||
fv.clear();
|
|
||||||
#endif // ndef BOOST_NO_STD_ALLOCATOR
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_exception()
|
static void test_exception()
|
||||||
{
|
{
|
||||||
boost::function<int (int, int)> f;
|
boost::function<int (int, int)> f;
|
||||||
@ -739,7 +675,6 @@ int test_main(int, char* [])
|
|||||||
test_emptiness();
|
test_emptiness();
|
||||||
test_member_functions();
|
test_member_functions();
|
||||||
test_ref();
|
test_ref();
|
||||||
test_allocator();
|
|
||||||
test_exception();
|
test_exception();
|
||||||
test_implicit();
|
test_implicit();
|
||||||
test_call();
|
test_call();
|
||||||
|
Reference in New Issue
Block a user