Compare commits
2 Commits
3928379d6f
...
7ac9576710
Author | SHA1 | Date | |
---|---|---|---|
7ac9576710 | |||
37a4a0c30b |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
.build/
|
||||
.cache/
|
||||
bin/
|
||||
compile_commands.json
|
@ -1,21 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
project(
|
||||
Builder
|
||||
VERSION 0.1.0
|
||||
LANGUAGES CXX)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../cmake")
|
||||
|
||||
include(ExportCompileCommands)
|
||||
include(sccache)
|
||||
|
||||
add_executable(Builder main.cpp)
|
||||
|
||||
target_compile_features(Builder PUBLIC cxx_std_20)
|
||||
|
||||
set_target_properties(
|
||||
Builder
|
||||
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
|
@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
cmake -S . -B .build -G Ninja -D CMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
ln -s .build/compile_commands.json
|
@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
cmake --build .build
|
@ -1,8 +0,0 @@
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
std::cout << "Builder" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,42 +1,9 @@
|
||||
#include <cstdlib>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
||||
class Singleton {
|
||||
private:
|
||||
static Singleton *singleton;
|
||||
static std::mutex mutex;
|
||||
|
||||
Singleton() = default;
|
||||
|
||||
public:
|
||||
Singleton(const Singleton &other) = delete;
|
||||
Singleton &operator=(const Singleton &) = delete;
|
||||
|
||||
static Singleton *GetInstance() {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
if (singleton == nullptr) {
|
||||
singleton = new Singleton();
|
||||
}
|
||||
|
||||
return singleton;
|
||||
}
|
||||
};
|
||||
|
||||
Singleton *Singleton::singleton = nullptr;
|
||||
std::mutex Singleton::mutex;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
std::cout << "Singleton" << std::endl;
|
||||
|
||||
auto singleton1 = Singleton::GetInstance();
|
||||
auto singleton2 = Singleton::GetInstance();
|
||||
|
||||
std::cout << std::setw(20) << "Singleton 1: " << singleton1 << std::endl;
|
||||
std::cout << std::setw(20) << "Singleton 2: " << singleton2 << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user