Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 17 | #ifndef ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_ |
| 18 | #define ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_ |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 19 | |
| 20 | namespace 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. |
| 34 | template <typename T> |
| 35 | struct Identity { |
| 36 | using type = T; |
| 37 | }; |
| 38 | |
| 39 | } // namespace art |
| 40 | |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 41 | #endif // ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_ |