Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: util/misc/implicit_cast.h

Issue 1335353002: Replace implicit_cast usage with static_cast. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: implicitcast: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « snapshot/mac/mach_o_image_reader_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
scottmg 2015/09/11 23:57:34 Needs to be added to util/util.gyp.
danakj 2015/09/12 00:10:58 Done.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 namespace crashpad {
scottmg 2015/09/11 23:57:34 This file needs header guards.
danakj 2015/09/12 00:10:58 Oops. Done.
16
17 // Use implicit_cast as a safe version of static_cast or const_cast
18 // for upcasting in the type hierarchy (i.e. casting a pointer to Foo
19 // to a pointer to SuperclassOfFoo or casting a pointer to Foo to
20 // a const pointer to Foo).
21 // When you use implicit_cast, the compiler checks that the cast is safe.
22 // Such explicit implicit_casts are necessary in surprisingly many
23 // situations where C++ demands an exact type match instead of an
24 // argument type convertible to a target type.
25 //
26 // The From type can be inferred, so the preferred syntax for using
27 // implicit_cast is the same as for static_cast etc.:
28 //
29 // implicit_cast<ToType>(expr)
30 //
31 // implicit_cast would have been part of the C++ standard library,
32 // but the proposal was submitted too late. It will probably make
33 // its way into the language in the future.
34 template<typename To, typename From>
35 inline To implicit_cast(From const &f) {
36 return f;
37 }
38
39 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/mac/mach_o_image_reader_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698