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
| /* Some Singleton Implementation Examples. */ | |
| /* Mainly consider of lazy initialization. */ | |
| // Version 1: simple lazy singleton. | |
| // Not thread safe. Can only be used in single thread. | |
| template<typename T> | |
| class Singleton { | |
| public: | |
| static T& getInstance() { |
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> | |
| #include <cinttypes> | |
| int main (void) { | |
| uint32_t num = 0x04030201; | |
| unsigned char* cp = reinterpret_cast<unsigned char*>(&num); | |
| if (*cp == 1) { | |
| std::cout << "littile-endian" << std::endl; | |
| } else if (*cp == 4) { |
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
| // Reference Rules for a variable | |
| // a). At any given time, you can have either (but not both of) one mutable reference or any number of immutable references. | |
| // b). References must always be valid. | |
| // First we define a simple struct | |
| struct Foo<T> { | |
| data: T, | |
| } | |
| impl<T> Foo<T> { |