functional.hpp (2332B)
1 /* 2 Copyright 2017 Adobe 3 Distributed under the Boost Software License, Version 1.0. 4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 7 /**************************************************************************************************/ 8 9 #ifndef STLAB_FUNCTIONAL_HPP 10 #define STLAB_FUNCTIONAL_HPP 11 12 /**************************************************************************************************/ 13 14 #include <functional> 15 #include <type_traits> 16 17 /**************************************************************************************************/ 18 19 namespace stlab { 20 21 /**************************************************************************************************/ 22 23 inline namespace v1 { 24 /**************************************************************************************************/ 25 26 template <class T> 27 struct unwrap_reference { 28 using type = T; 29 }; 30 31 template <class T> 32 struct unwrap_reference<std::reference_wrapper<T>> { 33 using type = T; 34 }; 35 36 template <class T> 37 using unwrap_reference_t = typename unwrap_reference<T>::type; 38 39 /**************************************************************************************************/ 40 41 template <class T> 42 struct is_reference_wrapper : std::false_type {}; 43 template <class T> 44 struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {}; 45 46 template <class T> 47 constexpr bool is_reference_wrapper_v = is_reference_wrapper<T>::value; 48 49 /**************************************************************************************************/ 50 51 template <typename T> 52 T& unwrap(T& val) { 53 return val; 54 } 55 56 template <typename T> 57 const T& unwrap(const T& val) { 58 return val; 59 } 60 61 template <typename T> 62 T& unwrap(std::reference_wrapper<T>& val) { 63 return val.get(); 64 } 65 66 template <typename T> 67 const T& unwrap(const std::reference_wrapper<T>& val) { 68 return val.get(); 69 } 70 71 /**************************************************************************************************/ 72 73 } // namespace v1 74 75 /**************************************************************************************************/ 76 77 } // namespace stlab 78 79 /**************************************************************************************************/ 80 81 #endif 82 83 /**************************************************************************************************/