mpc
Haskell-like feature supports in C++
forward_like.hpp
Go to the documentation of this file.
1
2#pragma once
4
5namespace mpc {
6 template <class T, class U>
7 using __override_ref_t =
8 std::conditional_t<std::is_rvalue_reference_v<T>, std::remove_reference_t<U>&&, U&>;
9
10 template <class T, class U>
11 using __copy_const_t =
12 std::conditional_t<std::is_const_v<std::remove_reference_t<T>>, U const, U>;
13
14 template <class T, class U>
15 using forward_like_t = __override_ref_t<T&&, __copy_const_t<T, std::remove_reference_t<U>>>;
16
17 template <typename T>
18 [[nodiscard]] constexpr auto forward_like(auto&& x) noexcept -> forward_like_t<T, decltype(x)> {
19 return static_cast<forward_like_t<T, decltype(x)>>(x);
20 }
21} // namespace mpc