template <typename T>
struct identity { using type = T; }
template <typename T>
using identity_t = typename identity<T>::type;
template <typename T> void p0(vector<T>& v, T value);
template <typename T> void p1(vector<T>& v, identity_t<T> value);
void foo() {
std::vector<string> strings;
p0(strings, "abc"); //Error cannot deduce type T (string vs const char[4])
p1(strings, "abc"); //Ok, T is string
}
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
Yep. Its author is a slacker and would appreciate someone else taking over the update. LEWG's comments are at http://wiki.edg.com/twiki/bin/view/Wg21chicago2013/N3766.
On Thu, Feb 19, 2015 at 9:41 AM, Nevin Liber <ne...@eviloverlord.com> wrote:
But since then N3766 was received favorably in LEWG. I believe the current status is that we are waiting on an updated paper.
Yep. Its author is a slacker and would appreciate someone else taking over the update. LEWG's comments are at http://wiki.edg.com/twiki/bin/view/Wg21chicago2013/N3766.
On Thu, Feb 19, 2015 at 10:15 PM, Arthur O'Dwyer <arthur....@gmail.com> wrote:wiki.edg.com requires a login and password in order to view pages, and when I try to create a login via http://wiki.edg.com/twiki/bin/view/TWiki/TWikiRegistration it sends me to a "403 Forbidden" page at http://wiki.edg.com/twiki/bin/register/Main/WebHome So I can't see the LEWG comments. But if I could see them, I'd be happy to update the proposal accordingly.Write a new one, bring it to Lenexa meeting, and you will get the access.(My personal view so far is that identity<T>::operator() shouldn't exist; just identity<T>::type and its alias identity_t<T>. But I wonder what LEWG's view was.)LEWG spent some time on discussing how to make the operator() work in Chicago, including constraining the template and choosing the header file choice, but no poll was taken to show which approach is favored. If you want to champion one approach, please provide the reason in your paper. Also, if you want to use the name `identity`, you need a survey on existing implementations to see whether the old SGI `identity` is still in use, etc.
I propose
* to use id instead of identity to avoid the backward compatibility constraint and
* to remove the operator() from id<T> as it is not really needed, id<>{} is the identity function object.
Would the following be less controversial
template <class T=void>
struct id {
using type = T;
};
template <class T>
using id_t = typename id<T>::type;
template <>
struct id<void> {
using type = void;
template <class U>
U&& operator(U&& u) { return forward<U>(u); }
};
The drawback is that to name the identity function we need id<>{}
An alternative is to place the id meta function on a meta namespace (As Eric's meta library [1] does) and define an id lambda function (constexpr function object) as Lousi's Hana library does [1]
namespace meta {
template <class T>
struct id {
using type = T;
};
template <class T>
using id_t = typename id<T>::type;
}
/* constexpr*/ auto id = [](auto&& x) { return forward<decltype(x)>(x); };
"id" also commonly means identifier. The name could be misleading.
Another possibility could be std::same<T> or maybe std::identical<T>
On 2015-02-22 04:42, Vicente J. Botet Escriba wrote:
> I propose
> * to use id instead of identity to avoid the backward compatibility
> constraint
"Id" is *massively* used colloquially to mean "identification"... try
asking yourself how often you *don't* hear people substitute "id" when
they mean "identification" :-). In programming, it tends to mean instead
"identifier", although that's essentially the same idea.
Even though we *are* talking the same root as "identity", "identity" is
a specific mathematical term (and yes, I agree most programmers are
probably familiar with the mathematical meaning) that does not really
match up with what people think of as "identifiers".
That said, even "identity" is a bit broad of a concept, as there are
many possible "identities" (additive identity, multiplicative identity,
etc.).
It's (even) more typing, but what about type_identity?
Or maybe a shorthand
std::ident<T>
--