source: mainline/uspace/lib/cpp/include/__bits/functional/reference_wrapper.hpp@ e49d0ac

Last change on this file since e49d0ac was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef LIBCPP_BITS_FUNCTIONAL_REFERENCE_WRAPPER
8#define LIBCPP_BITS_FUNCTIONAL_REFERENCE_WRAPPER
9
10#include <__bits/functional/conditional_function_typedefs.hpp>
11#include <__bits/functional/invoke.hpp>
12#include <type_traits>
13
14namespace std
15{
16 /**
17 * 20.9.4, reference_wrapper:
18 */
19
20 template<class T>
21 class reference_wrapper
22 : public aux::conditional_function_typedefs<remove_cv_t<remove_reference_t<T>>>
23 {
24 public:
25 using type = T;
26
27 reference_wrapper(type& val) noexcept
28 : data_{&val}
29 { /* DUMMY BODY */ }
30
31 reference_wrapper(type&&) = delete;
32
33 reference_wrapper(const reference_wrapper& other) noexcept
34 : data_{other.data_}
35 { /* DUMMY BODY */ }
36
37 reference_wrapper& operator=(const reference_wrapper& other) noexcept
38 {
39 data_ = other.data_;
40
41 return *this;
42 }
43
44 operator type&() const noexcept
45 {
46 return *data_;
47 }
48
49 type& get() const noexcept
50 {
51 return *data_;
52 }
53
54 template<class... Args>
55 decltype(auto) operator()(Args&&... args) const
56 {
57 return aux::INVOKE(*data_, std::forward<Args>(args)...);
58 }
59
60 private:
61 type* data_;
62 };
63
64 template<class T>
65 reference_wrapper<T> ref(T& t) noexcept
66 {
67 return reference_wrapper<T>{t};
68 }
69
70 template<class T>
71 reference_wrapper<const T> cref(const T& t) noexcept
72 {
73 return reference_wrapper<const T>{t};
74 }
75
76 template<class T>
77 void ref(const T&&) = delete;
78
79 template<class T>
80 void cref(const T&&) = delete;
81
82 template<class T>
83 reference_wrapper<T> ref(reference_wrapper<T> t) noexcept
84 {
85 return ref(t.get());
86 }
87
88 template<class T>
89 reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept
90 {
91 return cref(t.get());
92 }
93}
94
95#endif
Note: See TracBrowser for help on using the repository browser.