• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright 2017 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4 
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #include <boost/core/pointer_traits.hpp>
9 #include <boost/core/lightweight_test.hpp>
10 
11 template<class T>
12 class pointer {
13 public:
14     typedef typename boost::pointer_traits<T>::element_type element_type;
pointer(T value)15     pointer(T value)
16         : value_(value) { }
get() const17     T get() const BOOST_NOEXCEPT {
18         return value_;
19     }
pointer_to(element_type & value)20     static pointer<T> pointer_to(element_type& value) {
21         return pointer<T>(&value);
22     }
23 private:
24     T value_;
25 };
26 
27 template<class T>
28 inline bool
operator ==(const pointer<T> & lhs,const pointer<T> & rhs)29 operator==(const pointer<T>& lhs, const pointer<T>& rhs) BOOST_NOEXCEPT
30 {
31     return lhs.get() == rhs.get();
32 }
33 
main()34 int main()
35 {
36     int i = 0;
37     {
38         typedef int* type;
39         type p = &i;
40         BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p);
41     }
42     {
43         typedef pointer<int*> type;
44         type p(&i);
45         BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p);
46     }
47     {
48         typedef pointer<pointer<int*> > type;
49         type p(&i);
50         BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p);
51     }
52     {
53         typedef const int* type;
54         type p = &i;
55         BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p);
56     }
57     {
58         typedef pointer<const int*> type;
59         type p(&i);
60         BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p);
61     }
62     return boost::report_errors();
63 }
64