forked from boostorg/core
Compare commits
12 Commits
feature/cm
...
boost-1.65
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb800a05e3 | ||
|
|
2d7f98c844 | ||
|
|
8914603fcf | ||
|
|
3792047e09 | ||
|
|
6de3da8360 | ||
|
|
e55d6279d5 | ||
|
|
a87fd099e7 | ||
|
|
09f4823baa | ||
|
|
526e0b2f53 | ||
|
|
ac6044769f | ||
|
|
2876914d02 | ||
|
|
36f60e47ad |
150
.travis.yml
150
.travis.yml
@@ -1,4 +1,4 @@
|
||||
# Copyright 2016 Peter Dimov
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@@ -109,6 +109,15 @@ matrix:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++03
|
||||
addons:
|
||||
@@ -145,6 +154,50 @@ matrix:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
@@ -217,6 +270,7 @@ matrix:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
@@ -227,10 +281,101 @@ matrix:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.9
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.9
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.9
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.9
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-4.0
|
||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-4.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-4.0
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-4.0
|
||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-4.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-4.0
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-4.0
|
||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-4.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-4.0
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-4.0
|
||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-4.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-4.0
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
@@ -240,6 +385,9 @@ matrix:
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++14
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++1z
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b $TRAVIS_BRANCH https://github.com/boostorg/boost.git boost-root
|
||||
|
||||
46
appveyor.yml
46
appveyor.yml
@@ -1,4 +1,4 @@
|
||||
# Copyright 2016 Peter Dimov
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@@ -11,6 +11,45 @@ branches:
|
||||
- master
|
||||
- develop
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
TOOLSET: msvc-9.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
TOOLSET: msvc-10.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
TOOLSET: msvc-11.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
TOOLSET: msvc-12.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
TOOLSET: gcc
|
||||
CXXFLAGS: cxxflags=-std=c++03
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
TOOLSET: gcc
|
||||
CXXFLAGS: cxxflags=-std=c++11
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
ADDPATH: C:\mingw\bin;
|
||||
TOOLSET: gcc
|
||||
CXXFLAGS: cxxflags=-std=c++03
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
ADDPATH: C:\mingw\bin;
|
||||
TOOLSET: gcc
|
||||
CXXFLAGS: cxxflags=-std=c++11
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
|
||||
TOOLSET: gcc
|
||||
CXXFLAGS: cxxflags=-std=c++03
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
|
||||
TOOLSET: gcc
|
||||
CXXFLAGS: cxxflags=-std=c++11
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-14.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost-root
|
||||
@@ -23,10 +62,11 @@ install:
|
||||
- git submodule init tools/build
|
||||
- git submodule update
|
||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\core
|
||||
- bootstrap
|
||||
- cmd /c bootstrap
|
||||
- b2 headers
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- b2 libs/core/test toolset=msvc-9.0,msvc-10.0,msvc-11.0,msvc-14.0
|
||||
- PATH=%ADDPATH%%PATH%
|
||||
- b2 libs/core/test toolset=%TOOLSET% %CXXFLAGS%
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
|
||||
[section Header <boost/core/noncopyable.hpp>]
|
||||
|
||||
The header `<boost/noncopyable.hpp>` defines the class
|
||||
The header `<boost/core/noncopyable.hpp>` defines the class
|
||||
`boost::noncopyable`. It is intended to be used as a private
|
||||
base. `boost::noncopyable` has private (under C++03) or
|
||||
base class. `boost::noncopyable` has private (under C++03) or
|
||||
deleted (under C++11) copy constructor and a copy assignment
|
||||
operator and can't be copied or assigned; a class that derives
|
||||
from it inherits these properties.
|
||||
|
||||
@@ -27,16 +27,15 @@ for obtaining raw pointers from pointers.
|
||||
|
||||
[section Examples]
|
||||
|
||||
The following function template obtains a raw pointer from a pointer and is
|
||||
well defined when the pointer aliases storage that has no object constructed
|
||||
in it.
|
||||
The following example allocates storage and constructs an object in that
|
||||
storage using an allocator.
|
||||
|
||||
```
|
||||
template<class T>
|
||||
inline typename boost::pointer_traits<T>::element_type*
|
||||
to_raw_pointer(T v) noexcept
|
||||
template<class Allocator>
|
||||
void function(Allocator& a)
|
||||
{
|
||||
return boost::pointer_traits<T>::to_address(v);
|
||||
auto p = a.allocate(1);
|
||||
std::allocator_traits<Allocator>::construct(a, boost::to_address(p));
|
||||
}
|
||||
```
|
||||
|
||||
@@ -55,7 +54,7 @@ namespace boost {
|
||||
template<class U> using rebind = typename rebind_to<U>::type;
|
||||
|
||||
static pointer pointer_to(``['see below]`` v);
|
||||
static element_type* to_address(pointer v) noexcept;
|
||||
static element_type* to_address(const pointer& v) noexcept;
|
||||
};
|
||||
|
||||
template<class T> struct pointer_traits<T*> {
|
||||
@@ -69,63 +68,64 @@ namespace boost {
|
||||
static pointer pointer_to(``['see below]`` v) noexcept;
|
||||
static element_type* to_address(pointer v) noexcept;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
typename pointer_traits<T>::element_type* to_address(const T& v) noexcept;
|
||||
}
|
||||
```
|
||||
|
||||
[section Member types]
|
||||
|
||||
[variablelist
|
||||
[[`typedef` ['see below] `element_type;`]
|
||||
[[variablelist
|
||||
[[Type]
|
||||
[`T::element_type` if such a type exists; otherwise `U` if `T` is a
|
||||
class template instantiation of the form `Pointer<U, Args>`, where
|
||||
`Args` is zero or more type arguments; otherwise the specialization
|
||||
is ill-formed.]]]]]
|
||||
[[`typedef` ['see below] `difference_type;`]
|
||||
[[variablelist
|
||||
[[Type]
|
||||
[`T::difference_type` if such a type exists; otherwise
|
||||
`std::ptrdiff_t`.]]]]]
|
||||
[[`template<class U> struct rebind_to { typedef` ['see below] `type; };`]
|
||||
[[variablelist
|
||||
[[Type]
|
||||
[`type` is `T::rebind<U>` if such a type exists; otherwise,
|
||||
`Pointer<V, Args>` if `T` is a class template instantiation of the
|
||||
form `Pointer<T, Args>`, where `Args` is zero or more type
|
||||
arguments; otherwise, the instantiation of `rebind_to` is
|
||||
ill-formed.]]]]]]
|
||||
[[`typedef` ['see below] `element_type;`]
|
||||
[`T::element_type` if such a type exists; otherwise `U` if `T` is a class
|
||||
template instantiation of the form `Pointer<U, Args>`, where `Args` is zero
|
||||
or more type arguments; otherwise the specialization is ill-formed.]]
|
||||
[[`typedef` ['see below] `difference_type;`]
|
||||
[`T::difference_type` if such a type exists; otherwise `std::ptrdiff_t`.]]
|
||||
[[`template<class U> struct rebind_to { typedef` ['see below] `type; };`]
|
||||
[`type` is `T::rebind<U>` if such a type exists; otherwise, `Pointer<V, Args>`
|
||||
if `T` is a class template instantiation of the form `Pointer<T, Args>`,
|
||||
where `Args` is zero or more type arguments; otherwise, the instantiation of
|
||||
`rebind_to` is ill-formed.]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Member functions]
|
||||
|
||||
[variablelist pointer_traits
|
||||
[[`static pointer pointer_to(`['see below] `v);`]
|
||||
[[variablelist
|
||||
[[Remark]
|
||||
[If `element_type` is a void type, the type of `v` is unspecified;
|
||||
otherwise, it is `element_type&`.]]
|
||||
[[Returns]
|
||||
[A pointer to `v` obtained by calling `T::pointer_to(v)`.]]]]]
|
||||
[[`static element_type* to_address(pointer v) noexcept;`]
|
||||
[[variablelist
|
||||
[[Requires]
|
||||
[`v` is not a null pointer.]]
|
||||
[[Returns]
|
||||
[A pointer of type `element_type*` that references the same location
|
||||
as the argument.]]]]]]
|
||||
[[`static pointer pointer_to(`['see below] `v);`]
|
||||
[[variablelist
|
||||
[[Remark]
|
||||
[If `element_type` is a void type, the type of `v` is unspecified; otherwise,
|
||||
it is `element_type&`.]]
|
||||
[[Returns]
|
||||
[A pointer to `v` obtained by calling `T::pointer_to(v)`.]]]]]
|
||||
[[`static element_type* to_address(const pointer& v) noexcept;`]
|
||||
[[variablelist
|
||||
[[Requires] [`v` is not a null pointer.]]
|
||||
[[Returns]
|
||||
[A pointer of type `element_type*` that references the same location
|
||||
as the argument.]]]]]]
|
||||
|
||||
[variablelist pointer_traits<T*>
|
||||
[[`static pointer pointer_to(`['see below] `v) noexcept;`]
|
||||
[[variablelist
|
||||
[[Remark]
|
||||
[If `element_type` is a void type, the type of `v` is unspecified;
|
||||
otherwise, it is `element_type&`.]]
|
||||
[[Returns]
|
||||
[The result of `std::addressof(v)`.]]]]]
|
||||
[[`static element_type* to_address(pointer v) noexcept;`]
|
||||
[[variablelist [[Returns] [The value of `v`.]]]]]]
|
||||
[[`static pointer pointer_to(`['see below] `v) noexcept;`]
|
||||
[[variablelist
|
||||
[[Remark]
|
||||
[If `element_type` is a void type, the type of `v` is unspecified; otherwise,
|
||||
it is `element_type&`.]]
|
||||
[[Returns] [The result of `boost::addressof(v)`.]]]]]
|
||||
[[`static element_type* to_address(pointer v) noexcept;`]
|
||||
[[variablelist [[Returns] [The value of `v`.]]]]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Free functions]
|
||||
|
||||
[variablelist
|
||||
[[`template<class T> typename pointer_traits<T>::element_type*
|
||||
to_address(const T& v) noexcept;`]
|
||||
[[variablelist [[Returns] [`boost::pointer_traits<T>::to_address(v)`.]]]]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <iterator>
|
||||
#include <boost/core/no_exceptions_support.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/current_function.hpp>
|
||||
#include <boost/core/no_exceptions_support.hpp>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <cstring>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ struct pointer_traits;
|
||||
namespace detail {
|
||||
|
||||
template<class U>
|
||||
static typename boost::pointer_traits<U>::element_type*
|
||||
ptr_traits_address(U v) BOOST_NOEXCEPT
|
||||
inline typename boost::pointer_traits<U>::element_type*
|
||||
ptr_traits_address(const U& v) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::pointer_traits<U>::to_address(v);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ struct pointer_traits
|
||||
typedef typename std::pointer_traits<T>::template rebind<U> type;
|
||||
};
|
||||
static typename std::pointer_traits<T>::element_type*
|
||||
to_address(T v) BOOST_NOEXCEPT {
|
||||
to_address(const T& v) BOOST_NOEXCEPT {
|
||||
return detail::ptr_traits_address(v.operator->());
|
||||
}
|
||||
};
|
||||
@@ -211,7 +211,7 @@ struct pointer_traits {
|
||||
pointer_to(typename detail::ptr_traits_value<element_type>::type& v) {
|
||||
return pointer::pointer_to(v);
|
||||
}
|
||||
static element_type* to_address(pointer v) BOOST_NOEXCEPT {
|
||||
static element_type* to_address(const pointer& v) BOOST_NOEXCEPT {
|
||||
return detail::ptr_traits_address(v.operator->());
|
||||
}
|
||||
};
|
||||
@@ -239,6 +239,20 @@ struct pointer_traits<T*> {
|
||||
};
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
inline typename pointer_traits<T>::element_type*
|
||||
to_address(const T& v) BOOST_NOEXCEPT
|
||||
{
|
||||
return pointer_traits<T>::to_address(v);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T*
|
||||
to_address(T* v) BOOST_NOEXCEPT
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -116,6 +116,7 @@ run pointer_traits_element_type_test.cpp ;
|
||||
run pointer_traits_difference_type_test.cpp ;
|
||||
run pointer_traits_rebind_test.cpp ;
|
||||
run pointer_traits_pointer_to_test.cpp ;
|
||||
run to_address_test.cpp ;
|
||||
|
||||
use-project /boost/core/swap : ./swap ;
|
||||
build-project ./swap ;
|
||||
|
||||
@@ -21,6 +21,44 @@ private:
|
||||
T value_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class special {
|
||||
public:
|
||||
special(T* value)
|
||||
: value_(value) { }
|
||||
T* get() const BOOST_NOEXCEPT {
|
||||
return value_;
|
||||
}
|
||||
private:
|
||||
T* value_;
|
||||
};
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
struct pointer_traits<special<T> > {
|
||||
typedef special<T> pointer;
|
||||
typedef T element_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
template<class U>
|
||||
struct rebind_to {
|
||||
typedef special<U> type;
|
||||
};
|
||||
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
template<class U>
|
||||
using rebind = typename rebind_to<U>::type;
|
||||
#endif
|
||||
template<class U>
|
||||
static pointer pointer_to(U& v) BOOST_NOEXCEPT {
|
||||
return pointer(&v);
|
||||
}
|
||||
static element_type* to_address(const pointer& v) BOOST_NOEXCEPT {
|
||||
return v.get();
|
||||
}
|
||||
};
|
||||
|
||||
} /* boost */
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 0;
|
||||
@@ -59,5 +97,35 @@ int main()
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::pointer_traits<type>::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef special<int> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::pointer_traits<type>::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef special<void> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::pointer_traits<type>::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef special<const int> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::pointer_traits<type>::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<special<int> > type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::pointer_traits<type>::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<special<void> > type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::pointer_traits<type>::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<special<const int> > type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::pointer_traits<type>::to_address(p) == &i);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
131
test/to_address_test.cpp
Normal file
131
test/to_address_test.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
Copyright 2017 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/pointer_traits.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
template<class T>
|
||||
class pointer {
|
||||
public:
|
||||
typedef typename boost::pointer_traits<T>::element_type element_type;
|
||||
pointer(T value)
|
||||
: value_(value) { }
|
||||
T operator->() const BOOST_NOEXCEPT {
|
||||
return value_;
|
||||
}
|
||||
private:
|
||||
T value_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class special {
|
||||
public:
|
||||
special(T* value)
|
||||
: value_(value) { }
|
||||
T* get() const BOOST_NOEXCEPT {
|
||||
return value_;
|
||||
}
|
||||
private:
|
||||
T* value_;
|
||||
};
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
struct pointer_traits<special<T> > {
|
||||
typedef special<T> pointer;
|
||||
typedef T element_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
template<class U>
|
||||
struct rebind_to {
|
||||
typedef special<U> type;
|
||||
};
|
||||
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
template<class U>
|
||||
using rebind = typename rebind_to<U>::type;
|
||||
#endif
|
||||
template<class U>
|
||||
static pointer pointer_to(U& v) BOOST_NOEXCEPT {
|
||||
return pointer(&v);
|
||||
}
|
||||
static element_type* to_address(const pointer& v) BOOST_NOEXCEPT {
|
||||
return v.get();
|
||||
}
|
||||
};
|
||||
|
||||
} /* boost */
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 0;
|
||||
{
|
||||
typedef int* type;
|
||||
type p = &i;
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<int*> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<pointer<int*> > type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef void* type;
|
||||
type p = &i;
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<void*> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef const int* type;
|
||||
type p = &i;
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<const int*> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef special<int> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef special<void> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef special<const int> type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<special<int> > type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<special<void> > type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
{
|
||||
typedef pointer<special<const int> > type;
|
||||
type p(&i);
|
||||
BOOST_TEST(boost::to_address(p) == &i);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user