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

It would be nice to have an identity function object #17

Open
mclow opened this issue Oct 1, 2011 · 1 comment
Open

It would be nice to have an identity function object #17

mclow opened this issue Oct 1, 2011 · 1 comment

Comments

@mclow
Copy link
Owner

mclow commented Oct 1, 2011

From the -users ML:

I use the following function on a regular basis:

template < class P_T > P_T const &same (P_T const &p) { return p; }

I use it for two purposes:

  1. to pass an identity function to an API that expects a unary function,
  2. to help the compiler identify the right chain of type conversions.

The standard uses static_cast for (2), which could be used but it disables
some compile-time verification so I would rather not use static_cast when
not absolutely necessary.

@dabrahams
Copy link

Whether this is really an algorithm, and how it should be written in the presence of rvalue references, are both open questions.

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

No branches or pull requests

2 participants