My Project
reference_wrapper.hpp
Go to the documentation of this file.
1 
28 #ifndef BSL_REFERENCE_WRAPPER_HPP
29 #define BSL_REFERENCE_WRAPPER_HPP
30 
31 #include "addressof.hpp"
32 #include "forward.hpp"
33 #include "invoke_result.hpp"
34 
35 namespace bsl
36 {
52  template<typename T>
53  class reference_wrapper final
54  {
56  T *m_ptr;
57 
58  public:
60  using type = T;
61 
71  explicit constexpr reference_wrapper(T &val) noexcept : m_ptr{addressof(val)}
72  {}
73 
83  [[nodiscard]] constexpr T &
84  get() const noexcept
85  {
86  return *m_ptr;
87  }
88 
103  template<typename... ARGS>
104  [[nodiscard]] constexpr invoke_result_t<T &, ARGS...>
105  operator()(ARGS &&... a) const
106  {
107  return invoke(this->get(), bsl::forward<ARGS>(a)...);
108  }
109  };
110 }
111 
112 #endif
constexpr auto invoke(FUNC &&f, TN &&... tn) noexcept(//-- noexcept(details::invoke_impl< FUNC, TN... >::call(//-- bsl::forward< FUNC >(f),//-- bsl::forward< TN >(tn)...))) -> decltype(details::invoke_impl< FUNC, TN... >::call(bsl::forward< FUNC >(f), bsl::forward< TN >(tn)...))
Invokes the callable object "f" with arguments "tn".
Definition: invoke.hpp:61
constexpr reference_wrapper(T &val) noexcept
Used to initialize a reference_wrapper by getting an address to the provided "val" and storing the ad...
Definition: reference_wrapper.hpp:71
constexpr T * addressof(T &val) noexcept
Obtains the actual address of the object or function arg, even in presence of overloaded operator& (i...
Definition: addressof.hpp:47
constexpr T & get() const noexcept
Returns a reference to the thing that is wrapped. This is done by taking the stored address and retur...
Definition: reference_wrapper.hpp:84
T type
alias for: T
Definition: reference_wrapper.hpp:60
typename invoke_result< FUNC, TN... >::type invoke_result_t
a helper that reduces the verbosity of bsl::invoke_result
Definition: invoke_result.hpp:54
constexpr invoke_result_t< T &, ARGS... > operator()(ARGS &&... a) const
Invokes the reference_wrapper as if it were a function.
Definition: reference_wrapper.hpp:105