-
Notifications
You must be signed in to change notification settings - Fork 22
Fix alias sfinae #1058
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
Closed
Closed
Fix alias sfinae #1058
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
= Reference | ||
:mrdocs: | ||
|
||
[#index] | ||
== Global namespace | ||
|
||
=== Types | ||
|
||
[cols=1] | ||
|=== | ||
| Name | ||
| link:#enable_if_t[`enable_if_t`] | ||
| link:#if_enable_t[`if_enable_t`] | ||
|=== | ||
|
||
=== Functions | ||
|
||
[cols=1] | ||
|=== | ||
| Name | ||
| link:#f1[`f1`] | ||
| link:#f2[`f2`] | ||
|=== | ||
|
||
[#enable_if_t] | ||
== enable_if_t | ||
|
||
=== Synopsis | ||
|
||
Declared in `<alias.cpp>` | ||
|
||
[source,cpp,subs="verbatim,replacements,macros,-callouts"] | ||
---- | ||
template< | ||
bool C, | ||
typename T> | ||
using enable_if_t = T; | ||
---- | ||
|
||
[#if_enable_t] | ||
== if_enable_t | ||
|
||
=== Synopsis | ||
|
||
Declared in `<alias.cpp>` | ||
|
||
[source,cpp,subs="verbatim,replacements,macros,-callouts"] | ||
---- | ||
template< | ||
typename T, | ||
bool C> | ||
using if_enable_t = T; | ||
---- | ||
|
||
[#f1] | ||
== f1 | ||
|
||
=== Synopsis | ||
|
||
Declared in `<alias.cpp>` | ||
|
||
[source,cpp,subs="verbatim,replacements,macros,-callouts"] | ||
---- | ||
template<typename T> | ||
T | ||
f1() | ||
requires std::is_class_v<T>; | ||
---- | ||
|
||
[#f2] | ||
== f2 | ||
|
||
=== Synopsis | ||
|
||
Declared in `<alias.cpp>` | ||
|
||
[source,cpp,subs="verbatim,replacements,macros,-callouts"] | ||
---- | ||
template<typename T> | ||
T | ||
f2() | ||
requires std::is_class_v<T>; | ||
---- | ||
|
||
|
||
[.small]#Created with https://www.mrdocs.com[MrDocs]# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <type_traits> | ||
|
||
// just like std::enable_if_t | ||
template <bool C, typename T> | ||
using enable_if_t = typename std::enable_if<C, T>::type; | ||
|
||
template <typename T> | ||
enable_if_t<std::is_class_v<T>, T> f1(); | ||
|
||
// reversed param order | ||
template <typename T, bool C> | ||
using if_enable_t = typename std::enable_if<C, T>::type; | ||
|
||
template <typename T> | ||
if_enable_t<T, std::is_class_v<T>> f2(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<html lang="en"> | ||
<head> | ||
<title>Reference</title> | ||
</head> | ||
<body> | ||
<div> | ||
<h1>Reference</h1> | ||
<div> | ||
<div> | ||
<h2 id="index"><a href="#index"></a></h2> | ||
</div> | ||
<h2>Types</h2> | ||
<table style="table-layout: fixed; width: 100%;"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><a href="#enable_if_t"><code>enable_if_t</code></a> </td></tr><tr> | ||
<td><a href="#if_enable_t"><code>if_enable_t</code></a> </td></tr> | ||
</tbody> | ||
</table> | ||
|
||
<h2>Functions</h2> | ||
<table style="table-layout: fixed; width: 100%;"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><a href="#f1"><code>f1</code></a> </td></tr><tr> | ||
<td><a href="#f2"><code>f2</code></a> </td></tr> | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
<div> | ||
<div> | ||
<h2 id="enable_if_t"><a href="#enable_if_t">enable_if_t</a></h2> | ||
</div> | ||
<div> | ||
<h3>Synopsis</h3> | ||
<div> | ||
Declared in <code><alias.cpp></code></div> | ||
<pre> | ||
<code class="source-code cpp">template< | ||
bool C, | ||
typename T> | ||
using enable_if_t = T; | ||
|
||
</code> | ||
</pre> | ||
</div> | ||
</div> | ||
<div> | ||
<div> | ||
<h2 id="if_enable_t"><a href="#if_enable_t">if_enable_t</a></h2> | ||
</div> | ||
<div> | ||
<h3>Synopsis</h3> | ||
<div> | ||
Declared in <code><alias.cpp></code></div> | ||
<pre> | ||
<code class="source-code cpp">template< | ||
typename T, | ||
bool C> | ||
using if_enable_t = T; | ||
|
||
</code> | ||
</pre> | ||
</div> | ||
</div> | ||
<div> | ||
<div> | ||
<h2 id="f1"><a href="#f1">f1</a></h2> | ||
</div> | ||
<div> | ||
<h3>Synopsis</h3> | ||
<div> | ||
Declared in <code><alias.cpp></code></div> | ||
<pre> | ||
<code class="source-code cpp">template<typename T> | ||
T | ||
f1() | ||
requires std::is_class_v<T>; | ||
|
||
</code> | ||
</pre> | ||
</div> | ||
</div> | ||
<div> | ||
<div> | ||
<h2 id="f2"><a href="#f2">f2</a></h2> | ||
</div> | ||
<div> | ||
<h3>Synopsis</h3> | ||
<div> | ||
Declared in <code><alias.cpp></code></div> | ||
<pre> | ||
<code class="source-code cpp">template<typename T> | ||
T | ||
f2() | ||
requires std::is_class_v<T>; | ||
|
||
</code> | ||
</pre> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
<div> | ||
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4> | ||
</div> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc"> | ||
<namespace id="//////////////////////////8="> | ||
<template> | ||
<tparam name="C" class="non-type" type="bool"/> | ||
<tparam name="T" class="type"/> | ||
<namespace-alias name="enable_if_t" id="G6KvcosPT2J4Mp72/Jj/t+hpu7w="> | ||
<file short-path="alias.cpp" source-path="alias.cpp" line="4"/> | ||
<type name="T"/> | ||
</namespace-alias> | ||
</template> | ||
<template> | ||
<tparam name="T" class="type"/> | ||
<tparam name="C" class="non-type" type="bool"/> | ||
<namespace-alias name="if_enable_t" id="3mL2o5cGgdygMfQf6RJVMv4YrLg="> | ||
<file short-path="alias.cpp" source-path="alias.cpp" line="11"/> | ||
<type name="T"/> | ||
</namespace-alias> | ||
</template> | ||
<template> | ||
<tparam name="T" class="type"/> | ||
<function name="f1" requires="std::is_class_v<T>" id="wxSwXFUt9arsW/YBeWhVf1gINhw="> | ||
<file short-path="alias.cpp" source-path="alias.cpp" line="7"/> | ||
<return> | ||
<type name="T"/> | ||
</return> | ||
</function> | ||
</template> | ||
<template> | ||
<tparam name="T" class="type"/> | ||
<function name="f2" requires="std::is_class_v<T>" id="koj7SBKjX4SV47aOs0homZpcPWQ="> | ||
<file short-path="alias.cpp" source-path="alias.cpp" line="14"/> | ||
<return> | ||
<type name="T"/> | ||
</return> | ||
</function> | ||
</template> | ||
</namespace> | ||
</mrdocs> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't handle the other template argument kinds. I think you want
isSameTemplateArgument
.But comparing template arguments like that only makes sense if the parameters are equivalent, as otherwise they'll have different conversions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only attempts to handle the boolean case. Given
the goal here is to match the
C
that is an argument tostd::enable_if
to theC
that is a parameter ofenable_if_t
.The pre-existing case attempts to do something similar for
T
. Nothing else (no heroics).Would
isSameTemplateArgument
be a better choice here? Or is there a simpler alternative?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isSameTemplateArgument
does what this code does, and more, since it handles the other template argument kinds as well, such as template template arguments, the other kinds of converted constant template arguments, packs, and such.What I mean is, if we are comparing template arguments to equivalent template parameters, then it makes sense to compare them like this.
If they are otherwise not equivalent, for example you are comparing a template argument for a constant template parameter of type
bool
, to another one of typeint
, then this won't work as expected.