Lines Matching refs:to
14 // used to endorse or promote products derived from this software without
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48 // - Performing arithmetic conversions (int32 to int64, int to double, etc.).
51 // In general, implicit_cast can be used to convert this code
52 // To to = from;
53 // DoSomething(to);
54 // to this
55 // DoSomething(implicit_cast<To>(from));
57 // base::identity_ is used to make a non-deduced context, which
58 // forces all callers to explicitly specify the template argument.
59 template<typename To>
60 inline To implicit_cast(typename identity_<To>::type to) {
61 return to;
66 template<typename To, typename From>
67 inline To implicit_cast(typename identity_<From>::type const &f) {
71 // When you upcast (that is, cast a pointer from type Foo to type
72 // SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts
74 // type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
78 // use dynamic_cast<> to double-check the downcast is legal (we die
80 // instead. Thus, it's important to test in debug mode to make sure
83 // In particular, you SHOULDN'T be using dynamic_cast<> in order to
87 // You should design the code some other way not to need this.
89 template<typename To, typename From> // use like this: down_cast<T*>(foo);
90 inline To down_cast(From* f) { // so we only accept pointers
91 // Ensures that To is a sub-type of From *. This test is here only
98 implicit_cast<From*, To>(NULL);
102 assert(f == NULL || dynamic_cast<To>(f) != NULL); // NOLINT
103 return static_cast<To>(f);