OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 inline T* operator->() const { return p_; } | 56 inline T* operator->() const { return p_; } |
57 | 57 |
58 // You can get the underlying pointer out with the * operator. | 58 // You can get the underlying pointer out with the * operator. |
59 inline T* operator*() { return p_; } | 59 inline T* operator*() { return p_; } |
60 | 60 |
61 // You can use [n] to index as if it was a plain pointer | 61 // You can use [n] to index as if it was a plain pointer |
62 inline T& operator[](size_t i) { | 62 inline T& operator[](size_t i) { |
63 return p_[i]; | 63 return p_[i]; |
64 } | 64 } |
65 | 65 |
| 66 // You can use [n] to index as if it was a plain pointer |
| 67 const inline T& operator[](size_t i) const { |
| 68 return p_[i]; |
| 69 } |
| 70 |
66 // We don't have implicit conversion to a T* since that hinders migration: | 71 // We don't have implicit conversion to a T* since that hinders migration: |
67 // You would not be able to change a method from returning a T* to | 72 // You would not be able to change a method from returning a T* to |
68 // returning an SmartArrayPointer<T> and then get errors wherever it is used. | 73 // returning an SmartArrayPointer<T> and then get errors wherever it is used. |
69 | 74 |
70 | 75 |
71 // If you want to take out the plain pointer and don't want it automatically | 76 // If you want to take out the plain pointer and don't want it automatically |
72 // deleted then call Detach(). Afterwards, the smart pointer is empty | 77 // deleted then call Detach(). Afterwards, the smart pointer is empty |
73 // (NULL). | 78 // (NULL). |
74 inline T* Detach() { | 79 inline T* Detach() { |
75 T* temp = p_; | 80 T* temp = p_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 inline SmartPointer() { } | 135 inline SmartPointer() { } |
131 explicit inline SmartPointer(T* ptr) | 136 explicit inline SmartPointer(T* ptr) |
132 : SmartPointerBase<ObjectDeallocator<T>, T>(ptr) { } | 137 : SmartPointerBase<ObjectDeallocator<T>, T>(ptr) { } |
133 inline SmartPointer(const SmartPointer<T>& rhs) | 138 inline SmartPointer(const SmartPointer<T>& rhs) |
134 : SmartPointerBase<ObjectDeallocator<T>, T>(rhs) { } | 139 : SmartPointerBase<ObjectDeallocator<T>, T>(rhs) { } |
135 }; | 140 }; |
136 | 141 |
137 } } // namespace v8::internal | 142 } } // namespace v8::internal |
138 | 143 |
139 #endif // V8_SMART_POINTERS_H_ | 144 #endif // V8_SMART_POINTERS_H_ |
OLD | NEW |