meta icon indicating copy to clipboard operation
meta copied to clipboard

Mixing always/const_ and meta::id. Missing meta::identity Callable.

Open viboes opened this issue 8 years ago • 8 comments

id<T>: A trait that always returns its argument T. Also, a Callable that always returns T.

Other libraries use always<T> or const_<T> for a Callable that always returns T.

Naming id<T> a Callable that doesn't behaves as the identify Callable is disturbing. I believe that id<T> should only be a trait and that we could add an meta::identity Callable

struct identity {
  template < class T>
  using invoke = T;
};

it can also be defined as

using identity = quote_trait<id>;

What do you think?

viboes avatar May 21 '16 16:05 viboes

Naming id<T> a Callable that doesn't behaves as the identify Callable is disturbing.

I'm not sure understand. What exactly is the problem?

ericniebler avatar May 21 '16 18:05 ericniebler

It's a misnomer to say that id<T> is both a trait and a callable; the class template id is a trait, and its specializations are callables. (Yes, Trait is a concept for class templates, not for types.)

Naming id<T> a Callable that doesn't behaves as the identify Callable is disturbing.

Why would someone expect id<double> or id<std::string> to be an identity callable?

CaseyCarter avatar May 21 '16 20:05 CaseyCarter

It's a misnomer to say that id<T> is both a trait and a callable; the class template id is a trait, and its specializations are callables. (Yes, Trait is a concept for class templates, not for types.)

That is not how meta defines the Trait concept.

ericniebler avatar May 21 '16 21:05 ericniebler

For me this is a naming issue. You can of course disagree.

I believe that the identity callable is missing as it is one of the basic Callable operations.

While i was looking for this Callable, I found id but its definition as a Callable is not what I was looking for.

What I'm saying is that if invoke<id<T>, Us...>> is T, it behaves like the constant function T. And that other libraries use for this Callable other names like always or constant.

I pretend that the following is more readable and coveys better the intent

invoke<always<T>, U>>

than

invoke<id<T>, U>>

But maybe you think differently.

viboes avatar May 22 '16 09:05 viboes

What, in your opinion, should invoke<id<T>, U> be?

ericniebler avatar May 23 '16 16:05 ericniebler

It's a misnomer to say that id is both a trait and a callable; the class template id is a trait, and its specializations are callables. (Yes, Trait is a concept for class templates, not for types.)

That is not how meta defines the Trait concept.

... which in conflict with how the standard uses the term trait. I should revisit this.

ericniebler avatar May 23 '16 16:05 ericniebler

As a sidenote: I expect: invoke<id<double>, U> to turn into double<U> which does not work of course. Is this correct?

gabyx avatar May 23 '16 16:05 gabyx

What, in your opinion, should invoke<id<T>, U> be?

Compilation fail.

I would expect invoke<always<T>, U> or invoke<constant<T>, U> to be T.

viboes avatar May 23 '16 19:05 viboes