mirror of
https://github.com/boostorg/utility.git
synced 2025-05-08 18:34:02 +00:00
Removed type_traits include, added more tests
[SVN r27712]
This commit is contained in:
parent
ae19cd6236
commit
dcb2dd4736
@ -7,43 +7,88 @@
|
||||
|
||||
// For more information, see http://www.boost.org
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
#include <boost/utility/addressof.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||
#pragma warning(push, 3)
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
template<class T> void scalar_test( T * = 0 )
|
||||
{
|
||||
T* px = new T();
|
||||
|
||||
T& x = *px;
|
||||
BOOST_TEST( boost::addressof(x) == px );
|
||||
|
||||
const T& cx = *px;
|
||||
const T* pcx = boost::addressof(cx);
|
||||
BOOST_TEST( pcx == px );
|
||||
|
||||
volatile T& vx = *px;
|
||||
volatile T* pvx = boost::addressof(vx);
|
||||
BOOST_TEST( pvx == px );
|
||||
|
||||
const volatile T& cvx = *px;
|
||||
const volatile T* pcvx = boost::addressof(cvx);
|
||||
BOOST_TEST( pcvx == px );
|
||||
|
||||
delete px;
|
||||
}
|
||||
|
||||
template<class T> void array_test( T * = 0 )
|
||||
{
|
||||
T nrg[3] = {1,2,3};
|
||||
T (*pnrg)[3] = &nrg;
|
||||
BOOST_TEST( boost::addressof(nrg) == pnrg );
|
||||
|
||||
T const cnrg[3] = {1,2,3};
|
||||
T const (*pcnrg)[3] = &cnrg;
|
||||
BOOST_TEST( boost::addressof(cnrg) == pcnrg );
|
||||
}
|
||||
|
||||
struct addressable
|
||||
{
|
||||
addressable( int = 0 )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct useless_type {};
|
||||
|
||||
class nonaddressable {
|
||||
public:
|
||||
void dummy(); // Silence GCC warning: all member of class are private
|
||||
|
||||
nonaddressable( int = 0 )
|
||||
{
|
||||
}
|
||||
|
||||
void dummy(); // Silence GCC warning: all member of class are private
|
||||
|
||||
private:
|
||||
useless_type operator&() const;
|
||||
|
||||
useless_type operator&() const;
|
||||
};
|
||||
|
||||
int test_main(int, char*[])
|
||||
int main()
|
||||
{
|
||||
nonaddressable* px = new nonaddressable();
|
||||
scalar_test<char>();
|
||||
scalar_test<int>();
|
||||
scalar_test<addressable>();
|
||||
scalar_test<nonaddressable>();
|
||||
|
||||
nonaddressable& x = *px;
|
||||
BOOST_CHECK(boost::addressof(x) == px);
|
||||
array_test<char>();
|
||||
array_test<int>();
|
||||
array_test<addressable>();
|
||||
array_test<nonaddressable>();
|
||||
|
||||
const nonaddressable& cx = *px;
|
||||
BOOST_CHECK(boost::addressof(cx) == static_cast<const nonaddressable*>(px));
|
||||
|
||||
volatile nonaddressable& vx = *px;
|
||||
BOOST_CHECK(boost::addressof(vx) == static_cast<volatile nonaddressable*>(px));
|
||||
|
||||
const volatile nonaddressable& cvx = *px;
|
||||
BOOST_CHECK(boost::addressof(cvx) == static_cast<const volatile nonaddressable*>(px));
|
||||
|
||||
int nrg[3] = {1,2,3};
|
||||
int (*pnrg)[3] = &nrg;
|
||||
BOOST_CHECK(boost::addressof(nrg) == pnrg);
|
||||
|
||||
int const cnrg[3] = {1,2,3};
|
||||
int const (*pcnrg)[3] = &cnrg;
|
||||
BOOST_CHECK(boost::addressof(cnrg) == pcnrg);
|
||||
|
||||
return 0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -13,9 +13,6 @@
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
||||
# include <boost/type_traits/add_pointer.hpp>
|
||||
# endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -23,7 +20,14 @@ namespace boost {
|
||||
|
||||
// VC7 strips const from nested classes unless we add indirection here
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
||||
template <typename T> typename add_pointer<T>::type
|
||||
|
||||
template<class T> struct _addp
|
||||
{
|
||||
typedef T * type;
|
||||
};
|
||||
|
||||
template <typename T> typename _addp<T>::type
|
||||
|
||||
# else
|
||||
template <typename T> T*
|
||||
# endif
|
||||
|
@ -19,7 +19,7 @@ local test_monitor = <lib>@boost/libs/test/build/boost_test_exec_monitor ;
|
||||
# Please keep the tests ordered by filename
|
||||
test-suite utility
|
||||
:
|
||||
[ run ../addressof_test.cpp $(test_monitor) ]
|
||||
[ run ../addressof_test.cpp ]
|
||||
[ run ../assert_test.cpp ]
|
||||
[ run ../base_from_member_test.cpp ]
|
||||
[ run ../binary_search_test.cpp ]
|
||||
|
@ -12,7 +12,7 @@ import testing ;
|
||||
# Please keep the tests ordered by filename
|
||||
test-suite utility
|
||||
:
|
||||
[ run ../addressof_test.cpp ../../test/build//boost_test_exec_monitor ]
|
||||
[ run ../addressof_test.cpp ]
|
||||
[ run ../assert_test.cpp ]
|
||||
[ run ../base_from_member_test.cpp ]
|
||||
[ run ../binary_search_test.cpp ]
|
||||
|
Loading…
x
Reference in New Issue
Block a user