ericniebler / meta

A tiny metaprogramming library
Boost Software License 1.0
302 stars 47 forks source link

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

Open viboes opened 8 years ago

viboes commented 8 years ago

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?

ericniebler commented 8 years ago

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

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

CaseyCarter commented 8 years ago

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 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?

ericniebler commented 8 years ago

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.

viboes commented 8 years ago

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.

ericniebler commented 8 years ago

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

ericniebler commented 8 years ago

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.

gabyx commented 8 years ago

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

viboes commented 8 years ago

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.