Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A type trait to indicate that a type is a proxy reference type #29

Open
cor3ntin opened this issue May 16, 2020 · 4 comments
Open

A type trait to indicate that a type is a proxy reference type #29

cor3ntin opened this issue May 16, 2020 · 4 comments

Comments

@cor3ntin
Copy link
Owner

To fix tuple / get / pair for reference_wrapper and vectorreference

@ThePhD
Copy link

ThePhD commented May 16, 2020

From the stream, a suggested unwrap_unreference can be further expanded to detect a wrapper by detecting either std::reference_wrapper or response to the well-formedness of an ADL hook call, allowing different kind of reference wrappers to be given consistent behavior without specializing std::reference_wrapper.

#include <utility>

namespace std0 {

	namespace detail {
		template <typename T>
		using detect_unwrap_reference = decltype(unwrap_reference(std::declval<T>()));
	}

	struct unwrap_reference_niebloid {
		template <typename T>
		constexpr decltype(auto) operator()(T&& value) const noexcept {
			// detect general unwrap ADL extension point
			if constexpr (is_detected_v<detail::detect_unwrap_reference, T>) {
				return unwrap_reference(std::forward<T>(value));
			}
			// Dr. WEB paper on is_specialization_of
			else if constexpr (is_specialization_of_v<T, std::reference_wrapper>) {
				return value.get();
			}
			else {
				return std::forward<T>(value);
			}
		}
	} inline constexpr unwrap_reference{};

	template <typename T>
	using unwrap_reference_t = decltype(std0::unwrap_reference(std::declval<T>()));

}

@cor3ntin
Copy link
Owner Author

Hey @ThePhD - i missed that comment, it seems worth exploring!

@cor3ntin
Copy link
Owner Author

@cor3ntin
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants