This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <class T> | |
| class AutoPtr { | |
| public: | |
| AutoPtr(T* aPointer) | |
| : thePointer(aPointer) | |
| {} | |
| ~AutoPtr() { | |
| delete thePointer; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int main() { | |
| AutoPtr<Bomb> a(new Bomb()); | |
| a.reset(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void reset() { | |
| T* tmp = thePointer; | |
| thePointer = nullptr; | |
| delete tmp; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdexcept> | |
| class Bomb { | |
| public: | |
| ~Bomb() { throw std::runtime_error("BOOM"); } | |
| }; | |
| int main() | |
| try { | |
| Bomb b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void* operator new (std::size_t size); | |
| void* operator new (std::size_t size, const std::nothrow_t& nothrow_value) noexcept; | |
| void* operator new (std::size_t size, void* ptr) noexcept; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new_handler set_new_handler (new_handler new_p) noexcept; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| class ReservedMemory { | |
| public: | |
| ReservedMemory() | |
| : theMemoryReserved(new char[80000*1024]) | |
| {} | |
| ~ReservedMemory() { delete []theMemoryReserved; } | |
| void release() { | |
| if (theMemoryReserved) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int sumScale(int a, int b, int c) { | |
| return c*(a + b); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <class T> | |
| T sumScale(T a, T b, int c) { | |
| return c*(a + b); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <class T> | |
| concept bool SummableScalable() { | |
| return requires(T a, T b, int c) { | |
| {a + b}->T; | |
| {c * a}->T; | |
| }; | |
| } |