blob: d7f1b6f708d2341253fa386bb42f3b217bcb9818 [file] [log] [blame]
Martin Stjernholmc15e7e42020-12-02 22:50:53 +00001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_
18#define ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_
19
20namespace art {
21
22// Use to suppress type deduction for a function argument.
23// See std::identity<> for more background:
24// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1856.html#20.2.2 - move/forward helpers
25//
26// e.g. "template <typename X> void bar(identity<X>::type foo);
27// bar(5); // compilation error
28// bar<int>(5); // ok
29// or "template <typename T> void foo(T* x, typename Identity<T*>::type y);
30// Base b;
31// Derived d;
32// foo(&b, &d); // Use implicit Derived* -> Base* conversion.
33// If T was deduced from both &b and &d, there would be a mismatch, i.e. deduction failure.
34template <typename T>
35struct Identity {
36 using type = T;
37};
38
39} // namespace art
40
41#endif // ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_