Silicium
ptr_adaptor.hpp
Go to the documentation of this file.
1 #ifndef SILICIUM_PTR_ADAPTOR_HPP
2 #define SILICIUM_PTR_ADAPTOR_HPP
3 
4 #include <silicium/config.hpp>
5 #include <boost/version.hpp>
6 #if BOOST_VERSION >= 105500
7 # include <boost/utility/explicit_operator_bool.hpp>
8 #endif
9 
10 namespace Si
11 {
12  template <class Pointee>
13  struct ptr_adaptor
14  {
15  template <class ...Args>
16  explicit ptr_adaptor(Args &&...args)
17  : m_value(std::forward<Args>(args)...)
18  {
19  }
20 
21  Pointee &operator *() BOOST_NOEXCEPT
22  {
23  return m_value;
24  }
25 
26  Pointee *operator ->() BOOST_NOEXCEPT
27  {
28  return &m_value;
29  }
30 
31  bool operator !() const BOOST_NOEXCEPT
32  {
33  return false;
34  }
35 
36 #ifdef BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT
37  //the noexcept version was added in 1.56 http://www.boost.org/doc/libs/1_57_0/libs/core/doc/html/core/explicit_operator_bool.html
38  BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
39 #elif defined(BOOST_EXPLICIT_OPERATOR_BOOL)
40  BOOST_EXPLICIT_OPERATOR_BOOL()
41 #else
42  operator bool() const BOOST_NOEXCEPT
43  {
44  return true;
45  }
46 #endif
47 
48 #if !SILICIUM_COMPILER_GENERATES_MOVES
50  : m_value(std::move(other.m_value))
51  {
52  }
53 
55  {
56  m_value = std::move(other.m_value);
57  return *this;
58  }
59 #endif
60 
61  private:
62 
63  Pointee m_value;
64  };
65 
66  template <class Pointee>
67  auto make_ptr_adaptor(Pointee &&value)
68 #if !SILICIUM_COMPILER_HAS_AUTO_RETURN_TYPE
69  ->ptr_adaptor<typename std::decay<Pointee>::type>
70 #endif
71  {
72  return ptr_adaptor<typename std::decay<Pointee>::type>(std::forward<Pointee>(value));
73  }
74 }
75 
76 #endif
std::remove_reference< T >::type && move(T &&ref)
Definition: move.hpp:10
ptr_adaptor(Args &&...args)
Definition: ptr_adaptor.hpp:16
ptr_adaptor(ptr_adaptor &&other)
Definition: ptr_adaptor.hpp:49
Definition: absolute_path.hpp:352
Definition: absolute_path.hpp:19
Pointee * operator->() BOOST_NOEXCEPT
Definition: ptr_adaptor.hpp:26
auto make_ptr_adaptor(Pointee &&value) -> ptr_adaptor< typename std::decay< Pointee >::type >
Definition: ptr_adaptor.hpp:67
Pointee & operator*() BOOST_NOEXCEPT
Definition: ptr_adaptor.hpp:21
bool operator!() const BOOST_NOEXCEPT
Definition: ptr_adaptor.hpp:31
ptr_adaptor & operator=(ptr_adaptor &&other)
Definition: ptr_adaptor.hpp:54
Definition: ptr_adaptor.hpp:13