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

tagged<user-defined type> does not work #364

Closed
CaseyCarter opened this issue Mar 4, 2017 · 3 comments
Closed

tagged<user-defined type> does not work #364

CaseyCarter opened this issue Mar 4, 2017 · 3 comments

Comments

@CaseyCarter
Copy link
Collaborator

CaseyCarter commented Mar 4, 2017

Since tagged getters use qualified std::get to access the fields of Base and users are forbidden to overload std::get. A possible solution is to use ADL to find get function templates in the user's namespace(s) as implemented in range-v3's tagged.

Proposed Resolution

This issue is resolved by the PR for #363.

@CaseyCarter CaseyCarter changed the title tagged must find get by ADL tagged<user-defined type> does not work Mar 5, 2017
@CaseyCarter
Copy link
Collaborator Author

CaseyCarter commented Mar 5, 2017

SUPERSEDED

(This PR also resolves #418.)

Modify [taggedtup.tagged]/4 as follows:

 A tagged getter class with DerivedCharacteristic D, ElementIndex N, and ElementName "name" shall
 provide the following interface:

   struct __TAGGED_GETTER {
-    constexpr decltype(auto) name() & { return get<N>(static_cast<D&>(*this)); }
+    constexpr decltype(auto) name() &
+      noexcept(noexcept(ADL::GET<N>(static_cast<D&>(*this))))
+    {
+      return ADL::GET<N>(static_cast<D&>(*this));
+    }
-    constexpr decltype(auto) name() const & { return get<N>(static_cast<const D&>(*this)); }
+    constexpr decltype(auto) name() const &
+      noexcept(noexcept(ADL::GET<N>(static_cast<const D&>(*this))))
+    {
+      return ADL::GET<N>(static_cast<const D&>(*this));
+    }
-    constexpr decltype(auto) name() && { return get<N>(static_cast<D&&>(*this)); }
+    constexpr decltype(auto) name() &&
+      noexcept(noexcept(ADL::GET<N>(static_cast<D&&>(*this))))
+    {
+      return ADL::GET<N>(static_cast<D&&>(*this));
+    }
+    constexpr decltype(auto) name() const &&
+      noexcept(noexcept(ADL::GET<N>(static_cast<const D&&>(*this))))
+    {
+      return ADL::GET<N>(static_cast<const D&&>(*this));
+    }
   };

+Where ADL::GET refers to the exposition-only function template defined in an 
+exposition-only sub-namespace:
+
+  namespace ADL {
+    using std::get;
+
+    template<size_t I, class T>
+    constexpr decltype(auto) GET(T&& t)
+      noexcept(noexcept(get<N>(std::forward<T>(t))))
+   {
+      return get<N>(std::forward<T>(t));
+   }
+ }

Also strike the redundant and now incorrect example [alg.tagspec]/3:

-3 [Example: tag::in is a type such that TAGGET(D, tag::in, N) names a type [...]

@ericniebler
Copy link
Owner

Looks good.

CaseyCarter added a commit to CaseyCarter/cmcstl2 that referenced this issue Jul 1, 2017
CaseyCarter added a commit to CaseyCarter/cmcstl2 that referenced this issue Jul 1, 2017
CaseyCarter added a commit to CaseyCarter/cmcstl2 that referenced this issue Jul 2, 2017
* Implement ericniebler/stl2#299
* Implement ericniebler/stl2#363
* Implement ericniebler/stl2#364
* Implement ericniebler/stl2#418
* Remove tuple_find that was dropped from variant ages ago
* Implement extension 'structible object concepts
* tighten up constrains in the tagged impl
@ericniebler ericniebler added P4 and removed P3 labels Jul 12, 2017
@CaseyCarter CaseyCarter added TS and removed PDTS labels Jul 16, 2017
@CaseyCarter CaseyCarter added NAD and removed new labels Jun 15, 2018
@CaseyCarter
Copy link
Collaborator Author

LEWG has killed tagged for C++20 - closing this as NAD.

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

No branches or pull requests

2 participants