diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..08b59108 --- /dev/null +++ b/.clang-format @@ -0,0 +1,11 @@ +BasedOnStyle: Google +IndentWidth: 4 +AccessModifierOffset: -4 +ColumnLimit: 100 +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +DerivePointerAlignment: true +KeepEmptyLinesAtTheStartOfBlocks: true +SortIncludes: true + diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..f062712c --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,48 @@ +--- + +Checks: '-*,cppcoreguidelines-avoid-goto,cppcoreguidelines-pro-type-const-cast, google-runtime-int, modernize-use-nullptr, readability-braces-around-statements, readability-container-size-empty, readability-redundant-control-flow, readability-identifier-naming, readability-simplify-boolean-expr, google-build-using-namespace, readability-implicit-bool-conversion, google-explicit-constructor' + +CheckOptions: + - key: readability-identifier-naming.NamespaceCase + value: lower_case + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.StructCase + value: CamelCase + - key: readability-identifier-naming.TypedefCase + value: lower_case + - key: readability-identifier-naming.TypeAliasCase + value: lower_case + - key: readability-identifier-naming.FunctionCase + value: CamelCase + - key: readability-identifier-naming.ParameterCase + value: lower_case + - key: readability-identifier-naming.VariableCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberSuffix + value: '_' + - key: readability-identifier-naming.GlobalConstantCase + value: CamelCase + - key: readability-identifier-naming.GlobalConstantPrefix + value: k + - key: readability-identifier-naming.StaticConstantCase + value: CamelCase + - key: readability-identifier-naming.StaticConstantPrefix + value: k + - key: readability-identifier-naming.ConstexprVariableCase + value: CamelCase + - key: readability-identifier-naming.ConstexprVariablePrefix + value: k + - key: readability-identifier-naming.TypeTemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.ClassMemberCase + value: lower_case + - key: readability-identifier-naming.ClassMemberSuffix + value: '_' + - key: readability-simplify-boolean-expr.ChainedConditionalReturn + value: '1' + - key: readability-simplify-boolean-expr.ChainedConditionalAssignment + value: '1' + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..db1e49c4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: ci + +on: [pull_request] + +jobs: + ci: + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: tests + env: + CLANG_FORMAT_SUBMODULE: /home/runner/work/HSE-Course/HSE-Course/clangformat-cmake + TITLE: ${{github.event.pull_request.title}} + working-directory: ./module-1/homework/ + run: + sudo apt-get install clang-tidy-10 && + sudo apt-get install clang-format-10 && + sudo rm -rf /usr/bin/clang-tidy && + sudo rm -rf /usr/bin/clang-format && + sudo ln -s /usr/bin/clang-tidy-10 /usr/bin/clang-tidy && + sudo ln -s /usr/bin/clang-format-10 /usr/bin/clang-format && + clang-tidy --version && + clang-format --version && + git submodule update --init --recursive && + prname=${TITLE} && + cmake -B ${prname}/build -S ${prname} && + cmake --build ${prname}/build --target runner clangformat && + ./${prname}/build/runner \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..2942881b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "clangformat-cmake"] + path = clangformat-cmake + url = https://github.com/morell5/clangformat-cmake.git +[submodule "module-1/homework/Allocator/clangformat-cmake"] + path = module-1/homework/Allocator/clangformat-cmake + url = https://github.com/zemasoft/clangformat-cmake diff --git a/README.md b/README.md index 326ac5ea..3f8b0b95 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ ## Структура репозитория -`module-1` - задания и семинары за 1-ое учебное полугодие
-`module-2` - задания и семинары за 2-ое учебное полугодие
+`module-1` - задания и семинары
## Сдача заданий @@ -23,4 +22,4 @@ ## Связь -[Slack Workspace](https://join.slack.com/t/1c-hseworkspace/shared_invite/zt-h4q9ff3l-oKj26qGMHhmoLH5G7hDpYA) \ No newline at end of file +[Slack Workspace](https://join.slack.com/t/1c-hseworkspace/shared_invite/zt-n67k87vo-d~ypzAzri~Tu4e15zQLSBw) \ No newline at end of file diff --git a/clangformat-cmake b/clangformat-cmake new file mode 160000 index 00000000..af9301a2 --- /dev/null +++ b/clangformat-cmake @@ -0,0 +1 @@ +Subproject commit af9301a267935869fd8d2d4325ae912c934c41f3 diff --git a/module-1/homework/Allocator/CMakeLists.txt b/module-1/homework/Allocator/CMakeLists.txt new file mode 100644 index 00000000..790ffa90 --- /dev/null +++ b/module-1/homework/Allocator/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.16) + +include(GoogleTest) + +project("runner") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +################ gtest ################ +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() + +################ Sanitizers ################ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold -fsanitize=undefined,address -fno-sanitize-recover=all -O2 -Wall -Werror -Wsign-compare") + +################ clang-tidy ################ +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-header-filter=.") + +add_executable(runner tests.cpp) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(runner) + +add_subdirectory(src/allocator) +add_subdirectory(src/list) + +target_link_libraries(runner LINK_PUBLIC list allocator gtest_main) + +add_test(NAME runner_test COMMAND runner) \ No newline at end of file diff --git a/module-1/homework/Allocator/CMakeLists.txt.in b/module-1/homework/Allocator/CMakeLists.txt.in new file mode 100644 index 00000000..f98ccb4a --- /dev/null +++ b/module-1/homework/Allocator/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/module-1/homework/Allocator/clangformat-cmake b/module-1/homework/Allocator/clangformat-cmake new file mode 160000 index 00000000..ced236e1 --- /dev/null +++ b/module-1/homework/Allocator/clangformat-cmake @@ -0,0 +1 @@ +Subproject commit ced236e1919c412f5cf745de9a116cae119e7315 diff --git a/module-1/homework/Allocator/src/allocator/CMakeLists.txt b/module-1/homework/Allocator/src/allocator/CMakeLists.txt new file mode 100644 index 00000000..8cb8ba47 --- /dev/null +++ b/module-1/homework/Allocator/src/allocator/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +project(runner) + +add_library(allocator allocator.h) +set_target_properties(allocator PROPERTIES LINKER_LANGUAGE CXX) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(allocator) \ No newline at end of file diff --git a/module-1/homework/Allocator/src/allocator/allocator.h b/module-1/homework/Allocator/src/allocator/allocator.h new file mode 100644 index 00000000..6ff53187 --- /dev/null +++ b/module-1/homework/Allocator/src/allocator/allocator.h @@ -0,0 +1,120 @@ +#include +#include + +template +class CustomAllocator { +public: + template + struct rebind { // NOLINT + using other = CustomAllocator; + }; + using value_type = T; + using pointer = T*; + using const_pointer = const T*; + using reference = T&; + using const_reference = const T&; + using size_type = size_t; + using difference_type = ptrdiff_t; + + // Influence on container operations + using propagate_on_container_move_assignment = std::false_type; + using propagate_on_container_copy_assignment = std::false_type; + using propagate_on_container_swap = std::true_type; + using is_always_equal = std::false_type; + + CustomAllocator(); + CustomAllocator(const CustomAllocator& other) noexcept; + ~CustomAllocator(); + + template + explicit CustomAllocator(const CustomAllocator& other) noexcept; + + T* allocate(size_t n) { // NOLINT + if (*arena_offset_ + n > ARENA_BASIC_SIZE) { + throw std::runtime_error("Allocator's arena is full"); + } + + *arena_offset_ += n; + + return static_cast(arena_) + (*arena_offset_ - n); + } + + void deallocate(T*, size_t) { // NOLINT + } + + template + void construct(pointer p, Args&&... args) { // NOLINT + ::new (p) value_type(std::forward(args)...); + }; + + void destroy(pointer p) { // NOLINT + p->~T(); + }; + + void* get_arena() const { + return arena_; + } + + size_t* get_arena_offset() const { + return arena_offset_; + } + + size_t* get_allocators_count() const { + return allocators_count_; + } + + template + friend bool operator==(const CustomAllocator& lhs, const CustomAllocator& rhs) noexcept; + template + friend bool operator!=(const CustomAllocator& lhs, const CustomAllocator& rhs) noexcept; + +private: + static const size_t ARENA_BASIC_SIZE = 65536; + void* arena_ = nullptr; + size_t* arena_offset_ = nullptr; + size_t* allocators_count_ = nullptr; +}; + +template +CustomAllocator::CustomAllocator() { + arena_ = ::operator new(ARENA_BASIC_SIZE * sizeof(T)); + arena_offset_ = new size_type(0); + allocators_count_ = new size_type(1); +} + +template +CustomAllocator::CustomAllocator(const CustomAllocator& other) noexcept + : arena_{other.arena_}, + arena_offset_{other.arena_offset_}, + allocators_count_{other.allocators_count_} { + ++(*allocators_count_); +} + +template +CustomAllocator::~CustomAllocator() { + --(*allocators_count_); + if (*allocators_count_ == 0) { + ::operator delete(arena_); + delete arena_offset_; + delete allocators_count_; + } +} + +template +template +CustomAllocator::CustomAllocator(const CustomAllocator& other) noexcept + : arena_{other.get_arena()}, + arena_offset_{other.get_arena_offset()}, + allocators_count_{other.get_allocators_count()} { + ++(*allocators_count_); +} + +template +bool operator==(const CustomAllocator& lhs, const CustomAllocator& rhs) noexcept { + return lhs.arena_ == rhs.arena_; +} + +template +bool operator!=(const CustomAllocator& lhs, const CustomAllocator& rhs) noexcept { + return lhs.arena_ != rhs.arena_; +} \ No newline at end of file diff --git a/module-1/homework/Allocator/src/list/CMakeLists.txt b/module-1/homework/Allocator/src/list/CMakeLists.txt new file mode 100644 index 00000000..90a496de --- /dev/null +++ b/module-1/homework/Allocator/src/list/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +project(runner) + +add_library(list list.h) +set_target_properties(list PROPERTIES LINKER_LANGUAGE CXX) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(list) \ No newline at end of file diff --git a/module-1/homework/Allocator/src/list/list.h b/module-1/homework/Allocator/src/list/list.h new file mode 100644 index 00000000..84a9ce5a --- /dev/null +++ b/module-1/homework/Allocator/src/list/list.h @@ -0,0 +1,553 @@ +#pragma once + +#include +#include +#include + +namespace task { +template +class Node { +public: + Node(Node* prev, Node* next, T value) : value(value), prev(prev), next(next) { + } + + void push_back(Node* node) { + next = node; + if (node) + node->prev = this; + } + + void push_front(Node* node) { + prev = node; + if (node) + node->next = this; + } + + ~Node() { + } + + T value; + Node* prev = nullptr; + Node* next = nullptr; + + // friend class List::Iterator; +}; + +template > +class List { +private: + class Iterator; + +public: + using value_type = T; + // Your code goes here + using allocator_type = Allocator; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + using reference = value_type&; + using const_reference = const value_type&; + using pointer = typename std::allocator_traits::pointer; + using const_pointer = typename std::allocator_traits::const_pointer; + using iterator = Iterator; + using const_iterator = const Iterator; + + // Special member functions + List() { + Node* x = alloc_.allocate(1); + alloc_.construct(x, nullptr, nullptr, T()); + head_ = tail_ = x; + } + List(const List& other); + List(const List& other, const Allocator& alloc); + List(List&& other) noexcept; + List(List&& other, const Allocator& alloc); + + ~List(); + + List& operator=(const List& other); + + List& operator=(List&& other) noexcept; + + // Element access + reference Front(); + const_reference Front() const; + reference Back(); + const_reference Back() const; + + // Iterators + iterator Begin() noexcept; + const_iterator Begin() const noexcept; + + iterator End() noexcept; + const_iterator End() const noexcept; + + // Capacity + bool Empty() const noexcept; + + size_type Size() const noexcept; + + size_type MaxSize() const noexcept; + + // Modifiers + void Clear(); + void Swap(List& other) noexcept; + + void PushBack(const T& value); + void PushBack(T&& value); + + template + void EmplaceBack(Args&&... args); + void PopBack(); + void PushFront(const T& value); + void PushFront(T&& value); + template + void EmplaceFront(Args&&... args); + void PopFront(); + + void Resize(size_type count); + + // Operations + void Remove(const T& value); + void Unique(); + void Sort(); + + allocator_type GetAllocator() const noexcept; + +private: + typedef typename std::allocator_traits::template rebind_alloc> node_alocator; + + node_alocator alloc_; + Node* head_; + Node* tail_; + std::size_t list_size_ = 0; + +private: + class Iterator { + public: + using value_type = List::value_type; + using pointer = List::pointer; + using reference = List::reference; + using difference_type = ptrdiff_t; + using iterator_category = std::bidirectional_iterator_tag; + + explicit Iterator(Node* node) : node_(node) { + } + + Iterator& operator++() { + node_ = node_->next; + return *this; + } + + Iterator operator++(int) { + Iterator iter(*this); + ++(*this); + return iter; + } + + Iterator& operator--() { + node_ = node_->prev; + return *this; + } + + Iterator operator--(int) { + Iterator iter(*this); + --(*this); + return iter; + } + + bool operator==(const iterator& other) { + return node_ == other.node_; + } + + bool operator!=(const iterator& other) { + return node_ != other.node_; + } + + pointer operator->() const { + return &node_->value; + } + + reference operator*() const { + return node_->value; + } + + private: + Node* node_; + }; +}; + +template +List::List(const List& other) : alloc_(other.alloc_) { + for (Node* x = other.head_; x != nullptr; x = x->next) + PushBack(x->value); + --list_size_; +} + +template +List::List(const List& other, const Allocator& alloc) { + alloc_ = alloc; + for (Node* x = other.head_; x != nullptr; x = x->next) + PushBack(x->value); + --list_size_; +} + +template +List::List(List&& other) noexcept { + *this = std::move(other); +} + +template +List::List(List&& other, const Allocator& alloc) { + alloc_ = alloc; + for (Node* x = other.head_; x != nullptr; x = x->next) + PushBack(std::move(x->value)); + + other.Clear(); +} + +template +List::~List() { + Clear(); + alloc_.destroy(tail_); + alloc_.deallocate(tail_, 1); +} + +template +List& List::operator=(const List& other) { + if (this == &other) + return *this; + + Clear(); + + if (std::allocator_traits::propagate_on_container_copy_assignment::value) + alloc_ = other.alloc_; + + for (Node* x = other.head_; x != other.tail_; x = x->next) + PushBack(x->value); + + return *this; +} + +template +List& List::operator=(List&& other) noexcept { + if (this == &other) + return *this; + + Clear(); + + if (std::allocator_traits::propagate_on_container_move_assignment::value) { + + other.alloc_.destroy(tail_); + other.alloc_.deallocate(tail_, 1); + alloc_ = other.alloc_; + + head_ = other.head_; + other.head_ = nullptr; + + tail_ = other.tail_; + other.tail_ = nullptr; + + list_size_ = other.list_size_; + + Node* x = alloc_.allocate(1); + alloc_.construct(x, nullptr, nullptr, T()); + other.head_ = other.tail_ = x; + other.list_size_ = 0; + } else { + for (Node* x = other.head_; x != other.tail_; x = x->next) + PushBack(std::move(x->value)); + + other.Clear(); + other.alloc_.destroy(other.tail_); + other.alloc_.deallocate(other.tail_, 1); + } + + return *this; +} + +template +typename List::reference List::Front() { + return head_->value; +} + +template +typename List::const_reference List::Front() const { + return head_->value; +} + +template +typename List::reference List::Back() { + return tail_->prev->value; +} + +template +typename List::const_reference List::Back() const { + return tail_->prev->value; +} + +template +typename List::iterator List::Begin() noexcept { + return iterator(head_); +} + +template +typename List::const_iterator List::Begin() const noexcept { + return const_iterator(head_); +} + +template +typename List::iterator List::End() noexcept { + return iterator(tail_); +} + +template +typename List::const_iterator List::End() const noexcept { + return const_iterator(tail_); +} + +template +bool List::Empty() const noexcept { + return list_size_ == 0; +} + +template +size_t List::Size() const noexcept { + return list_size_; +} + +template +void List::Clear() { + while (list_size_ != 0) + PopBack(); +} + +template +void List::Swap(List& other) noexcept { + if (std::allocator_traits::propagate_on_container_swap::value) { + std::swap(alloc_, other.alloc_); + std::swap(head_, other.head_); + std::swap(tail_, other.tail_); + std::swap(list_size_, other.list_size_); + } else { + List t = std::move(other); + other = std::move(*this); + *this = std::move(t); + } +} + +template +void List::PushBack(const T& value) { + Node* x = alloc_.allocate(1); + if (Empty()) { + alloc_.construct(x, nullptr, nullptr, value); + head_ = x; + head_->next = tail_; + tail_->prev = head_; + } else { + alloc_.construct(x, nullptr, tail_, value); + tail_->prev->push_back(x); + tail_->prev = x; + } + ++list_size_; +} + +template +void List::PushBack(T&& value) { + Node* x = alloc_.allocate(1); + if (Empty()) { + alloc_.construct(x, nullptr, nullptr, std::move(value)); + head_ = x; + head_->next = tail_; + tail_->prev = head_; + } else { + alloc_.construct(x, nullptr, tail_, std::move(value)); + tail_->prev->push_back(x); + tail_->prev = x; + } + ++list_size_; +} + +template +template +void List::EmplaceBack(Args&&... args) { + Node* x = alloc_.allocate(1); + alloc_.construct(x, tail_->prev, tail_, std::forward(args)...); + + if (head_ == tail_) { + head_ = x; + } else { + x->prev->next = x; + } + tail_->prev = x; + ++list_size_; +} + +template +void List::PopBack() { + if (list_size_ == 1) { + alloc_.destroy(head_); + alloc_.deallocate(head_, 1); + head_ = tail_; + --list_size_; + } else if (list_size_ > 1) { + Node* x = tail_->prev; + tail_->prev = tail_->prev->prev; + tail_->prev->next = tail_; + + alloc_.destroy(x); + alloc_.deallocate(x, 1); + --list_size_; + } +} + +template +void List::PushFront(const T& value) { + Node* x = alloc_.allocate(1); + if (Empty()) { + alloc_.construct(x, nullptr, tail_, value); + head_ = x; + tail_->prev = head_; + } else { + alloc_.construct(x, nullptr, head_, value); + head_->push_front(x); + head_ = head_->prev; + } + ++list_size_; +} + +template +void List::PushFront(T&& value) { + Node* x = alloc_.allocate(1); + if (Empty()) { + alloc_.construct(x, nullptr, tail_, std::move(value)); + head_ = x; + tail_->prev = head_; + } else { + alloc_.construct(x, nullptr, head_, std::move(value)); + head_->push_front(x); + head_ = head_->prev; + } + ++list_size_; +} + +template +template +void List::EmplaceFront(Args&&... args) { + Node* x = alloc_.allocate(1); + alloc_.construct(x, nullptr, head_, std::forward(args)...); + + if (head_ != tail_) { + head_->prev = x; + } + head_ = x; +} + +template +void List::PopFront() { + if (list_size_ == 1) { + alloc_.destroy(head_); + alloc_.deallocate(head_, 1); + head_ = tail_; + --list_size_; + } else if (list_size_ > 1) { + Node* x = head_; + head_ = head_->next; + head_->prev = nullptr; + + alloc_.destroy(x); + alloc_.deallocate(x, 1); + --list_size_; + } +} + +template +void List::Resize(size_type count) { + if (count < 0) + return; + while (count > list_size_) + PushBack(T()); + + while (count < list_size_) + PopBack(); +} + +template +void List::Remove(const T& value) { + if (list_size_ == 0) + return; + + Node* x = head_; + Node* delx = nullptr; + + while (x != tail_) { + if (x->value == value) { + if (x->prev) { + x->next->prev = x->prev; + x->prev->next = x->next; + } else { + x->next->prev = nullptr; + } + delx = x; + + if (x == head_) { + head_ = x->next; + } + } + x = x->next; + if (delx) { + alloc_.destroy(delx); + alloc_.deallocate(delx, 1); + --list_size_; + delx = nullptr; + } + } +} + +template +void List::Unique() { + if (list_size_ < 2) + return; + T pred = head_->value; + Node* x = head_->next; + Node* delx = nullptr; + + while (x != tail_) { + if (x->value == pred) { + delx = x; + x->prev->push_back(x->next); + x = x->next; + + alloc_.destroy(delx); + alloc_.deallocate(delx, 1); + --list_size_; + } else { + pred = x->value; + x = x->next; + } + } +} + +template +void List::Sort() { + std::vector values; + + Node* x = head_; + while (x != tail_) { + values.push_back(x->value); + x = x->next; + } + + std::sort(values.begin(), values.end()); + + Clear(); + + for (T& d : values) + PushBack(d); +} + +template +typename List::allocator_type List::GetAllocator() const noexcept { + return Allocator(alloc_); +} + +} // namespace task diff --git a/module-1/homework/Allocator/task.md b/module-1/homework/Allocator/task.md new file mode 100644 index 00000000..319350e2 --- /dev/null +++ b/module-1/homework/Allocator/task.md @@ -0,0 +1,23 @@ +# Allocator + +## Задание + +Взять свою имплементацию `list` из задания `List` + +Добавить: +* move-constructor +* move-assignment operator +* iterator (должен удовлетворять категории `LegacyBidirectionalIterator`) +* allocator для `Node`(должен удовлетворять [Allocator requirements](https://en.cppreference.com/w/cpp/named_req/Allocator)) + * алгоритм размещения `Node` по одному из [алгоритмов](https://github.com/mtrebi/memory-allocators) + * интерфейс по `C++11` + +Должно быть: +* `list.h` - интерфейс и имплементация из задания `List` +* `allocator.h` - интерфейс и имплементация аллокатора по `C++11` + +Упрощение: для шаблонного параметра `T` предполагается + +```c++ +std::is_trivially_constructible::value <- true +``` \ No newline at end of file diff --git a/module-1/homework/Allocator/tests.cpp b/module-1/homework/Allocator/tests.cpp new file mode 100644 index 00000000..ce9e9a18 --- /dev/null +++ b/module-1/homework/Allocator/tests.cpp @@ -0,0 +1,265 @@ +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "src/allocator/allocator.h" +#include "src/list/list.h" + +TEST(CopyAssignment, Test) { + task::List> actual; + task::List> actual_copy; + std::list> expected; + std::list> expected_copy; + + for (std::size_t i = 0; i < 10; i++) { + actual_copy.PushBack("hello"); + expected_copy.push_back("hello"); + } + + actual = actual_copy; + expected = expected_copy; + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(MoveAssignment, Test1) { + task::List l1; + task::List l2; + std::list l3; + std::list l4; + + l1.PushBack("hello"); + l2 = std::move(l1); + l3.push_back("hello"); + l4 = std::move(l3); + + ASSERT_TRUE(std::equal(l1.Begin(), l1.End(), l3.begin(), l3.end())); + ASSERT_TRUE(std::equal(l2.Begin(), l2.End(), l4.begin(), l4.end())); +} + +TEST(Front, Test1) { + task::List> actual; + std::list> expected; + + actual.PushBack("hello"); + expected.push_back("hello"); + + actual.PushBack("hello"); + expected.push_back("hello"); + + actual.PushBack("hello"); + expected.push_back("hello"); + + actual.Clear(); + expected.clear(); + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(Clear, Test1) { + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.PushBack("hello"); + expected.push_back("hello"); + } + + actual.Clear(); + expected.clear(); + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(Swap, Test1) { + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.PushBack("hello"); + expected.push_back("hello"); + } + + task::List> actual2; + std::list> expected2; + + for (std::size_t i = 0; i < 10; i++) { + actual2.PushBack("world"); + expected2.push_back("world"); + } + + actual.Swap(actual2); + expected.swap(expected2); + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); + ASSERT_TRUE(std::equal(actual2.Begin(), actual2.End(), expected2.begin(), expected2.end())); +} + +TEST(PushBack, Test) { + std::vector actual_v(10, "hello"); + std::vector expected_v(10, "hello"); + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.PushBack(std::move(actual_v[i])); + expected.push_back(std::move(expected_v[i])); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(EmplaceBack, Test1) { + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.EmplaceBack("hello"); + expected.emplace_back("hello"); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(PopBack, Test1) { + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.EmplaceBack("hello"); + expected.emplace_back("hello"); + } + + for (std::size_t i = 0; i < 5; i++) { + actual.PopBack(); + expected.pop_back(); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(PushFront, Test1) { + std::vector actual_v(10, "hello"); + std::vector expected_v(10, "hello"); + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.PushFront(actual_v[i]); + expected.push_front(expected_v[i]); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(PushFront, Test2) { + std::vector actual_v(10, "hello"); + std::vector expected_v(10, "hello"); + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.PushFront(std::move(actual_v[i])); + expected.push_front(std::move(expected_v[i])); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(EmplaceFront, Test1) { + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.EmplaceFront("hello"); + expected.emplace_front("hello"); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(PopFront, Test1) { + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 10; i++) { + actual.EmplaceBack("hello"); + expected.emplace_back("hello"); + } + + for (std::size_t i = 0; i < 5; i++) { + actual.PopFront(); + expected.pop_front(); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(Resize, Test1) { + task::List> actual; + actual.Resize(2); + ASSERT_EQ(actual.Size(), 2); +} + +TEST(Remove, Test1) { + task::List> actual; + actual.PushBack("hello"); + actual.PushBack("world"); + actual.PushBack("hello"); + actual.Remove("hello"); + std::list> expected; + expected.push_back("world"); + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(Unique, Test1) { + task::List> actual; + actual.PushBack("hello"); + actual.PushBack("hello"); + actual.PushBack("world"); + actual.PushBack("world"); + actual.Unique(); + std::list> expected; + expected.push_back("hello"); + expected.push_back("world"); + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(Sort, Test1) { + std::random_device random_device; + std::mt19937 random_engine(random_device()); + std::uniform_int_distribution distribution(1, 100); + + task::List actual; + std::list expected; + for (size_t i = 0; i < 100; ++i) { + int value = distribution(random_engine); + actual.PushBack(value); + expected.push_back(value); + } + actual.Sort(); + expected.sort(); + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +TEST(Mixed, Test1) { + task::List> actual; + std::list> expected; + + for (std::size_t i = 0; i < 5; i++) { + actual.PushBack("hello"); + expected.push_back("hello"); + } + + for (std::size_t i = 0; i < 3; i++) { + actual.PopFront(); + expected.pop_front(); + } + + for (std::size_t i = 0; i < 5; i++) { + actual.PushFront("world"); + expected.push_front("world"); + } + + for (std::size_t i = 0; i < 3; i++) { + actual.PopBack(); + expected.pop_back(); + } + ASSERT_TRUE(std::equal(actual.Begin(), actual.End(), expected.begin(), expected.end())); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/module-1/homework/BigInteger/CMakeLists.txt b/module-1/homework/BigInteger/CMakeLists.txt index a1330c96..dbd259a7 100644 --- a/module-1/homework/BigInteger/CMakeLists.txt +++ b/module-1/homework/BigInteger/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16) include(GoogleTest) -project("BigInteger") +project("runner") configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) diff --git a/module-1/homework/Optional/CMakeLists.txt b/module-1/homework/Optional/CMakeLists.txt new file mode 100644 index 00000000..c1ae97fd --- /dev/null +++ b/module-1/homework/Optional/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.16) + +include(GoogleTest) + +project("runner") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +################ gtest ################ +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() + +################ Sanitizers ################ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold -fsanitize=undefined,address -fno-sanitize-recover=all -O2 -Wall -Werror -Wsign-compare") + +################ clang-tidy ################ +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-header-filter=.") + +add_executable(runner tests.cpp optional.h) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(runner) + +target_link_libraries(runner LINK_PUBLIC gtest_main) + +add_test(NAME runner_test COMMAND runner) \ No newline at end of file diff --git a/module-1/homework/Optional/CMakeLists.txt.in b/module-1/homework/Optional/CMakeLists.txt.in new file mode 100644 index 00000000..f98ccb4a --- /dev/null +++ b/module-1/homework/Optional/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/module-1/homework/Optional/optional.h b/module-1/homework/Optional/optional.h new file mode 100644 index 00000000..1c2bbf91 --- /dev/null +++ b/module-1/homework/Optional/optional.h @@ -0,0 +1,64 @@ +#include +#include + +#pragma once + +namespace task { + +struct NullOpt { + // Your code goes here; +}; + +constexpr NullOpt kNullOpt = // Your code goes here; + +struct InPlace { + // Your code goes here; +}; + +constexpr InPlace kInPlace = //Your code goes here; + +template +class Optional : public // Your code goes here; { +public: + using value_type = // Your code goes here; + + constexpr Optional() noexcept; + + template + constexpr explicit Optional(U&& value); + + constexpr explicit Optional(NullOpt) noexcept; + + template + constexpr explicit Optional(InPlace, Args&&... args); + + Optional& operator=(NullOpt) noexcept; + + template + Optional& operator=(U&& value); + + void Reset() noexcept; + + template + constexpr T ValueOr(U&& default_value) const&; + + template + constexpr T ValueOr(U&& default_value) &&; + + constexpr bool HasValue() const noexcept; + + constexpr explicit operator bool() const noexcept; + + constexpr std::add_pointer_t operator->() const; + + constexpr std::add_pointer_t operator->(); + + constexpr const value_type& operator*() const&; + + constexpr value_type& operator*() &; + + constexpr const value_type&& operator*() const&&; + + constexpr value_type&& operator*() &&; +}; +} // namespace task \ No newline at end of file diff --git a/module-1/homework/Optional/task.md b/module-1/homework/Optional/task.md new file mode 100644 index 00000000..16ffcb78 --- /dev/null +++ b/module-1/homework/Optional/task.md @@ -0,0 +1,41 @@ +# Optional + +## Задание + +[`Optional`](https://en.cppreference.com/w/cpp/utility/optional) - контейнер, реализующий функциональность опионального хранения
заданного значения / пустого значения (отдельно выделенного) + +Конструкторы: + +````c++ +constexpr Optional() noexcept; +```` + +```c++ +template< class U = value_type > +constexpr Optional( U&& value ); +``` + +```c++ +constexpr Optional(nullopt_t) noexcept; +``` + +```c++ +template +constexpr explicit Optional(in_place_t, _Args&&... __args); +``` + +Реализовать операторы: +* `->` - разыменования с обращением к полю / методу +* `*` - разыменования +* `bool()` - преобразование к `bool` + +Методы: +* `HasValue` - проверка наличия значения +* `ValueOr` - возвращает хранимое значение при его наличии или передаваемый аргумент
+при отсутствии хранимого значения +* `Reset` - вызов деструктора у хранимого значении при наличии деструктора у типа этого значения + +Можно использовать: +* `std::is_trivially_destructible` +* `std::addressof` +* `std::add_pointer_t` \ No newline at end of file diff --git a/module-1/homework/Optional/tests.cpp b/module-1/homework/Optional/tests.cpp new file mode 100644 index 00000000..749f0981 --- /dev/null +++ b/module-1/homework/Optional/tests.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include "gtest/gtest.h" +#include "optional.h" + +TEST(ValueOR, Test1) { + task::Optional opt("Hello world"); + ASSERT_EQ(opt.ValueOr("empty"), "Hello world"); +} + +TEST(ValueOR, Test2) { + task::Optional opt; + ASSERT_EQ(opt.ValueOr("empty"), "empty"); +} + +TEST(HasValue, Test1) { + task::Optional opt("Hello world"); + ASSERT_TRUE(opt.HasValue()); +} + +TEST(Reset, Test1) { + task::Optional opt("Hello world"); + opt.Reset(); + ASSERT_FALSE(opt.HasValue()); +} + +TEST(ConversionToBool, Test1) { + task::Optional opt("Hello world"); + ASSERT_TRUE(opt); +} + +TEST(ArrowOperator, Test1) { + task::Optional opt("Hello world"); + ASSERT_EQ(std::string(opt->c_str()), "Hello world"); +} + +TEST(IndirectionOperator, Test1) { + task::Optional opt(1); + ASSERT_EQ(*opt, 1); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/module-1/homework/SharedPointer/.gitignore b/module-1/homework/SharedPointer/.gitignore new file mode 100644 index 00000000..3c34c2f5 --- /dev/null +++ b/module-1/homework/SharedPointer/.gitignore @@ -0,0 +1 @@ +*build* \ No newline at end of file diff --git a/module-1/homework/SharedPointer/CMakeLists.txt b/module-1/homework/SharedPointer/CMakeLists.txt new file mode 100644 index 00000000..b5513e61 --- /dev/null +++ b/module-1/homework/SharedPointer/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.16) + +include(GoogleTest) + +project("runner") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +################ gtest ################ +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() + +################ clang-tidy ################ +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-header-filter=.") + +add_executable(runner tests.cpp) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(runner) + +add_subdirectory(src/control) +add_subdirectory(src/shared_ptr) + +target_link_libraries(runner LINK_PUBLIC control shared_ptr gtest_main) + +add_test(NAME runner_test COMMAND runner) \ No newline at end of file diff --git a/module-1/homework/SharedPointer/CMakeLists.txt.in b/module-1/homework/SharedPointer/CMakeLists.txt.in new file mode 100644 index 00000000..f98ccb4a --- /dev/null +++ b/module-1/homework/SharedPointer/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/module-1/homework/SharedPointer/src/control/CMakeLists.txt b/module-1/homework/SharedPointer/src/control/CMakeLists.txt new file mode 100644 index 00000000..c5047ad5 --- /dev/null +++ b/module-1/homework/SharedPointer/src/control/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +project(runner) + +add_library(control control.h) +set_target_properties(control PROPERTIES LINKER_LANGUAGE CXX) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(control) \ No newline at end of file diff --git a/module-1/homework/SharedPointer/src/control/control.h b/module-1/homework/SharedPointer/src/control/control.h new file mode 100644 index 00000000..b2fc359b --- /dev/null +++ b/module-1/homework/SharedPointer/src/control/control.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +class SharedCount { +public: + // Your code goes here... + +protected: + // Your code goes here... +}; + +class SharedWeakCount : public SharedCount { +public: + // Your code goes here... + +protected: + // Your code goes here... +}; + +template +class ControlBlock : public SharedWeakCount { +public: + // Your code goes here... + +private: + // Your code goes here... +}; \ No newline at end of file diff --git a/module-1/homework/SharedPointer/src/shared_ptr/CMakeLists.txt b/module-1/homework/SharedPointer/src/shared_ptr/CMakeLists.txt new file mode 100644 index 00000000..0b306ad3 --- /dev/null +++ b/module-1/homework/SharedPointer/src/shared_ptr/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +project(runner) + +add_library(shared_ptr shared_ptr.h) +set_target_properties(shared_ptr PROPERTIES LINKER_LANGUAGE CXX) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(shared_ptr) \ No newline at end of file diff --git a/module-1/homework/SharedPointer/src/shared_ptr/shared_ptr.h b/module-1/homework/SharedPointer/src/shared_ptr/shared_ptr.h new file mode 100644 index 00000000..2a60bbcf --- /dev/null +++ b/module-1/homework/SharedPointer/src/shared_ptr/shared_ptr.h @@ -0,0 +1,108 @@ +#pragma once + +#include "../control/control.h" + +// SharedPtr +template +class WeakPtr; + +template +class SharedPtr { +public: + using element_type = // Your code goes here... + + constexpr SharedPtr() noexcept = default; + ~SharedPtr(); + + template + explicit SharedPtr(Y* p); + + template + SharedPtr(Y* p, Deleter deleter) noexcept; + + SharedPtr(const SharedPtr& other) noexcept; + SharedPtr(SharedPtr&& other) noexcept; + + SharedPtr& operator=(const SharedPtr& r) noexcept; + + template + SharedPtr& operator=(const SharedPtr& r) noexcept; + + SharedPtr& operator=(SharedPtr&& r) noexcept; + + template + SharedPtr& operator=(SharedPtr&& r) noexcept; + + // Modifiers + void Reset() noexcept; + + template + void Reset(Y* p) noexcept; + + template + void Reset(Y* p, Deleter deleter) noexcept; + + void Swap(SharedPtr& other) noexcept; + + // Observers + T* Get() const noexcept; + int64_t UseCount() const noexcept; + T& operator*() const noexcept; + T* operator->() const noexcept; + element_type& operator[](std::ptrdiff_t idx) const; + explicit operator bool() const noexcept; + + template + friend class WeakPtr; + +private: + // Your code goes here... +}; + + +// MakeShared +// Your code goes here... +// MakeShared + +// SharedPtr +// Your code goes here... +// SharedPtr + +// WeakPtr +template +class WeakPtr { + +public: + using element_type = // Your code goes here... + + // Special-member functions + constexpr WeakPtr() noexcept = default; + template + explicit WeakPtr(const SharedPtr& other); + WeakPtr(const WeakPtr& other) noexcept; + WeakPtr(WeakPtr&& other) noexcept; + template + WeakPtr& operator=(const SharedPtr& other); + WeakPtr& operator=(const WeakPtr& other) noexcept; + WeakPtr& operator=(WeakPtr&& other) noexcept; + + ~WeakPtr(); + + // Modifiers + void Reset() noexcept; + void Swap(WeakPtr& other) noexcept; + + // Observers + bool Expired() noexcept; + SharedPtr Lock() const noexcept; + + template + friend class SharedPtr; + +public: + // Your code goes here... +}; + +// WeakPtr +// Your code goes here... +// WeakPtr \ No newline at end of file diff --git a/module-1/homework/SharedPointer/task.md b/module-1/homework/SharedPointer/task.md new file mode 100644 index 00000000..9aeaaaeb --- /dev/null +++ b/module-1/homework/SharedPointer/task.md @@ -0,0 +1,112 @@ +# SharedPointer + +## Задание + +Реализовать `ControlBlock` в `control.h` +* без аллокатора +* счетчик ссылок + + ```c++ + std::atomic + ``` + +Написать класс [SharedPtr](https://en.cppreference.com/w/cpp/memory/shared_ptr) + +Реализовать: +* **Special member functions** + + ```c++ + constexpr SharedPtr() noexcept = default; + + template + SharedPtr(Y* p); + + template + SharedPtr(Y* p, Deleter deleter) noexcept; + + SharedPtr(const SharedPtr& other) noexcept; + + SharedPtr(SharedPtr&& other) noexcept; + + SharedPtr& operator=( const SharedPtr& r ) noexcept; + + template + SharedPtr& operator=( const SharedPtr& r ) noexcept; + + SharedPtr& operator=( SharedPtr&& r ) noexcept; + + template + SharedPtr& operator=( SharedPtr&& r ) noexcept; + + ~SharedPtr(); + ``` + +* **Modifiers** + + ```c++ + void Reset() noexcept; + + template + void Reset(Y* p) noexcept; + + template + void Reset(Y*p, Deleter deleter) noexcept; + + void Swap(SharedPtr& other) noexcept; + ``` + +* **Observers** + + ```c++ + T* Get() const noexcept; + + long UseCount() const noexcept; + + T& operator*() const noexcept; + + T* operator->() const noexcept; + + element_type& operator[](std::ptrdiff_t idx) const; + + explicit operator bool() const noexcept; + ``` + + +Написать класс [WeakPtr](https://en.cppreference.com/w/cpp/memory/weak_ptr) + +Реализовать: +* **Special member functions** + + ```c++ + constexpr WeakPtr() noexcept = default; + + template + WeakPtr(const SharedPtr& other); + + WeakPtr(const WeakPtr& other) noexcept; + + WeakPtr(WeakPtr&& other) noexcept; + + template + WeakPtr& operator=(const SharedPtr& other); + + WeakPtr& operator=(const WeakPtr& other) noexcept; + + WeakPtr& operator=(WeakPtr&& other) noexcept; + + ~WeakPtr(); + ``` + +* **Modifiers** + + ```c++ + void Reset() noexcept; + void Swap(WeakPtr& other) noexcept; + ``` + +* **Observers** + + ```c++ + bool Expired() noexcept; + SharedPtr Lock() const noexcept; + ``` \ No newline at end of file diff --git a/module-1/homework/SharedPointer/tests.cpp b/module-1/homework/SharedPointer/tests.cpp new file mode 100644 index 00000000..00a31e2a --- /dev/null +++ b/module-1/homework/SharedPointer/tests.cpp @@ -0,0 +1,163 @@ +#include +#include + +#include "gtest/gtest.h" +#include "src/shared_ptr/shared_ptr.h" + +// WeakPtr +TEST(WeakExpired, Test1) { + WeakPtr w; + { + auto sp = MakeShared(42); + w = sp; + ASSERT_FALSE(w.Expired()); + } +} + +TEST(WeakExpired, Test2) { + WeakPtr w; + { + auto sp = MakeShared(42); + w = sp; + } + ASSERT_TRUE(w.Expired()); +} + +TEST(WeakReset, Test3) { + WeakPtr w; + auto sp = MakeShared(42); + w = sp; + w.Reset(); + ASSERT_TRUE(w.Expired()); +} + +TEST(WeakLock, Test1) { + WeakPtr w; + auto sp = MakeShared(42); + w = sp; + ASSERT_TRUE(*w.Lock() == 42); +} + +TEST(WeakLock, Test2) { + WeakPtr w; + { + auto sp = MakeShared(42); + w = sp; + } + ASSERT_FALSE(w.Lock()); +} + +// SharedPtr +TEST(SharedMoveConstructor, Test1) { + class Contrainer {}; + SharedPtr s1 = MakeShared(); + Contrainer* raw_s1 = s1.Get(); + SharedPtr s2 = std::move(s1); + ASSERT_TRUE(s1.UseCount() == 0 && s1.Get() == nullptr && s2.Get() == raw_s1 && + s2.UseCount() == 1); +} + +TEST(SharedMoveAssignment, Test1) { + class Contrainer {}; + SharedPtr s1 = MakeShared(); + Contrainer* raw_s1 = s1.Get(); + SharedPtr s2; + s2 = std::move(s1); + ASSERT_TRUE(s1.UseCount() == 0 && s1.Get() == nullptr && s2.Get() == raw_s1 && + s2.UseCount() == 1); +} + +TEST(SharedAssignment, Test1) { + class Contrainer {}; + SharedPtr s1 = MakeShared(); + SharedPtr s2; + SharedPtr s3; + s2 = s1; + s3 = s2; + + ASSERT_TRUE(s1.UseCount() == 3 && s2.UseCount() == 3 && s3.UseCount() == 3 && + s1.Get() == s2.Get() && s2.Get() == s3.Get()); +} + +TEST(SharedReset, Test1) { + class Contrainer {}; + SharedPtr s1 = MakeShared(); + s1.Reset(); + ASSERT_FALSE(s1); +} + +TEST(SharedReset, Test2) { + class Contrainer {}; + SharedPtr s1 = MakeShared(); + Contrainer* p = new Contrainer; + s1.Reset(p); + + ASSERT_TRUE(s1.Get() == p && s1.UseCount() == 1); +} + +TEST(SharedReset, Test3) { + class Contrainer {}; + + SharedPtr s1 = MakeShared(); + Contrainer* p = new Contrainer; + s1.Reset(p, std::default_delete()); + + ASSERT_TRUE(s1.Get() == p && s1.UseCount() == 1); +} + +TEST(SharedUseCount, Test1) { + class Contrainer {}; + + SharedPtr s1 = MakeShared(); + SharedPtr s2 = s1; + { SharedPtr s3 = s2; } + + ASSERT_TRUE(s1.UseCount() == 2 && s2.UseCount() == 2 && s1.Get() == s2.Get()); +} + +TEST(SharedSwap, Test1) { + SharedPtr s1 = MakeShared(1); + SharedPtr s2 = s1; + SharedPtr s3 = MakeShared(2); + auto raw_s1 = s1.Get(); + auto raw_s3 = s3.Get(); + s1.Swap(s3); + + ASSERT_TRUE(s1.UseCount() == 1 && s2.UseCount() == 2 && s3.UseCount() == 2 && + s2.Get() == s3.Get() && s2.Get() == raw_s1 && s1.Get() == raw_s3); +} + +TEST(SharedIndirectionOperator, Test1) { + SharedPtr s1 = MakeShared(1); + ASSERT_TRUE(*s1 == 1); +} + +TEST(SharedArrowOperator, Test1) { + struct Contrainer { + constexpr int Foo() const noexcept { + return 1; + } + }; + + SharedPtr s1 = MakeShared(); + ASSERT_TRUE(s1->Foo() == 1); +} + +TEST(SharedBoolOperator, Test1) { + class Contrainer {}; + + SharedPtr s1 = MakeShared(); + ASSERT_TRUE(s1); +} + +TEST(SharedBoolOperator, Test2) { + class Contrainer {}; + + SharedPtr s1; + ASSERT_FALSE(s1); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/module-1/homework/TypeTraits/.gitignore b/module-1/homework/TypeTraits/.gitignore new file mode 100644 index 00000000..3c34c2f5 --- /dev/null +++ b/module-1/homework/TypeTraits/.gitignore @@ -0,0 +1 @@ +*build* \ No newline at end of file diff --git a/module-1/homework/TypeTraits/CMakeLists.txt b/module-1/homework/TypeTraits/CMakeLists.txt new file mode 100644 index 00000000..7320c77f --- /dev/null +++ b/module-1/homework/TypeTraits/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 3.16) + +include(GoogleTest) + +project("runner") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +################ gtest ################ +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() + +################ Sanitizers ################ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold -fsanitize=undefined,address -fno-sanitize-recover=all -O2 -Wall -Werror -Wsign-compare") + +################ clang-tidy ################ +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-header-filter=.") + +add_executable(runner tests.cpp) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(runner) + +add_subdirectory(type_traits) + +target_link_libraries(runner LINK_PUBLIC type_traits gtest_main) + +add_test(NAME runner_test COMMAND runner) \ No newline at end of file diff --git a/module-1/homework/TypeTraits/CMakeLists.txt.in b/module-1/homework/TypeTraits/CMakeLists.txt.in new file mode 100644 index 00000000..f98ccb4a --- /dev/null +++ b/module-1/homework/TypeTraits/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/module-1/homework/TypeTraits/task.md b/module-1/homework/TypeTraits/task.md new file mode 100644 index 00000000..8e65baf1 --- /dev/null +++ b/module-1/homework/TypeTraits/task.md @@ -0,0 +1,24 @@ +# TypeTraits + +## Задание + +Реализовать: +* [IsCopyConstructible](https://en.cppreference.com/w/cpp/types/is_copy_constructible) +* [IsNoThrowMoveConstructible](https://en.cppreference.com/w/cpp/types/is_move_constructible) +* [MoveIfNoExcept](https://en.cppreference.com/w/cpp/utility/move_if_noexcept) + +Реализация в соответсвующих header файлах + +При реализации использовать хелперы из `utility.h` + +Замечание: следующие type_traits можно брать из std +* `std::negation` +* `std::is_base_of` +* `std::is_reference` +* `std::disjunction` +* `std::is_same` +* `std::false_type` +* `std::true_type` +* `std::integral_constant` +* `std::is_destructible` +* `std::conjunction` \ No newline at end of file diff --git a/module-1/homework/TypeTraits/tests.cpp b/module-1/homework/TypeTraits/tests.cpp new file mode 100644 index 00000000..d9e810d2 --- /dev/null +++ b/module-1/homework/TypeTraits/tests.cpp @@ -0,0 +1,140 @@ +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "type_traits/is_copy_constructible.h" +#include "type_traits/is_nothrow_move_constructible.h" +#include "type_traits/move_if_noexcept.h" + +TEST(IsConstructible, Test1) { + + class Foo { + public: + explicit Foo(int32_t n) : v1_(n), v2_() { + } + Foo(int32_t n, double f) noexcept : v1_(n), v2_(f) { + } + void Bar() { + v1_ = 0; + v2_ = 0; + } + + private: + int32_t v1_; + double v2_; + }; + + static_assert(IsConstructible::value, "expected true"); +} + +TEST(IsConstructible, Test2) { + + static_assert(IsConstructible::value, "expected true"); +} + +TEST(IsConstructible, Test3) { + + struct Base {}; + + struct Derived : Base {}; + + static_assert(!IsConstructible::value, "expected false"); + + static_assert(IsConstructible::value, "expected true"); +} + +TEST(IsConstructible, Test4) { + + struct Foo {}; + + static_assert(!IsConstructible::value, "expected false"); + + static_assert(IsConstructible::value, "expected true"); + + static_assert(!IsConstructible::value, "expected false"); +} + +TEST(IsConstructible, Test5) { + + struct Foo {}; + + static_assert(IsConstructible::value, "expected true"); + + static_assert(!IsConstructible::value, "expected false"); + + static_assert(IsConstructible::value, "expected true"); +} + +TEST(IsConstructible, Test6) { + + struct Foo {}; + + static_assert(IsConstructible::value, "expected true"); + + static_assert(IsConstructible::value, "expected true"); + + static_assert(IsConstructible::value, "expected true"); +} + +TEST(IsNoThrowMoveConstructible, Test1) { + + struct Foo { + std::string str; + }; + + static_assert(IsNoThrowMoveConstructible::value, "expected true"); +} + +TEST(IsNoThrowMoveConstructible, Test2) { + + struct Foo { + Foo(Foo&&) = default; + + int32_t n; + }; + + static_assert(IsNoThrowMoveConstructible::value, "expected true"); +} + +TEST(IsNoThrowMoveConstructible, Test3) { + + struct Foo { + Foo(const Foo&) { + } + }; + + static_assert(!IsNoThrowMoveConstructible::value, "expected true"); +} + +TEST(MoveIfNoExcept, Test1) { + + struct ThrowFoo { + bool copy = false; + ThrowFoo() = default; + ThrowFoo(ThrowFoo&&){}; + ThrowFoo(const ThrowFoo&) { + copy = true; + }; + }; + ThrowFoo foo; + ThrowFoo foo2 = MoveIfNoExcept(foo); + ASSERT_TRUE(foo2.copy); +} + +TEST(MoveIfNoExcept, Test2) { + + struct NonThrowFoo { + NonThrowFoo() = default; + NonThrowFoo(NonThrowFoo&&) noexcept {}; + NonThrowFoo(const NonThrowFoo&) noexcept { + copy = true; + }; + + bool copy = false; + }; + NonThrowFoo foo; + NonThrowFoo foo2 = MoveIfNoExcept(foo); + ASSERT_FALSE(foo2.copy); +} \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/CMakeLists.txt b/module-1/homework/TypeTraits/type_traits/CMakeLists.txt new file mode 100644 index 00000000..55b81fe6 --- /dev/null +++ b/module-1/homework/TypeTraits/type_traits/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +project(runner) + +add_library(type_traits is_copy_constructible.h is_nothrow_move_constructible.h move_if_noexcept.h utility.h) +set_target_properties(type_traits PROPERTIES LINKER_LANGUAGE CXX) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(type_traits) \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/is_copy_constructible.h b/module-1/homework/TypeTraits/type_traits/is_copy_constructible.h new file mode 100644 index 00000000..b02d9f02 --- /dev/null +++ b/module-1/homework/TypeTraits/type_traits/is_copy_constructible.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +#include "utility.h" + +template +struct LibCppIsConstructible; + +template +struct IsInvalidBaseToDerivedCast { + // Your code goes here +}; + +template +struct IsInvalidLvalueToRvalueCast : std::false_type { + // Your code goes here +}; + +template +struct IsInvalidLvalueToRvalueCast { + // Your code goes here +}; + +struct IsConstructibleHelper { + // Your code goes here +}; + +// LibCppIsConstructible - partial specializations +// Your code goes here +// LibCppIsConstructible - partial specializations + +template +struct IsConstructible : // Your code goes here {...} + +template +struct IsCopyConstructible : // Your code goes here {...} \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/is_nothrow_move_constructible.h b/module-1/homework/TypeTraits/type_traits/is_nothrow_move_constructible.h new file mode 100644 index 00000000..bd749521 --- /dev/null +++ b/module-1/homework/TypeTraits/type_traits/is_nothrow_move_constructible.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "is_copy_constructible.h" +#include "utility.h" + +// +template +struct LibCppIsNoThrowConstructible; + +// LibCppIsNoThrowConstructible - partial specializations +// Your code goes here +// LibCppIsNoThrowConstructible - partial specializations + +template +struct IsNoThrowConstructible : // Your code goes here {...} + +template +struct IsNoThrowConstructible : // Your code goes here {...} + +template +struct IsNoThrowMoveConstructible : // Your code goes here {...} \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/move_if_noexcept.h b/module-1/homework/TypeTraits/type_traits/move_if_noexcept.h new file mode 100644 index 00000000..4ce67cec --- /dev/null +++ b/module-1/homework/TypeTraits/type_traits/move_if_noexcept.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + +#include "is_copy_constructible.h" +#include "is_nothrow_move_constructible.h" +#include "utility.h" + +template +struct Conditional { + // Your code goes here +}; + +// Conditional - partial specialization +// Your code goes here +// Conditional - partial specialization + +template +struct Conditional { + using type = T; +}; + +template +using conditional_v = // Your code goes here + +// MoveIfNoExcept +// Your code goes here +// MoveIfNoExcept \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/utility.h b/module-1/homework/TypeTraits/type_traits/utility.h new file mode 100644 index 00000000..1f0dc419 --- /dev/null +++ b/module-1/homework/TypeTraits/type_traits/utility.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +template +struct Uncvref { + // Your code goes here +}; + +template +using uncvref_t = // Your code goes here + +template +struct AddConst { + using type = // Your code goes here +}; + +template +using add_const_t = // Your code goes here + +template +struct AddLvalueReference : // Your code goes here + +template +struct AddRvalueReference : // Your code goes here + +template +using add_lvalue_reference_t = // Your code goes here + +template +using add_rvalue_reference_t = // Your code goes here \ No newline at end of file diff --git a/module-1/homework/Variant/CMakeLists.txt b/module-1/homework/Variant/CMakeLists.txt new file mode 100644 index 00000000..516469b8 --- /dev/null +++ b/module-1/homework/Variant/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.16) + +include(GoogleTest) + +project("runner") + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +################ gtest ################ +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() + +################ Sanitizers ################ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold -fsanitize=undefined,address -fno-sanitize-recover=all -O2 -Wall -Werror -Wsign-compare") + +################ clang-tidy ################ +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-header-filter=.") + +add_executable(runner tests.cpp variant.h) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(runner) + +target_link_libraries(runner LINK_PUBLIC gtest_main) + +add_test(NAME runner_test COMMAND runner) \ No newline at end of file diff --git a/module-1/homework/Variant/CMakeLists.txt.in b/module-1/homework/Variant/CMakeLists.txt.in new file mode 100644 index 00000000..f98ccb4a --- /dev/null +++ b/module-1/homework/Variant/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/module-1/homework/Variant/task.md b/module-1/homework/Variant/task.md new file mode 100644 index 00000000..66180b54 --- /dev/null +++ b/module-1/homework/Variant/task.md @@ -0,0 +1,10 @@ +# Variant + +## Задание + +[`Variant`](https://en.cppreference.com/w/cpp/utility/variant) - обощение типа **union** + +Реализовать функции: +* [`Get`](https://en.cppreference.com/w/cpp/utility/variant/get) - получение значения в `Variant` по индексу +* [`Get`](https://en.cppreference.com/w/cpp/utility/variant/get) - получение значения в `Variant` по типу +* [`operator=`](https://en.cppreference.com/w/cpp/utility/variant/operator%3D) - оператор присваивания значения \ No newline at end of file diff --git a/module-1/homework/Variant/tests.cpp b/module-1/homework/Variant/tests.cpp new file mode 100644 index 00000000..a51fb1d9 --- /dev/null +++ b/module-1/homework/Variant/tests.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include "gtest/gtest.h" +#include "variant.h" + +TEST(Get, Test1) { + task::Variant v; + v = "Hello world"; + ASSERT_EQ(Get(v), "Hello world"); +} + +TEST(Get, Test2) { + task::Variant v; + v = 12.0; + ASSERT_NEAR(Get(v), 12.0, 1e-5); +} + +TEST(Get, Test3) { + task::Variant v; + v = "Hello world"; + ASSERT_EQ(Get<2>(v), "Hello world"); +} + +TEST(Get, Test4) { + task::Variant v; + v = 12.0; + ASSERT_NEAR(Get<1>(v), 12.0, 1e-5); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/module-1/homework/Variant/variant.h b/module-1/homework/Variant/variant.h new file mode 100644 index 00000000..647742e7 --- /dev/null +++ b/module-1/homework/Variant/variant.h @@ -0,0 +1,48 @@ +#include +#include + +#pragma once + +namespace task { + +template +class Variant; + +template +struct VariantAlternative; + +template +using variant_alternative_t = typename VariantAlternative::type; + +template +struct VariantAlternative> { + using type = // Your code goes here +}; + +template +class Variant { +public: + // Special member functions + constexpr Variant() noexcept; + + template + Variant& operator=(T&& t) noexcept; + +private: + // Your code goes here +}; + +// Non-member functions +template +constexpr const variant_alternative_t>& Get(Variant& v); + +template +constexpr variant_alternative_t>&& Get(Variant&& v); + +template +constexpr const T& Get(Variant& v); + +template +constexpr T&& Get(Variant&& v); + +}; // namespace task \ No newline at end of file diff --git a/module-1/lectures/1-course/lecture3.pdf b/module-1/lectures/1-course/lecture3.pdf index 5ce5809a..2f4816be 100644 Binary files a/module-1/lectures/1-course/lecture3.pdf and b/module-1/lectures/1-course/lecture3.pdf differ diff --git a/module-1/lectures/3-course/lecture3.pdf b/module-1/lectures/3-course/lecture3.pdf index fe1466a1..2f4816be 100644 Binary files a/module-1/lectures/3-course/lecture3.pdf and b/module-1/lectures/3-course/lecture3.pdf differ diff --git a/module-1/seminars/seminar15/Allocator/CMakeLists.txt b/module-1/seminars/seminar15/Allocator/CMakeLists.txt new file mode 100644 index 00000000..06a12b9d --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.16) + +include(GoogleTest) + +project("runner") + +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() + +add_executable(runner list.h list.cpp) +target_link_libraries(runner gtest_main) +add_test(NAME runner_test COMMAND runner) \ No newline at end of file diff --git a/module-1/seminars/seminar15/Allocator/CMakeLists.txt.in b/module-1/seminars/seminar15/Allocator/CMakeLists.txt.in new file mode 100644 index 00000000..f98ccb4a --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/module-1/seminars/seminar15/Allocator/allocator/CMakeLists.txt b/module-1/seminars/seminar15/Allocator/allocator/CMakeLists.txt new file mode 100644 index 00000000..44168e93 --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/allocator/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.16) +project("Tutorial") + +add_executable(allocator allocator.cpp allocator.h) \ No newline at end of file diff --git a/module-1/seminars/seminar15/Allocator/allocator/allocator.cpp b/module-1/seminars/seminar15/Allocator/allocator/allocator.cpp new file mode 100644 index 00000000..e93c9668 --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/allocator/allocator.cpp @@ -0,0 +1,72 @@ +#include "allocator.h" + +template +SimpleAllocator::SimpleAllocator() { + arena = ::operator new(2000 * sizeof(T)); +} + +template +SimpleAllocator::SimpleAllocator(const SimpleAllocator& other) noexcept : + arena(other.arena) +{ +} + +template +template +SimpleAllocator::SimpleAllocator(const SimpleAllocator& other) noexcept : + arena(other.arena) +{ +} + +template +SimpleAllocator::~SimpleAllocator() +{ + num_allocators--; + if (num_allocators) { + delete arena; + } +} + + +template +SimpleAllocator SimpleAllocator::select_on_container_copy_construction() const { + return SimpleAllocator(); +} + +template +T* SimpleAllocator::allocate(std::size_t n) { + return ::operator new(n * sizeof(T)); +} + +template +void SimpleAllocator::deallocate(void* p, std::size_t n) { + ::operator delete(p); +} + +template +bool operator==(const SimpleAllocator& lhs, const SimpleAllocator& rhs) noexcept { + return true; +} + +template +bool operator!=(const SimpleAllocator& lhs, const SimpleAllocator& rhs) noexcept { + return true; +} + +template +template +void SimpleAllocator::construct(void* p, Args&&... args) { + // new(p) - это new expression (конкретнее placement new expression), + // который вызывает new operator + + new(p) value_type(std::forward(args)...); +} + +template +void SimpleAllocator::destroy(void* p) { + ::delete(p); +} + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar15/Allocator/allocator/allocator.h b/module-1/seminars/seminar15/Allocator/allocator/allocator.h new file mode 100644 index 00000000..1f9b301a --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/allocator/allocator.h @@ -0,0 +1,46 @@ +#include +#include + +template +class SimpleAllocator { + private: + template + struct rebind { + using other = SimpleAllocator; + }; + + public: + + using value_type = T; + using pointer = T*; + using reference = T&; + using const_pointer = const T*; + using const_reference = const T&; + using size_type = std::size_t; + using pointer_difference = std::ptrdiff_t; + using propagate_on_container_move_assignment = std::false_type; + using propagate_on_container_copy_assignment = std::false_type; + using propogate_on_container_swap = std::false_type; + using is_always_equal = std::false_type; + + SimpleAllocator(); + SimpleAllocator(const SimpleAllocator& other) noexcept; + ~SimpleAllocator(); + + template + SimpleAllocator(const SimpleAllocator& other) noexcept; + + SimpleAllocator select_on_container_copy_construction() const; + + T* allocate(std::size_t n); + // void* allocate(std::size_t n, void* cvp); + void deallocate(void* p, std::size_t n); + // std::size_t max_size() const noexcept; + template + void construct(void* p, Args&&... args); + void destroy(void* p); + + private: + std::size_t num_allocators = 0; + void* arena; +}; \ No newline at end of file diff --git a/module-1/seminars/seminar15/Allocator/list/CMakeLists.txt b/module-1/seminars/seminar15/Allocator/list/CMakeLists.txt new file mode 100644 index 00000000..647a1205 --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/list/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.16) +project("Tutorial") + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_executable(list list.cpp list.h) \ No newline at end of file diff --git a/module-1/seminars/seminar15/Allocator/list/list.cpp b/module-1/seminars/seminar15/Allocator/list/list.cpp new file mode 100644 index 00000000..321dc5af --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/list/list.cpp @@ -0,0 +1,223 @@ +#include "list.h" + +// Special member functions +template +task::list::list() : + head(alloc.allocate(1)), + tail(alloc.allocate(1)) +{ + alloc.construct(head); + alloc.construct(tail); + head->next = tail; + tail->prev = head; +} + +template +task::list::list(const task::list& other) : + alloc(std::allocator_traits<__node_allocator>::select_on_container_copy_construction(other.alloc)), + head(alloc.allocate(1)), + tail(alloc.allocate(1)) +{ + alloc.construct(head); + alloc.construct(tail); + head->next = tail; + tail->prev = head; + +} + +template +task::list::list(const task::list& other, const Allocator& alloc) : + alloc(alloc), + head(alloc.allocate(1)), + tail(alloc.allocate(1)) +{ + alloc.construct(head); + alloc.construct(tail); + head->next = tail; + tail->prev = head; +} + +template +task::list::list(list&& other) : + // тут сценарии + // 1. вызывается user-defined(нами опеределенный) move constructor decltype(alloc) + // 2. вызывается move constructor decltype(alloc) + // 3. вызывается copy constructor decltype(alloc) т.к. const lvalue-ref может быть проиницализирована с rvalue expression + alloc(std::move(other.alloc)), + head(other.head), + tail(other.tail) +{ + other.head = nullptr; + other.tail = nullptr; +} + +template +task::list::list(list&& other, const Allocator& alloc) : + alloc(alloc), + head(other.head), + tail(other.tail) +{ + other.head = nullptr; + other.tail = nullptr; +} + +template +task::list::~list() { + alloc.destroy(head); + alloc.deallocate(head, 1); + alloc.destroy(tail); + alloc.deallocate(tail, 1); +} + +template +void assign(typename task::list::iterator left, typename task::list::iterator right) +{ + for (auto it = left; it != right; it++) { + push_back(*it); + } +} + +template +void task::list::clear() +{ + while(!empty()) { + pop_back(); + } +} + +template +task::list& task::list::operator=(const list& other) { + if (this == &other) { + return *this; + } + + if (std::allocator_traits::propagete_on_container_copy_assignment::value()) { + if (alloc != other.alloc) { + clear(); + } + alloc = other.alloc; + assign(other.begin(), other.end()); + } + return *this; +} + +template +task::list& task::list::operator=(list&& other) noexcept { + + clear(); + if (std::allocator_traits::propagete_on_container_move_assignment::value()) { + alloc = std::move(other.alloc); + head = other.head; + tail = other.tail; + other.head = nullptr; + other.tail = nullptr; + } else if (__node_allocator::is_always_equal::value() == std::true_type() || alloc == other.alloc()) { + head = other.head; + tail = other.tail; + other.head = nullptr; + other.tail = nullptr; + } else { + for (auto it = other.begin(); it != other.end(); it++) { + push_back(std::move(*it)); + } + } + + return *this; +} + +template +void task::list::push_back(const T& value) +{ + Node* p = static_cast(alloc.allocate(1)); + // Передаем value в construct -> вызываем copy constructor Node + alloc.construct(p, value); + p->next = tail; + p->prev = tail->prev; + tail->prev->next = p; + tail->prev = p; + size_++; +} + +template +void task::list::push_back(T&& value) +{ + Node* p = static_cast(alloc.allocate(1)); + // forward т.к. надо передать reference collapsing на место аругмента + // move сделал бы все expressions вида xvalue expression + alloc.construct(p, std::forward(value)); + p->next = tail; + p->prev = tail->prev; + tail->prev->next = p; + tail->prev = p; + size_++; +} + +template +template +void task::list::emplace_back(Args&&... args) +{ + Node* p = static_cast(alloc.allocate(1)); + alloc.construct(p, std::forward(args)...); + p->next = tail; + p->prev = tail->prev; + tail->prev->next = p; + tail->prev = p; + size_++; +} + +template +void task::list::pop_back() +{ + Node* p = tail->prev; + tail->prev->next = tail; + tail->prev = p->prev; + alloc.destroy(p); + alloc.deallocate(p, 1); + size_--; +} + +template +typename task::list::allocator_type task::list::get_allocator() const noexcept { + return allocator_type(alloc); +} + +// Modifiers +template +void task::list::swap(list& other) noexcept +{ + // использовал decltype, чтобы не писать __node_allocator + if (!std::allocator_traits::propogate_on_container_swap::value && get_allocator() != other.get_allocator()) { + std::exit(0); + } + // стандарт запрещает делать swap на элементах контейнера + // но head, tail - это хелперы, требования на них не распространяются + utility::__swap_allocator(alloc, other.alloc); + std::swap(head, other.head); + std::swap(tail, other.tail); +} + +template +typename task::list::iterator task::list::begin() noexcept { + return iterator(head->next); +} + +template +typename task::list::iterator task::list::end() noexcept { + return iterator(tail); +} + +// Capacity +template +bool task::list::empty() const noexcept { + return size_ == 0; +} + +template +typename task::list::size_type task::list::size() const noexcept { + return size_; +} + +int main() { + task::list lst; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar15/Allocator/list/list.h b/module-1/seminars/seminar15/Allocator/list/list.h new file mode 100644 index 00000000..d7527952 --- /dev/null +++ b/module-1/seminars/seminar15/Allocator/list/list.h @@ -0,0 +1,160 @@ +#pragma once + +#include +#include + +#include "../allocator/allocator.h" + +namespace utility { + //https://github.com/llvm-mirror/libcxx/blob/master/include/memory + template + void __swap_allocator(Allocator& lhs, Allocator& rhs) { + __swap_allocator(lhs, rhs, std::integral_constant::propagate_on_container_swap::value>()); + } + + template + void __swap_allocator(Allocator& lhs, Allocator& rhs, std::true_type) { + std::swap(lhs, rhs); + } + + template + void __swap_allocator(Allocator& lhs, Allocator& rhs, std::false_type) {} +}; + +namespace task { + +template> +class list { + +private: + class iterator; + +public: + + using value_type = T; + using allocator_type = Allocator; + using size_type = std::size_t; + using reference = value_type&; + using const_reference = const value_type&; + using pointer = typename std::allocator_traits::pointer; + using const_pointer = typename std::allocator_traits::const_pointer; + using iterator = iterator; + using const_iterator = const iterator; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterat = std::reverse_iterator; + + // Special member functions + list(); + // explicit list( const Allocator& alloc ); + // list(size_type count, const T& value, const Allocator& alloc = Allocator()); + // explicit list( size_type count, const Allocator& alloc = Allocator() ); + + list(const list& other); + list(const list& other, const Allocator& alloc); + + list(list&& other); + list(list&& other, const Allocator& alloc); + + ~list(); + + list& operator=(const list& other); + list& operator=(list&& other) noexcept; + + // // Element access + // reference front(); + // const reference front() const; + + // reference back(); + // const reference back() const; + + // // Iterators + iterator begin() noexcept; + // const_iterator begin() const noexcept; + + iterator end() noexcept; + // const_iterator end() noexcept; + + // // Capacity + bool empty() const noexcept; + size_type size() const noexcept; + // size_type max_size() const noexcept; + + // // Modifiers + void clear(); + void swap(list& other) noexcept; + + void push_back(const T& value); + void push_back(T&& value); + + template + void emplace_back(Args&&... args); + void pop_back(); + // void push_front(const T& value); + // void pop_front(); + // void resize(size_t count); + + // // Operations + // void remove(const T& value); + // void unique(); + // void sort(); + + allocator_type get_allocator() const noexcept; + +private: + void assign(iterator left, iterator right); + +private: + struct Node { + value_type value; + Node* next = nullptr; + Node* prev = nullptr; + + Node() = default; + + Node(value_type _value, Node* _next, Node* _prev) : + value(_value), + next(_next), + prev(_prev) + {} + + }; + + class iterator { + public: + iterator& operator++() { + ptr = ptr->next; + return *this; + } + + iterator operator++(int) { + iterator copy(*this); + operator++(); + return copy; + } + + iterator& operator--() { + ptr = ptr->prev; + return *this; + } + + iterator operator--(int) { + iterator copy(*this); + operator--(); + return copy; + } + + private: + Node* ptr = nullptr; + }; + +private: + typedef typename std::allocator_traits::template rebind_alloc __node_allocator; + +private: + __node_allocator alloc; + Node* head = nullptr; + Node* tail = nullptr; + size_type size_ = 0; +}; + +} \ No newline at end of file diff --git a/module-1/seminars/seminar16/unique_ptr/CMakeLists.txt b/module-1/seminars/seminar16/unique_ptr/CMakeLists.txt new file mode 100644 index 00000000..778b196c --- /dev/null +++ b/module-1/seminars/seminar16/unique_ptr/CMakeLists.txt @@ -0,0 +1,8 @@ +# ставим нижнее ограничение на версию cmake для сборки проекта +cmake_minimum_required(VERSION 3.16) + +# именуем проект: значение сохраняется в переменную PROJECT_NAME +project("lecture15") + +# создаем исполняемый target +add_executable(unique_ptr unique_ptr.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar16/unique_ptr/unique_ptr.cpp b/module-1/seminars/seminar16/unique_ptr/unique_ptr.cpp new file mode 100644 index 00000000..3c9b255f --- /dev/null +++ b/module-1/seminars/seminar16/unique_ptr/unique_ptr.cpp @@ -0,0 +1,153 @@ +#include +#include +#include +#include +#include + +// auto_ptr depreceted +void seg_fault() { + std::auto_ptr w1(new int(1)); + // делегировали содержимое w2 w1 + std::auto_ptr w2 = w1; + std::cout << *w1; +} + +// problem->solution +template +void problem() { + T* ptr = new T; + // ... + delete ptr; +} + +template +void solution(T) { + class unique_ptr { + public: + + ~unique_ptr() { + delete p; + } + + private: + T* p = nullptr; + }; +} + +// unique_move only +void copy_construct_error() { + std::unique_ptr u1(new int(1)); + // CE: + // std::unique_ptr u2(u1); +} + +void move_construct() { + std::unique_ptr u1(new int(1)); + std::unique_ptr u2(std::move(u1)); +} + +// std::unique_ptr has partial specualization for arrays +// it is semantically equal for new[] expression +void unique_partial() { + class container {}; + + std::unique_ptr u(new container[3]); + container* raw_p = new container[3]; +} + +// unique_has template parameter +void deleter() { + struct FileCloser { + void operator()(FILE* fp) const { + assert(fp != nullptr); + fclose(fp); + } + }; + // we don't worry about descriptor releasing + std::unique_ptr u(fopen("C:\\tmp.txt","w")); +} + +// Shared_ptr and simple_ref counting +void simple_ref_counting() { + struct Widget { + std::atomic usecount_{1}; + Widget* acquire() { + ++usecount_; + return this; + } + void release() { + if (--usecount_ == 0) { + delete this; + } + } + }; + + Widget* p = new Widget; + Widget* q = p->acquire(); + p->release(); + q->release(); // calls delete here + + // Problem: we call acquire, release explicitly, but shared_ptr automates these process +} + +// Solution: shared_ptr stores ptr to controll block. Control block increments ref_counts +void advanced_ref_counting() { + struct control_block { + std::size_t num_refs = 0; + }; + + struct my_shared_ptr { + + my_shared_ptr(int* p) : data(p) { + control_ptr = new control_block; + }; + my_shared_ptr(const my_shared_ptr& other) : + data(other.data), + control_ptr(other.control_ptr) + { + control_ptr->num_refs += 1; + } + + ~my_shared_ptr() { + control_ptr->num_refs -= 1; + if (control_ptr->num_refs == 0) { + delete data; + delete control_ptr; + } + } + + int* data; + control_block* control_ptr; + }; + + my_shared_ptr p1(new int(1)); + my_shared_ptr p2(p1); + std::cout << p2.control_ptr->num_refs; +} + +// Problem: raw new, delete +// make_shared, make_unique to the rescue! + +void evolution_of_consciousness() { + class Widget {}; + // Step1 + // explicit delete, explicit new + auto* w1 = new Widget; + delete w1; + + // Step2 + // no delete, but explicit new + std::shared_ptr w2(new Widget()); + + // Step3 + // no delete, no explicit new + auto w3 = std::make_shared(); + + +} + +// my_make_shared +template +std::shared_ptr my_make_shared(Args&&... args) { + return std::shared_ptr(new T(std::forward(args)...)); +} \ No newline at end of file diff --git a/module-1/seminars/seminar16/variant/CMakeLists.txt b/module-1/seminars/seminar16/variant/CMakeLists.txt new file mode 100644 index 00000000..0a4bafcf --- /dev/null +++ b/module-1/seminars/seminar16/variant/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +project("runner") + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_executable(variant variant.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar16/variant/__union_assignment.cpp b/module-1/seminars/seminar16/variant/__union_assignment.cpp new file mode 100644 index 00000000..de75b91e --- /dev/null +++ b/module-1/seminars/seminar16/variant/__union_assignment.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +template struct in_place_index_t { + explicit in_place_index_t() = default; +}; + +template +constexpr in_place_index_t in_place_index{}; + + +template +union __union; + +template +union __union<_Index> {}; + +template +union __union<_Index, T, _Types...> { + public: + template + void assign_helper(U&& value, in_place_index_t<0>, __union& u) { + u.head = value; + } + + template + void assign_helper(U&& value, in_place_index_t, __union& u) { + assign_helper(std::forward(value), in_place_index, u.tail); + } + + template + void assign(U&& value) { + assign_helper(std::forward(value), in_place_index, *this); + } + + T head; + __union<_Index + 1, _Types...> tail; + +}; +int main() { + __union<0, const char*, int, float> u; + u.assign<1>(1.2); + std::cout << u.tail.head; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar16/variant/find_exactly_one.cpp b/module-1/seminars/seminar16/variant/find_exactly_one.cpp new file mode 100644 index 00000000..bc248247 --- /dev/null +++ b/module-1/seminars/seminar16/variant/find_exactly_one.cpp @@ -0,0 +1,99 @@ + +// find_exactly_one_checked +// 1. пройтись по набору типов +// 2. там где совпал поставить 1 +// 3. пройтись по полученному набору 0 и 1 +// 4. если встретили 0 => идем дальше +// если встретили 1 и one_found = 0 => взводим флаг one_found = 1 и идем дальше +// если встретили 1 и one_found = 1 => возвращаем флаг ambiguity = -2 (что означет найдены повторы) + +// const static int not_founded = - 1; +// const static int ambiguity = not_founded - 1; + +// constexpr std::size_t simplified_condition(std::size_t i, std::size_t res, bool founded_value) { +// return (!founded_value) ? res : ((res == not_founded) ? i : ambiguity); +// } + +// template +// constexpr std::size_t __check_dublicates__(std::size_t cur_pos, const bool (&founded)[SizeofFounded]) { +// // условия: +// // если мы вышли за founded => по умолчанию считаем, что не нашли 1-ц=> возвращаем not_founded (1) +// // если в границах founded => возвращаем результат вызова из хвоста founded (2) +// // ниже condition (мы вышли за founded) ? (1) : (2) +// // (2). __check_dublicates__(cur_pos + 1, founded) - идем дальше по founded в хвост +// // перед вызовом simplified_condition мы обладаем значением __check_dublicates__(cur_pos + 1, founded) +// // т.е. проходим вглубь по __check_dublicates__ и возвращаем результат в simplified_condition +// return (cur_pos == SizeofFounded) ? not_founded : simplified_condition(cur_pos, __check_dublicates__(cur_pos + 1, founded), founded[cur_pos]); +// } + +// // в момент __check_dublicates__(cur_pos + 1, founded) возможные значения результата +// // not_founded : единицы не найдены в хвосте => т.е. хвост из 0 +// // founded_exaclty_one : единица найдена в хвосте и она единаственна +// // ambiguity : в хвосте несколько единиц +// // +// // Действие на основе значения: +// // not_founded : если founded[i] == 1 => пробрасываем founded_exaclty_one +// // : если founded[i] == 0 => пробрасываем not_founded +// // founded_exaclty_one : если founded[i] == 1 => пробрасываем ambiguity (т.к. сейчас 1 (по i позиции) и в хвосте 1-ца) +// // : если founded[i] == 0 => пробрасываем founded_exaclty_one (т.к. сейчас 0 (по i позиции) и в хвосте 1-ца) +// // ambiguity: продолжаем пробрасывать 1 + +// // Заметим, что при условии founded[i] == 0 пробрасывается возвращаемое значение +// // not_founded -> not_founded +// // founded_exaclty_one -> founded_exaclty_one +// // ambiguity -> ambiguity +// // тогда пишем +// // (!founded[i]) ? tail_has_ones : <тут остальные проверки> +// // +// // Заметим, что founded[i] == 1 пробрасывается: +// // not_founded -> founded_exaclty_one +// // founded_exaclty_one -> ambiguity +// // ambiguity -> ambiguity +// // тогда смотрим если пришел not_founded, то пробрасываем founded_exaclty_one, иначе пробрасывается ambiguity +// // +// // итог: (!founded[i]) ? tail_has_ones : (tail_has_ones == not_founded) ? founded_exaclty_one : ambiguity +// // получаем +// // +// // (!founded[i]) ? __check_dublicates__(cur_pos + 1, founded) : (__check_dublicates__(cur_pos + 1, founded) == not_founded) ? founded_exaclty_one : ambiguity +// // +// // но читать такое сложно!! +// // давайте данынй condition вынесем в отдельную функцию, а значения __check_dublicates__(cur_pos + 1, founded) будем туда передавать +// // +// // simplified_condition +// // std::size_t simplified_condition(std::size_t i, std::size_t res, bool founded_val) { +// // return (!founded_val) ? res : (res == not_founded) ? founded_exaclty_one : ambiguity; +// // } +// // вот founded_exaclty_one мы отдельно явно заводить не будем, под founded_exaclty_one мы продолжим пробрасывать текущий индекс понимая, что +// // семантически это founded_exaclty_one +// // +// // приходим к +// // +// // std::size_t simplified_condition(std::size_t i, std::size_t res, bool founded_val) { +// // return (!founded_val) ? res : (res == not_founded) ? i : ambiguity; +// // } + +// template +// struct _find_exactly_one_checked_ { +// // 1. пройтись по набору типов +// // 2. там где совпал поставить 1 +// constexpr static bool founded[sizeof...(Types)] = {std::is_same::value...}; +// // 3. пройтись по полученному набору 0 и 1 +// constexpr static std::size_t value = __check_dublicates__(0, founded); +// static_assert(value != not_founded, "type not found in type list" ); +// static_assert(value != ambiguity, "type occurs more than once in type list"); +// }; + +// template +// struct _find_exactly_one_checked_ { +// static_assert(!std::is_same::value, "type not in empty type list"); +// }; + +// template +// struct _find_exactly_one_t : public _find_exactly_one_checked_ { + +// }; + + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar16/variant/variant.cpp b/module-1/seminars/seminar16/variant/variant.cpp new file mode 100644 index 00000000..09f8fcdf --- /dev/null +++ b/module-1/seminars/seminar16/variant/variant.cpp @@ -0,0 +1,196 @@ +#include +#include +#include + +//----------------Helper structures---------------- + +template struct in_place_index_t { + explicit in_place_index_t() = default; +}; + +template +constexpr in_place_index_t in_place_index{}; + + +template +union __union; + +template +union __union<_Index> {}; + +template +union __union<_Index, T, _Types...> { + public: + + T head; + __union<_Index + 1, _Types...> tail; + + friend struct __access_union; +}; + +struct __assign_union { + template + static void assign_helper(U&& value, in_place_index_t<0>, __union& u) { + u.head = value; + } + + template + static void assign_helper(U&& value, in_place_index_t, __union& u) { + assign_helper(std::forward(value), in_place_index, u.tail); + } +}; + +struct __access_union { + template + static constexpr auto&& __get_alt(U&& __v, in_place_index_t<0>) { + return std::forward(__v).__head; + } + + + template + static constexpr auto&& __get_alt(U&& __v, in_place_index_t) { + // Логика __get_alt: выдать Idx шагов -> идти вправо по tail-> шаг сделан -> Idx - 1 -> на Idx=0 проверить есть ли head + return __get_alt(std::forward(__v).__tail, in_place_index); + } +}; + +struct __my_variant { + template + static constexpr auto&& __get_alt(T&& __v) { + return __access_union::__get_alt(std::forward(__v).__data, in_place_index); + } +}; +//----------------Helper structures---------------- + + +//----------------_find_exactly_one_t---------------- +const static int not_founded = - 1; +const static int ambiguity = not_founded - 1; + +constexpr std::size_t simplified_condition(std::size_t i, std::size_t res, bool founded_value) { + return (!founded_value) ? res : ((res == not_founded) ? i : ambiguity); +} + +template +constexpr std::size_t __check_dublicates__(std::size_t cur_pos, const bool (&founded)[SizeofFounded]) { + return (cur_pos == SizeofFounded) ? not_founded : simplified_condition(cur_pos, __check_dublicates__(cur_pos + 1, founded), founded[cur_pos]); +} + +template +struct _find_exactly_one_checked_ { + constexpr static bool founded[sizeof...(Types)] = {std::is_same::value...}; + constexpr static std::size_t value = __check_dublicates__(0, founded); + // static_assert(value != not_founded, "type not found in type list" ); + // static_assert(value != ambiguity, "type occurs more than once in type list"); +}; + +template +struct _find_exactly_one_checked_ { + static_assert(!std::is_same::value, "type not in empty type list"); +}; + +template +struct _find_exactly_one_t : public _find_exactly_one_checked_ {}; +//----------------_find_exactly_one_t---------------- + + +//----------------My variant---------------- +template +class my_variant { + + public: + __union<0, Types...> __data; + + public: + + my_variant() = default; + my_variant(Types... args) {}; + my_variant& operator=(const my_variant& other) { return *this; } + template::value> + my_variant& operator=(T&& value) { + __assign_union::assign_helper(std::forward(value), in_place_index, __data); + + return *this; + } + + private: + friend __my_variant; + +}; +//----------------My variant---------------- + + +//----------------Variant alternative---------------- +template +struct Typelist{ + typedef head Head; + typedef Typelist Tail; +}; + +template struct TypeAt; + +template +struct TypeAt<0, Typelist> { + typedef Head Result; +}; +template +struct TypeAt> { + typedef typename TypeAt>::Result Result; +}; + +template +struct variant_alternative; + +template +struct variant_alternative> { + // my_variant_alternative_t> - это упаковать Types... в TypeList / tuple и применить TypeAt + using type = typename TypeAt>::Result; +}; +template +using my_variant_alternative_t = typename variant_alternative::type; +//----------------Variant alternative---------------- + +//----------------Getters---------------- +template +auto&& generic_get(T&& v) { + // __my_variant друг my_variant => _my_variant может обратиться к полям my_variant + // друг может обратиться к полям my_variant + return __my_variant::__get_alt(std::forward(v))._value; +} + +template +my_variant_alternative_t>& get(my_variant& v) { + return generic_get(v); +} + +template +T& get(my_variant& v) { + std::cout << "get"; + const auto x = _find_exactly_one_t::value; + int y = 3; + return y; +} + +template +T&& get(my_variant&& v) { + return get<_find_exactly_one_t::value>(std::move(v)); +} +//----------------Getters---------------- + +int main() { + // План: + // 1. Разименовали строчку, добавили необходимый функционал (максимально общий / generic) + + // Нужен union с произвольным числом типов + // Реш: TypeList to the rescue! см __uinion + my_variant v, w; + // // нужен operator=, с правым операндом любого типа + // // Реш: добавляем operator=, принимающий по universal reference (converting assignment) + v = 1000; + + std::cout << v.__data.tail.head; + + // get: Segfault + //int i = get(v); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar17/CMakeLists.txt b/module-1/seminars/seminar17/CMakeLists.txt new file mode 100644 index 00000000..72b8cb67 --- /dev/null +++ b/module-1/seminars/seminar17/CMakeLists.txt @@ -0,0 +1,8 @@ +# ставим нижнее ограничение на версию cmake для сборки проекта +cmake_minimum_required(VERSION 3.16) + +# именуем проект: значение сохраняется в переменную PROJECT_NAME +project("seminar17") + +# включаем файлы в поддиректория в сборку проекта +add_executable(grim grim.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar17/grim.cpp b/module-1/seminars/seminar17/grim.cpp new file mode 100644 index 00000000..dcb93d44 --- /dev/null +++ b/module-1/seminars/seminar17/grim.cpp @@ -0,0 +1,153 @@ +#include +#include +#include +#include + +// weak_ptr +void weak_ptr_break_cycles() { + struct Son; + struct Daughter; + + struct Mother { + ~Mother() { + std::cout << "Mother gone" << std::endl; + } + + void setSon(const std::shared_ptr s) { + mySon = s; + } + + void setDaughter(const std::shared_ptr d) { + myDaughter = d; + } + + std::shared_ptr mySon; + std::weak_ptr myDaughter; + }; + + struct Son { + Son(std::shared_ptr m) : myMother(m) {} + ~Son() { + std::cout << "Som gone" << std::endl; + } + + std::shared_ptr myMother; + }; + + struct Daughter { + Daughter(std::shared_ptr m) : myMother(m) {} + ~Daughter() { + std::cout << "Daughter gone" << std::endl; + } + + std::shared_ptr myMother; + }; + + { + std::shared_ptr mother = std::shared_ptr(new Mother); + std::shared_ptr son = std::shared_ptr(new Son(mother)); + std::shared_ptr daughter = std::shared_ptr(new Daughter(mother)); + + mother->setSon(son); + mother->setDaughter(daughter); + } +} + +void weak_ptr_lock_logic() { + auto shared_ptr = std::make_shared(2011); + std::weak_ptr weak_ptr(shared_ptr); + + if (std::shared_ptr shared_from_weak = weak_ptr.lock()) { + std::cout << "use_count_A:" << shared_from_weak.use_count() << std::endl; + } else { + std::cout << "Empty_A!" << std::endl; + } + + weak_ptr.reset(); + if (std::shared_ptr shared_from_weak = weak_ptr.lock()) { + std::cout << "use_count_B:" << shared_from_weak.use_count() << std::endl; + } else { + std::cout << "Empty_B!" << std::endl; + } +} + +//p.19 +void perfomance() { + auto start = std::chrono::system_clock::now(); + for (long long i = 0; i < 100000000; i++) { + // Case1: + //int* tmp(new int(i)); + //delete tmp; + + // Case2: + //std::unique_ptr tmp(new int(i)); + // Case3: + //std::unique_ptr tmp = std::make_unique(i); + // Case4: + //std::shared_ptr tmp(new int(i)); + // Case5: + std::shared_ptr tmp = std::make_shared(i); + } + + auto end = std::chrono::system_clock::now(); + std::chrono::duration diff = end-start; + std::cout << diff.count(); +} + +// Ownership semantic part 1 +class container {}; + +void func(container cont) { + // 1. Independent owner of the resource + // 2. Deletes at the end of the scope +} + +void func(container* cont) { + // 1. Borrows resources + // 2. The resource could BE empty + // 3. May delete resource +} + +void func(container& cont) { + // 1. Borrows resources + // 2. The resource could NOT NE empty + // 3. Can not delete the resource +} + +void func(std::unique_ptr cont) { + // 1. Independent owner of the resource + // 2. Deletes at the end of the scope +} + +void func(std::shared_ptr cont) { + // 1. Borrow resource + // 2. The resource could BE empty + // 3. May delete resource at the end of the scope +} + +// Ownership semantic part 2 +void func(std::unique_ptr p) { + // func takes ownership +} + +void func(std::unique_ptr& p) { + // func may reset resource +} + +void func(std::shared_ptr p) { + // func shares ownership +} + +void func(std::shared_ptr& p) { + // func may reset reource +} + +void func(const std::shared_ptr& p) { + // func may retain a reference counter +} + + +int main() { + perfomance(); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/.gitignore b/module-1/seminars/seminar18/.gitignore new file mode 100644 index 00000000..c795b054 --- /dev/null +++ b/module-1/seminars/seminar18/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/module-1/seminars/seminar18/decltype/1.cpp b/module-1/seminars/seminar18/decltype/1.cpp new file mode 100644 index 00000000..4cee1257 --- /dev/null +++ b/module-1/seminars/seminar18/decltype/1.cpp @@ -0,0 +1,19 @@ +#include + +// args is visible in function scope => we can pass args to T (1) +struct D { + template + static void foo(Args&&... args) { + decltype(T(std::forward(args)...)) x; + } +}; + +struct Base { + template + Base(Args...) {}; +}; + +int main() { + D::foo(1, 2, 3); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/decltype/2.cpp b/module-1/seminars/seminar18/decltype/2.cpp new file mode 100644 index 00000000..1a6f470f --- /dev/null +++ b/module-1/seminars/seminar18/decltype/2.cpp @@ -0,0 +1,18 @@ +#include +// args is not visible in function scope => we can not pass args to T +// but we NEED to call T with Args +// Solution: declval to the rescue +struct D { + template(args)...))> + static void foo(Args&&... args) {} +}; + +struct Base { + template + Base(Args...) {}; +}; + +int main() { + D::foo(1, 2, 3); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/decltype/3.cpp b/module-1/seminars/seminar18/decltype/3.cpp new file mode 100644 index 00000000..147837f4 --- /dev/null +++ b/module-1/seminars/seminar18/decltype/3.cpp @@ -0,0 +1,22 @@ +#include + +// args is not visible in function scope => we can not pass args to T +// but we NEED to call T with Args +// Solution: declval to the rescue +struct D { + template()...))> + static void foo(Args&&...) { + decltype(T(std::declval()...)) x; + x = 3; + } +}; + +struct Base { + template + Base(Args...) {}; +}; + +int main() { + D::foo(1, 2, 3); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/decltype/CMakeLists.txt b/module-1/seminars/seminar18/decltype/CMakeLists.txt new file mode 100644 index 00000000..db05b5d1 --- /dev/null +++ b/module-1/seminars/seminar18/decltype/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner 3.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar18/decltype/inspect_value_category.cpp b/module-1/seminars/seminar18/decltype/inspect_value_category.cpp new file mode 100644 index 00000000..f7eb3af9 --- /dev/null +++ b/module-1/seminars/seminar18/decltype/inspect_value_category.cpp @@ -0,0 +1,12 @@ +#include +#include + +int main() { + // 1. put identifer (id-expression) into paranthesis + // 2. apply decltype to paranthesised id-exp + // 3. print std::is_same + int* p = new int(1); + std::cout << std::is_same::value; + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/is_constructible/CMakeLists.txt b/module-1/seminars/seminar18/is_constructible/CMakeLists.txt new file mode 100644 index 00000000..5f0c1edb --- /dev/null +++ b/module-1/seminars/seminar18/is_constructible/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner delete.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar18/is_constructible/default.cpp b/module-1/seminars/seminar18/is_constructible/default.cpp new file mode 100644 index 00000000..901f9c59 --- /dev/null +++ b/module-1/seminars/seminar18/is_constructible/default.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include + + +struct B { + B() = default; +}; + +struct D { + + template()...))> + static std::true_type foo(int); + + template + static std::false_type foo(...); +}; + + +int main() { + using v = decltype(D::foo(0)); + std::cout << v::value; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/is_constructible/delete.cpp b/module-1/seminars/seminar18/is_constructible/delete.cpp new file mode 100644 index 00000000..e1be0888 --- /dev/null +++ b/module-1/seminars/seminar18/is_constructible/delete.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include + + +struct B { + B() = delete; +}; + +struct D { + + template()...))> + static std::true_type foo(int); + + template + static std::false_type foo(...); +}; + + +int main() { + using v = decltype(D::foo(0)); + std::cout << v::value; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/CMakeLists.txt b/module-1/seminars/seminar18/lambdas/CMakeLists.txt new file mode 100644 index 00000000..2009b344 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner runner.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/capturing_by_&=13_1.cpp b/module-1/seminars/seminar18/lambdas/capturing_by_&=13_1.cpp new file mode 100644 index 00000000..dee6dac9 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/capturing_by_&=13_1.cpp @@ -0,0 +1,21 @@ +#include +#include + +void foo() { + + std::string title("hello"); + auto has_title_t = [&]() { + std::cout << "lam1:" << title << std::endl; + // Explanation: [&] - means get all needed data by reference to the scope => assignment to outer title + // [=] - captur by const + copy => CE on assignment + title = "world"; + std::cout << "lam2:" << title << std::endl; + return true; + }; + has_title_t(); + std::cout << "title:" << title << std::endl; +} +int main() { + foo(); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/capturing_by_move_12.cpp b/module-1/seminars/seminar18/lambdas/capturing_by_move_12.cpp new file mode 100644 index 00000000..d2dfa007 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/capturing_by_move_12.cpp @@ -0,0 +1,16 @@ +#include +#include + +void foo() { + + std::string title("hello"); + auto has_title_t = [t = std::move(title)]() { + return true; + }; + std::cout << "title:" << title << std::endl; +} + +int main() { + foo(); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/capturing_reference_11.cpp b/module-1/seminars/seminar18/lambdas/capturing_reference_11.cpp new file mode 100644 index 00000000..b1ef5451 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/capturing_reference_11.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +class Book { + public: + Book(std::string&& _title) : title(std::move(_title)) {} + std::string get_title() const { return title; } + + private: + std::string title; +}; + +bool contains_title(const std::vector& v, std::string title) { + // Explanation: equavalent to auto& t = title; + // be careful: if title is a local <=> on the stack -> returning the has_title you get a dangling reference t + // (title is destroyed, t refs to title ) + auto has_title = [&t = title](const Book& b) { + return b.get_title() == t; + }; + + return std::find_if(v.begin(), v.end(), has_title) != v.end(); +} + +// stack +// title -> 1 +// [has_title, a $ 1_object] t -> title + +// heap +// 1: "the lliad" + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/contains_title_copy_9.cpp b/module-1/seminars/seminar18/lambdas/contains_title_copy_9.cpp new file mode 100644 index 00000000..bfc35d7e --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/contains_title_copy_9.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +class Book { + public: + Book(std::string&& _title) : title(std::move(_title)) {} + std::string get_title() const { return title; } + + private: + std::string title; +}; + + +bool contains_title(const std::vector& v, std::string title) { + // Explanation: copy constructor call + // <=> auto t = title; + auto has_title = [t = title](const Book& b) { + return b.get_title() == t; + }; + + return std::find_if(v.begin(), v.end(), has_title) != v.end(); +} + +// stack +// title -> 1 +// [has_title, a $ 1_object] t -> 2 + +// heap +// 1: "the lliad" +// 2: "the lliad" +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/contains_title_pointer_10.cpp b/module-1/seminars/seminar18/lambdas/contains_title_pointer_10.cpp new file mode 100644 index 00000000..fbef6d11 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/contains_title_pointer_10.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +class Book { + public: + Book(std::string&& _title) : title(std::move(_title)) {} + std::string get_title() const { return title; } + + private: + std::string title; +}; + +bool contains_title(const std::vector& v, std::string title) { + // Explanation: equals auto pt = &title; + auto has_title = [pt = &title](const Book& b) { + return b.get_title() == *pt; + }; + + return std::find_if(v.begin(), v.end(), has_title) != v.end(); +} + +// stack +// title -> 1 +// [has_title, a $ 1_object] pt -> title + +// heap +// 1: "the lliad" + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/lambdas_reduce_boilerplate_7.cpp b/module-1/seminars/seminar18/lambdas/lambdas_reduce_boilerplate_7.cpp new file mode 100644 index 00000000..4cdbcb52 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/lambdas_reduce_boilerplate_7.cpp @@ -0,0 +1,44 @@ +class Plus { + int value; + public: + Plus(int v); + + int operator() (int x) const { + return x + value; + } +}; + +// Plus::operator()(int) const: # @Plus::operator()(int) const +// push rbp +// mov rbp, rsp +// mov qword ptr [rbp - 8], rdi +// mov dword ptr [rbp - 12], esi +// mov rax, qword ptr [rbp - 8] +// mov ecx, dword ptr [rbp - 12] +// add ecx, dword ptr [rax] +// mov eax, ecx +// pop rbp +// ret + +// Explanation: +// 1. reduce boilerplate +// 2. implementaion is same as call operator (operator()) + +auto plus = [value=1](int x) {return x + value;}; + +// $_0::operator()(int) const: # @"$_0::operator()(int) const" +// push rbp +// mov rbp, rsp +// mov qword ptr [rbp - 8], rdi +// mov dword ptr [rbp - 12], esi +// mov rax, qword ptr [rbp - 8] +// mov ecx, dword ptr [rbp - 12] +// add ecx, dword ptr [rax] +// mov eax, ecx +// pop rbp +// ret +// plus: +int main() { + plus(42); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/member_function_4.cpp b/module-1/seminars/seminar18/lambdas/member_function_4.cpp new file mode 100644 index 00000000..3e3bf1cd --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/member_function_4.cpp @@ -0,0 +1,46 @@ +class Plus { + int value; + public: + Plus(int v); + + int plusme(int x) const { + return x + value; + } +}; + + +// main: # @main +// push rbp +// mov rbp, rsp +// sub rsp, 16 +// mov dword ptr [rbp - 4], 0 +// lea rdi, [rbp - 8] +// mov esi, 1 +// call Plus::Plus(int) +// lea rdi, [rbp - 8] +// mov esi, 1 +// call Plus::plusme(int) const +// xor ecx, ecx +// mov dword ptr [rbp - 12], eax # 4-byte Spill +// mov eax, ecx +// add rsp, 16 +// pop rbp +// ret +// Plus::plusme(int) const: # @Plus::plusme(int) const +// push rbp +// mov rbp, rsp +// mov qword ptr [rbp - 8], rdi +// mov dword ptr [rbp - 12], esi +// mov rax, qword ptr [rbp - 8] +// mov ecx, dword ptr [rbp - 12] +// add ecx, dword ptr [rax] +// mov eax, ecx +// pop rbp +// ret + +int main() { + // Compiler produces: Plus::plusme(int) const: + Plus p(1); + p.plusme(1); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/mutable_state_15.cpp b/module-1/seminars/seminar18/lambdas/mutable_state_15.cpp new file mode 100644 index 00000000..2e39e952 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/mutable_state_15.cpp @@ -0,0 +1,28 @@ +#include + +auto counter = []() { + static int i; + return ++i; +}; + +// the behavior is equivalent to the following class + +class Counter { + public: + int operator() () const { + static int i; + return ++i; + } +}; + +int main() { + auto c1 = counter; + auto c2 = counter; + // equivalent to + // Counter c1; + // Counter c2; + + std::cout << c1() << c1() << c1() << std::endl; + std::cout << c2() << c2() << c2() << std::endl; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/mutable_state_16.cpp b/module-1/seminars/seminar18/lambdas/mutable_state_16.cpp new file mode 100644 index 00000000..990818ca --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/mutable_state_16.cpp @@ -0,0 +1,19 @@ +#include + +int main() { + // Explanation: we want to have a unique i for each object + // lets declare lambda's member in square bracket. We get a CE, the reason is + // captye by copy -> data member read only + auto lam = [i=0]() { return ++i; }; + // stack + // [c1, a $_o obj] i(0) + // [c2, a $_o obj] i(0) + + // CE: Increment read-only + // CE: cannot assign to a varible captured by copy in a non-mutable lambda + + // Correct + auto lam = [i=0]() mutable { return ++i; }; + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/operator_overloading_6.cpp b/module-1/seminars/seminar18/lambdas/operator_overloading_6.cpp new file mode 100644 index 00000000..7f2ad081 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/operator_overloading_6.cpp @@ -0,0 +1,27 @@ +class Plus { + int value; + public: + Plus(int v); + + int operator() (int x) const { + return x + value; + } +}; + +// Plus::operator()(int) const: # @Plus::operator()(int) const +// push rbp +// mov rbp, rsp +// mov qword ptr [rbp - 8], rdi +// mov dword ptr [rbp - 12], esi +// mov rax, qword ptr [rbp - 8] +// mov ecx, dword ptr [rbp - 12] +// add ecx, dword ptr [rax] +// mov eax, ecx +// pop rbp +// ret + +int main() { + auto plus = Plus(1); + plus(42); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/other_features_14.cpp b/module-1/seminars/seminar18/lambdas/other_features_14.cpp new file mode 100644 index 00000000..3b85bccc --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/other_features_14.cpp @@ -0,0 +1,16 @@ + +void foo() { + // C++20: + auto lam = [](int x) {return x + 1;}; + // lambda default constructible since C++20 + // decltype(lam) copy; + + // C++17: lambda constexpr by default + static_assert(lam(42) == 43); + static_assert(not noexcept(lam(42))); +} + +int main() { + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/overloading_2.cpp b/module-1/seminars/seminar18/lambdas/overloading_2.cpp new file mode 100644 index 00000000..fdccb7fb --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/overloading_2.cpp @@ -0,0 +1,37 @@ +#include + +// Explanation: +// 1. there is a problem, we need write difference version for each type +// 2. C++ magles the titles to linker symbols plus1(int), plus1(double) +int plus1(int x) { + return x + 1; +} + +int plus1(double x) { + return x + 1; +} + +// plus1(int): # @plus1(int) +// push rbp +// mov rbp, rsp +// mov dword ptr [rbp - 4], edi +// mov eax, dword ptr [rbp - 4] +// add eax, 1 +// pop rbp +// ret +// .LCPI1_0: +// .quad 4607182418800017408 # double 1 +// plus1(double): # @plus1(double) +// push rbp +// mov rbp, rsp +// movsd xmm1, qword ptr [rip + .LCPI1_0] # xmm1 = mem[0],zero +// movsd qword ptr [rbp - 8], xmm0 +// addsd xmm1, qword ptr [rbp - 8] +// cvttsd2si eax, xmm1 +// pop rbp +// ret + +int main() { + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/puzzle_13.cpp b/module-1/seminars/seminar18/lambdas/puzzle_13.cpp new file mode 100644 index 00000000..dda75fd6 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/puzzle_13.cpp @@ -0,0 +1,17 @@ +#include + +int g = 10; +auto kitten = [=]() { return g + 1; }; +auto cat = [g=g]() { return g + 1; }; + +int main() { + + g = 20; + printf("%d %d\t", kitten(), cat()); + // Out: 21 11 + // Explanation: cat makes a local copy g; kitten always tracks global g and make a copy just on the function call + // expression kitten(), only on the kitten() you make a copy of g in kitten + // in the cat lambda you make a copy of g just you reach line 5, because lambda is an object + // and ypu intialize an object in line 5 + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/single_function_1.cpp b/module-1/seminars/seminar18/lambdas/single_function_1.cpp new file mode 100644 index 00000000..5620529b --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/single_function_1.cpp @@ -0,0 +1,21 @@ + +// Explanation: C lang legacy +int plus1(int x) { + return x + 1; +} + +// this is clang for x86-64 arch +// Hypothesis: Arthur used x86 djgpp +// +// plus1(int): # @plus1(int) +// push rbp +// mov rbp, rsp +// mov dword ptr [rbp - 4], edi +// mov eax, dword ptr [rbp - 4] +// add eax, 1 +// pop rbp +// ret + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar18/lambdas/static_typing_to_the_rescue5.cpp b/module-1/seminars/seminar18/lambdas/static_typing_to_the_rescue5.cpp new file mode 100644 index 00000000..a5c876e8 --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/static_typing_to_the_rescue5.cpp @@ -0,0 +1,22 @@ +#include + +class Plus { + int value; + public: + Plus(int v); + + int plusme(int x) const { + return x + value; + } +}; + +int main() { + auto plus = Plus(1); + // Static typing gives as the knowladge that we call plusme of the Plus object, + // not something other plus me object + auto x = plus.plusme(42); + assert(x == 43); + return 0; +} + + diff --git a/module-1/seminars/seminar18/lambdas/template_3.cpp b/module-1/seminars/seminar18/lambdas/template_3.cpp new file mode 100644 index 00000000..f2715d3c --- /dev/null +++ b/module-1/seminars/seminar18/lambdas/template_3.cpp @@ -0,0 +1,33 @@ +template +T plus1(T x) { + return x + 1; +} + +// int plus1(int): # @int plus1(int) +// push rbp +// mov rbp, rsp +// mov dword ptr [rbp - 4], edi +// mov eax, dword ptr [rbp - 4] +// add eax, 1 +// pop rbp +// ret +// .LCPI2_0: +// .quad 4607182418800017408 # double 1 +// double plus1(double): # @double plus1(double) +// push rbp +// mov rbp, rsp +// movsd xmm1, qword ptr [rip + .LCPI2_0] # xmm1 = mem[0],zero +// movsd qword ptr [rbp - 8], xmm0 +// addsd xmm1, qword ptr [rbp - 8] +// movaps xmm0, xmm1 +// pop rbp +// ret + + +int main() { + // Compiler produces: plus1 + auto x = plus1(42); + // Compiler produces: plus1 + auto y = plus1(3.14); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/.gitignore b/module-1/seminars/seminar19/.gitignore new file mode 100644 index 00000000..c795b054 --- /dev/null +++ b/module-1/seminars/seminar19/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_abi/CMakeLists.txt b/module-1/seminars/seminar19/lambda_abi/CMakeLists.txt new file mode 100644 index 00000000..b5ffef87 --- /dev/null +++ b/module-1/seminars/seminar19/lambda_abi/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner main.cpp shelf.cpp shelf.h) \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_abi/main.cpp b/module-1/seminars/seminar19/lambda_abi/main.cpp new file mode 100644 index 00000000..29546f3e --- /dev/null +++ b/module-1/seminars/seminar19/lambda_abi/main.cpp @@ -0,0 +1,7 @@ +#include "shelf.h" + +int main() { + Shelf shelf(5); + shelf.ForEachBook([](auto&& book){book.print();}); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_abi/shelf.cpp b/module-1/seminars/seminar19/lambda_abi/shelf.cpp new file mode 100644 index 00000000..5facafa0 --- /dev/null +++ b/module-1/seminars/seminar19/lambda_abi/shelf.cpp @@ -0,0 +1,13 @@ +#include "shelf.h" + +Book::Book(std::string&& _title) : title(std::move(_title)) {} + +std::string Book::get_title() const { return title; } + +void Book::print() const { std::cout << title; } + +void Shelf::ForEachBook(std::function f) { + for (const Book& b : books_) { + f(b); + } +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_abi/shelf.h b/module-1/seminars/seminar19/lambda_abi/shelf.h new file mode 100644 index 00000000..02173306 --- /dev/null +++ b/module-1/seminars/seminar19/lambda_abi/shelf.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include + +class Book { + public: + Book() = default; + Book(std::string&& _title); + std::string get_title() const; + void print() const; + + private: + std::string title = "Hello\n"; +}; + +class Shelf { + public: + Shelf(const uint32_t num_books) : + books_(num_books) + {} + + void ForEachBook(std::function f); + + private: + std::vector books_; +}; \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_single_TU/CMakeLists.txt b/module-1/seminars/seminar19/lambda_single_TU/CMakeLists.txt new file mode 100644 index 00000000..62c052da --- /dev/null +++ b/module-1/seminars/seminar19/lambda_single_TU/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner main.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_single_TU/main.cpp b/module-1/seminars/seminar19/lambda_single_TU/main.cpp new file mode 100644 index 00000000..dba4b398 --- /dev/null +++ b/module-1/seminars/seminar19/lambda_single_TU/main.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +class Book { + public: + Book() = default; + Book(std::string&& _title); + std::string get_title() const; + void print() const; + + private: + std::string title = "Hello\n"; +}; + +class Shelf { + public: + Shelf(const uint32_t num_books) : + books_(num_books) + {} + + template + void ForEachBook(Func f); + + private: + std::vector books_; +}; + + +Book::Book(std::string&& _title) : title(std::move(_title)) {} + +std::string Book::get_title() const { return title; } + +void Book::print() const { std::cout << title; } + +template +void Shelf::ForEachBook(Func f) { + for (const Book& b : books_) { + f(b); + } +} + +int main() { + Shelf shelf(5); + shelf.ForEachBook([](auto&& book){book.print();}); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_template_abi_fail/CMakeLists.txt b/module-1/seminars/seminar19/lambda_template_abi_fail/CMakeLists.txt new file mode 100644 index 00000000..b5ffef87 --- /dev/null +++ b/module-1/seminars/seminar19/lambda_template_abi_fail/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner main.cpp shelf.cpp shelf.h) \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_template_abi_fail/main.cpp b/module-1/seminars/seminar19/lambda_template_abi_fail/main.cpp new file mode 100644 index 00000000..6820d776 --- /dev/null +++ b/module-1/seminars/seminar19/lambda_template_abi_fail/main.cpp @@ -0,0 +1,9 @@ +#include "shelf.h" + +int main() { + Shelf shelf(5); + // CE: Reason: template declaration and implmentaion in different files + // See lecture18/templates_implementation minimal sample + shelf.ForEachBook([](auto&& book){book.print();}); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_template_abi_fail/shelf.cpp b/module-1/seminars/seminar19/lambda_template_abi_fail/shelf.cpp new file mode 100644 index 00000000..ba7ae17b --- /dev/null +++ b/module-1/seminars/seminar19/lambda_template_abi_fail/shelf.cpp @@ -0,0 +1,14 @@ +#include "shelf.h" + +Book::Book(std::string&& _title) : title(std::move(_title)) {} + +std::string Book::get_title() const { return title; } + +void Book::print() const { std::cout << title; } + +template +void Shelf::ForEachBook(Func f) { + for (const Book& b : books_) { + f(b); + } +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambda_template_abi_fail/shelf.h b/module-1/seminars/seminar19/lambda_template_abi_fail/shelf.h new file mode 100644 index 00000000..534984d6 --- /dev/null +++ b/module-1/seminars/seminar19/lambda_template_abi_fail/shelf.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +class Book { + public: + Book() = default; + Book(std::string&& _title); + std::string get_title() const; + void print() const; + + private: + std::string title = "Hello\n"; +}; + +class Shelf { + public: + Shelf(const uint32_t num_books) : + books_(num_books) + {} + + template + void ForEachBook(Func f); + + private: + std::vector books_; +}; \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/CMakeLists.txt b/module-1/seminars/seminar19/lambdas/CMakeLists.txt new file mode 100644 index 00000000..2009b344 --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner runner.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/Plus_template_operator_1.cpp b/module-1/seminars/seminar19/lambdas/Plus_template_operator_1.cpp new file mode 100644 index 00000000..ab8f979b --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/Plus_template_operator_1.cpp @@ -0,0 +1,21 @@ +class Plus { +public: + Plus(int v) : value(v) {} + + // plus me is a tempate for stamping member functions + template + T operator()(T x) const { + return x + value; + } + +private: + int value; +}; + +int main() { + auto plus = Plus(1); + auto x = plus(42); + auto y = plus(3.14); + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/accept_lambdas_7.cpp b/module-1/seminars/seminar19/lambdas/accept_lambdas_7.cpp new file mode 100644 index 00000000..fa2b5308 --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/accept_lambdas_7.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +class Book { + public: + Book(std::string&& _title) : title(std::move(_title)) {} + std::string get_title() const { return title; } + + private: + std::string title; +}; + +// using +class Shelf { + public: + + // 1 translation unit => just use template parameter + template + void ForEachBook(Func f) { + for (const Book& b : books_) { + std::cout << f(b); + } + } + + private: + std::vector books_; +}; + +int main() { + Shelf shelf; + shelf.ForEachBook([](auto&& book){book.get_title();}); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/accept_lambdas_8.cpp b/module-1/seminars/seminar19/lambdas/accept_lambdas_8.cpp new file mode 100644 index 00000000..2b36556d --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/accept_lambdas_8.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +class Book { + public: + Book(std::string&& _title) : title(std::move(_title)) {} + std::string get_title() const { return title; } + + private: + std::string title; +}; + +// using +class Shelf { + public: + // several translation units (if we want to a lambda from one obf file to another obj file) => + // use concreate type with overloaded operator(): syntax ConcreateType f + // here we use std::function + void ForEachBook(std::function f) { + for (const Book& b : books_) { + std::cout << f(b); + } + } + + private: + std::vector books_; +}; + +int main() { + Shelf shelf; + shelf.ForEachBook([](auto&& book){book.get_title();}); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/capture_this_5.cpp b/module-1/seminars/seminar19/lambdas/capture_this_5.cpp new file mode 100644 index 00000000..5f8bb13d --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/capture_this_5.cpp @@ -0,0 +1,11 @@ +// 1. Deprecated: C++20. Reason: "=" means capture by value, this - pointer => just copy pointer + // run_in_thread([=]() {this->printer(x);}); + + // 2. To capture "this" by value you should capture it explicitly + // run_in_thread([=]() {this->printer(x);}); + + // 3. "this" by copy other by reference + // run_in_thread([&, this]() {this->printer(x);}); + + // 4. capture by "*this" captures Widget object explicitly + // run_in_thread([*this]() {this->printer(x);}); \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/clarification_=.cpp b/module-1/seminars/seminar19/lambdas/clarification_=.cpp new file mode 100644 index 00000000..b10c600d --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/clarification_=.cpp @@ -0,0 +1,45 @@ +#include + +class Container { + public: + Container() = default; + Container(const Container& other) { + std::cout << "copy" << std::endl; + }; +}; + +Container y; + +int main() { + // [] , [&], [=] difference + // [] - capture no local variables + // [=] - capture all local variables (that are used in the lambda) by copy + // [&] - capture all local variables (that are used in the lambda) by reference + + // CE: + Container x; + // auto lam1 = []() { x;}; + //lam1(); + + // Copy constructor + auto lam2 = [=]() { x;}; + lam2(); + + // No copy + auto lam3 = [&]() { x;}; + lam3(); + + // [] , [=] similarity + // [] - capture global variables by reference + // [=] - capture global variables by reference + // [&] - capture global variables by reference + auto lam4 = []() { y;}; + auto lam5 = [=]() { y;}; + auto lam6 = [&]() { y;}; + + //lam4(); + //lam5(); + //lam6(); + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/forward_6.cpp b/module-1/seminars/seminar19/lambdas/forward_6.cpp new file mode 100644 index 00000000..a13da2f7 --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/forward_6.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +int32_t foo(std::vector& v) {return 1;} + +int32_t foo(std::vector&& v) {return 2;} + +// Before C++20 +auto times = [](auto&&... args) { + return foo(std::forward(args)...); +}; + +// Since C++20 +auto times2 = [](Ts&&... args) { + return (std::forward(args)...); +} + +int main() { + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/generic_lambda_2.cpp b/module-1/seminars/seminar19/lambdas/generic_lambda_2.cpp new file mode 100644 index 00000000..2054799c --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/generic_lambda_2.cpp @@ -0,0 +1,46 @@ +#include + +class Int { +public: + Int(int val) : val_(val) {}; + + Int& operator+=(const Int& rhs) { + val_ += rhs.val_; + return *this; + } + + friend Int operator+(Int& lhs, const Int& rhs); + friend std::ostream& operator<<(std::ostream& lhs, const Int& rhs); + +private: + int val_; +}; + +Int operator+(Int& lhs, const Int& rhs) { + lhs += rhs; + return lhs; +} + +std::ostream& operator<<(std::ostream& lhs, const Int& rhs) { + lhs << rhs.val_; + return lhs; +} + +int main() { + + Int myInt(2); + auto non_template_plus = [value=1](int x) { return x + value; }; + // OK! + std::cout << non_template_plus(2); + // CE: + std::cout << non_template_plus(myInt); + + // 1. Template parameter disappeared + // 2. auto here is an equivalent for template parameter + auto template_plus = [value=1](auto x) { return x + value; }; + // OK! + std::cout << template_plus(2); + // OK! + std::cout << template_plus(myInt); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/lambda_this_4.cpp b/module-1/seminars/seminar19/lambdas/lambda_this_4.cpp new file mode 100644 index 00000000..132dfec0 --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/lambda_this_4.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +class Widget { +public: + + void SyncPrinter(int32_t x) { + this->printer(x); + } + + void AsyncPrinter(int32_t x) { + run_in_thread([=]() {this->printer(x);}); + std::thread::id this_id = std::this_thread::get_id(); + std::cout << "t1:" << this_id << std::endl; + } + +private: + + // TODO: set type for accepting lambdas + template + void run_in_thread(Func f) { + auto t = std::thread(f); + t.join(); + }; + + void printer(int32_t x) { + std::thread::id this_id = std::this_thread::get_id(); + std::cout << "t2:" << this_id << std::endl; + std::cout << x * x << std::endl; + } +}; + +int main() { + Widget w; + w.AsyncPrinter(10); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/lambdas_may_be_copyable_10.cpp b/module-1/seminars/seminar19/lambdas/lambdas_may_be_copyable_10.cpp new file mode 100644 index 00000000..cd6c0ff3 --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/lambdas_may_be_copyable_10.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + + +int main() { + std::unique_ptr prop; + auto lam = [p = std::move(prop)]() {}; + auto lam2 = std::move(lam); + + // CE: call to implicitly deleted copy constructor + // auto lam3 = lam2; + + // CE + // std::function f = std::move(lam); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/lambdas/variadic_lambdas_3.cpp b/module-1/seminars/seminar19/lambdas/variadic_lambdas_3.cpp new file mode 100644 index 00000000..b02f3872 --- /dev/null +++ b/module-1/seminars/seminar19/lambdas/variadic_lambdas_3.cpp @@ -0,0 +1,23 @@ + +int main() { + // 1. Template parameter disappeared + // 2. auto here is an equivalent for template parameter + + // tuple: + // 1. stores arguments + // 2. applies foo to arguments + auto tuple = [](auto ...xs) { + return [=](auto foo) { return foo(xs...); }; + }; + + // length: + // 1. stores arg + // 2. call arg with another func + auto length = [](auto xs) { + return xs([](auto ...z) { return sizeof...(z); }); + }; + + auto three = length(tuple(1, '2', "3")); + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/templates_implementation/CMakeLists.txt b/module-1/seminars/seminar19/templates_implementation/CMakeLists.txt new file mode 100644 index 00000000..8a4af1c1 --- /dev/null +++ b/module-1/seminars/seminar19/templates_implementation/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner main.cpp template.h template.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar19/templates_implementation/main.cpp b/module-1/seminars/seminar19/templates_implementation/main.cpp new file mode 100644 index 00000000..74013f8a --- /dev/null +++ b/module-1/seminars/seminar19/templates_implementation/main.cpp @@ -0,0 +1,6 @@ +#include "template.h" + +int main() { + foo(); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/templates_implementation/template.cpp b/module-1/seminars/seminar19/templates_implementation/template.cpp new file mode 100644 index 00000000..2e31fde3 --- /dev/null +++ b/module-1/seminars/seminar19/templates_implementation/template.cpp @@ -0,0 +1,6 @@ +#include "template.h" + +template +void foo() +{ +} \ No newline at end of file diff --git a/module-1/seminars/seminar19/templates_implementation/template.h b/module-1/seminars/seminar19/templates_implementation/template.h new file mode 100644 index 00000000..9984d34c --- /dev/null +++ b/module-1/seminars/seminar19/templates_implementation/template.h @@ -0,0 +1,4 @@ +#pragma once + +template +extern void foo(); diff --git a/module-1/seminars/seminar19/type_traits/is_copy_constructible.cpp b/module-1/seminars/seminar19/type_traits/is_copy_constructible.cpp new file mode 100644 index 00000000..d1c9abfe --- /dev/null +++ b/module-1/seminars/seminar19/type_traits/is_copy_constructible.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +template()))> +static std::true_type unary(int); + +template +static std::false_type unary(...); + +struct S { + S(int x) {}; + ~S() = delete; + + static int v; +}; + +int main() { + using T = S; + using A = int; + std::cout << std::is_destructible::value << std::endl; + std::cout << std::is_constructible::value << std::endl; + std::cout << decltype(unary(0))::value; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/.gitignore b/module-1/seminars/seminar20/.gitignore new file mode 100644 index 00000000..c795b054 --- /dev/null +++ b/module-1/seminars/seminar20/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/0_spec.cpp b/module-1/seminars/seminar20/type_traits/0_spec.cpp new file mode 100644 index 00000000..dd2106c8 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/0_spec.cpp @@ -0,0 +1,86 @@ +#include + +template +struct A { // #0 primary template + constexpr static int32_t val = 0; +}; + +template +struct A { // #4: + constexpr static int32_t val = 4; +}; + +template +struct A { // #1: + constexpr static int32_t val = 1; +}; + +template +struct A { // #3: + constexpr static int32_t val = 3; +}; + +template +struct A { // #2: + constexpr static int32_t val = 2; +}; + +// Expected: partial order +// branch0: #2 \subset #0 +// barnch1: #3 \subset #1 \subset #4 \subset #0 + +int main() { + + // Selection algorithm + // 0. Branch 0 analysis + // 0. check #2 fail on first parameter T1*: reason first is int32_t + // 1. Branch 1 analysis + // 0. check #3: fail on third parameter 5: reason third parameter is 1 + // 1. check #1: success: reason T1=int32_t, T1*=int32_t*, I=1 -> choose #1 + + std::cout << A::val << std::endl; // uses partial specialization #1 (T=int32_t, I=1) + + // Selection algorithm + // 0. Branch 0 analysis + // 0. check #2 fail on first parameter T1*: reason first is int32_t + // 1. Branch 1 analysis + // 0. check #3: success: reason T1=char -> spec accepts -> choose #3 + + std::cout << A::val << std::endl; // uses partial specialization #3, (T=char) + + // Selection algorithm + // 0. Branch 0 analysis + // 0. check #2 fail on first parameter T1*: reason first is int32_t + // 1. Branch 1 analysis + // 0. check #3: fail on third parameter 5: reason third parameter is 1 + // 1. check #1: fail on second parameter char*: reason T1=int32_t-> spec accepts + // 2. check #4: success: reason T1=int32_t, T2=char, I=1 -> spec accepts -> choose #4 + + std::cout << A::val << std::endl; // uses partial specialization #4, (X=int32_t, T=char, I=1) + + // Selection algorithm + // 0. Branch 0 analysis + // 0. check #2: fail on: T1*=int32_t** + // 1. Branch 1 analysis + // 0. check #3: fail on third parameter 5 + // 1. check #1: fail on T1*=int32_t** + // 2. check #4: fail on T2*=int32_t** + // 3. choose primary template + + std::cout << A::val << std::endl; // primary template + + + + // Selection algorithm + // 0. Branch 0 analysis + // 0. check #1: success: reason T1=int32_t, T1*=int32_t*, I=1 -> choose #1 + // 1. Branch 1 analysis + // 0. check #3: fail on third parameter 5: reason third parameter is 1 + // 1. check #1: fail on T1*=int32_t** + // 2. check #4: success: reason T1=int32_t, T2*=int32_t**, I=2 -> choose #1 + + // CE: branch 0 succeeded, branch 1 succeeded + // std::cout << A::val << std::endl; + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/10_mass_prod2.cpp b/module-1/seminars/seminar20/type_traits/10_mass_prod2.cpp new file mode 100644 index 00000000..165e23b2 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/10_mass_prod2.cpp @@ -0,0 +1,50 @@ +#include + +// Via functions + +struct is_polymorhic_helper { + + template(std::declval>()))> + static std::true_type foo(int); + + template + static std::false_type foo(...); +}; + +template +struct is_polymorhic_via_functions : public decltype(is_polymorhic_helper::foo(0)) {}; + +// Via structs + +template +struct IP_IMPL : std::false_type {}; + +template +struct IP_IMPL(std::declval>()))> : std::true_type {}; + + +template +// IP_IMPL well-formed -> true +// IP_IMPL ill-formed -> false +struct is_polymorhic_via_structs : IP_IMPL {}; + + +void remove_cv_t_explanation() { + // we use remove_cv_t to handle cast error from const T* / volatile T* to void* + + struct Foo { + public: + virtual void foo() {}; + }; + + + using T = const Foo; + using U = int; + // Example: CE + using M = decltype(dynamic_cast(std::declval())); +}; + +int main() { + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/11_mass_prod3.cpp b/module-1/seminars/seminar20/type_traits/11_mass_prod3.cpp new file mode 100644 index 00000000..f7501400 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/11_mass_prod3.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +template +struct IC_IMPL : std::false_type {}; + +template +struct IC_IMPL()...))), Ts...> : std::true_type { + constexpr static auto t = std::tuple(); +}; + +template +struct is_constructible : IC_IMPL {}; + +struct Foo { + Foo(int,double); +}; + +int main() { + auto t = is_constructible::t; + // void maps to second parameter -> decltype(void(::new T(std::declval()...))) + // there is no void in Ts... + std::cout << std::is_same>::value; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/12_mass_prod4.cpp b/module-1/seminars/seminar20/type_traits/12_mass_prod4.cpp new file mode 100644 index 00000000..b0f2cbed --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/12_mass_prod4.cpp @@ -0,0 +1,16 @@ +#include + +template +struct INCTImpl : std::false_type {}; + +// we use std::bool_constant to store noexcept result +template +struct INCTImpl()...))), Us...> : +std::bool_constant()...))> {}; + +template +struct IsNothrowConstructible : INCTImpl {}; + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/13_conditional_t.cpp b/module-1/seminars/seminar20/type_traits/13_conditional_t.cpp new file mode 100644 index 00000000..a4820494 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/13_conditional_t.cpp @@ -0,0 +1,18 @@ +#include + +template +struct Conditional { + using type = T; +}; + +template +struct Conditional { + using type = F; +}; + +template +using ConditionalT = typename Conditional::type; + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/14_enable_if_t1.cpp b/module-1/seminars/seminar20/type_traits/14_enable_if_t1.cpp new file mode 100644 index 00000000..05884479 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/14_enable_if_t1.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +template +struct EnableIf { + using type = T; +}; + +template +// Simplification from Conditional: Conditional -> Conditional +// { using type = F; } -> {} +struct EnableIf {}; + +template +using EnableIfT = typename EnableIf::type; + +template +struct A { + std::string name = "primary"; +}; + +template +struct A::value>> { + std::string name = "spec"; +}; + + +int main() { + std::cout << A().name << std::endl; + std::cout << A().name << std::endl; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/15_enable_if_t2.cpp b/module-1/seminars/seminar20/type_traits/15_enable_if_t2.cpp new file mode 100644 index 00000000..a063221e --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/15_enable_if_t2.cpp @@ -0,0 +1,41 @@ +#include +#include + +template +struct EnableIf { + using type = T; +}; + +template +struct EnableIf {}; + +template +using EnableIfT = typename EnableIf::type; + +// EnableIfT is an opposite to partial specializations with SFINAE +// EnableIfT maps: +// true -> well-formed expression +// false -> ill-formed expression + +// partial specializations with SFINAE maps: +// well-formed expression -> true +// ill-formed expression -> false + + +// Via structs + +template +struct IP_IMPL : std::false_type {}; + +template +struct IP_IMPL(std::declval>()))> : std::true_type {}; + + +template +// IP_IMPL well-formed -> true +// IP_IMPL ill-formed -> false +struct is_polymorhic_via_structs : IP_IMPL {}; + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/1_integral_const.cpp b/module-1/seminars/seminar20/type_traits/1_integral_const.cpp new file mode 100644 index 00000000..58d65a20 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/1_integral_const.cpp @@ -0,0 +1,17 @@ +#include +#include + +template +struct IntegralConst { + static constexpr T kValue = v; +}; + +template +using BoolConstant = IntegralConst; + +using TrueType = BoolConstant; +using FalseType = BoolConstant; + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/2_is_reference.cpp b/module-1/seminars/seminar20/type_traits/2_is_reference.cpp new file mode 100644 index 00000000..d429d5f9 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/2_is_reference.cpp @@ -0,0 +1,20 @@ +#include +#include + +template +struct IsReference : std::false_type {}; + +template +struct IsReference : std::true_type {}; + +template +struct IsReference : std::true_type {}; + +template +inline constexpr bool kIsReferenceV = typename IsReference::value; + +int main() { + static_assert(kIsReferenceV); + static_assert(!kIsReferenceV); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/3_remove_reference.cpp b/module-1/seminars/seminar20/type_traits/3_remove_reference.cpp new file mode 100644 index 00000000..aa881303 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/3_remove_reference.cpp @@ -0,0 +1,26 @@ +#include +#include + +template +struct RemoveReference { + using Type = T; +}; + +template +struct remove_reference { + using Type = T; +}; + +template +struct remove_reference { + using Type = T; +}; + +template +using RemoveReferenceT = typename RemoveReference::type; + +int main() { + static_assert(std::is_same, int>); + static_assert(std::is_same, int>); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/4_add_lvalue_reference.cpp b/module-1/seminars/seminar20/type_traits/4_add_lvalue_reference.cpp new file mode 100644 index 00000000..768b87eb --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/4_add_lvalue_reference.cpp @@ -0,0 +1,21 @@ +#include +#include + +template +struct add_lvalue_reference { + using type = T&; +}; + +template +using add_lvalue_reference_t = typename add_lvalue_reference::type; + +int main() { + // It is ok, but what about void? + static_assert( std::is_same_v, int&> ); + static_assert( std::is_same_v, int&> ); + static_assert( std::is_same_v, int&> ); + // CE: forming reference to void + static_assert( std::is_same, void> ); + // Solution: partial spec comes to the rescue + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/5_1_trouble_looms.cpp b/module-1/seminars/seminar20/type_traits/5_1_trouble_looms.cpp new file mode 100644 index 00000000..6e9b9f48 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/5_1_trouble_looms.cpp @@ -0,0 +1,37 @@ +#include +#include + +template +struct add_lvalue_reference { + using type = T&; +}; + +template <> +struct add_lvalue_reference { + using type = void; +}; + +template <> +struct add_lvalue_reference { + +}; + +template <> +struct add_lvalue_reference { + +}; + +template <> +struct add_lvalue_reference { + +}; + +template +using add_lvalue_reference_t = typename add_lvalue_reference::type; + +int main() { + // Now it works, but it's naive =( + static_assert( std::is_same_v, void> ); + // Motivation: make compiler add reference if and only if it would caused an error + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/5_2_trouble_looms.cpp b/module-1/seminars/seminar20/type_traits/5_2_trouble_looms.cpp new file mode 100644 index 00000000..74b25893 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/5_2_trouble_looms.cpp @@ -0,0 +1,25 @@ +#include +#include + +template +struct ALR_impl { + using type = T; +}; + +template +// we put std::remove_reference_t here to triggere sfinae on +// std::remove_reference_t - because it causes CE +struct ALR_impl> { + using type = T&; +}; + +template +struct add_lvalue_reference : ALR_impl> {}; + +int main() { + + // Notice that: + // - we use partial spec => std::remove_reference_t == std::remove_reference_t (same type) + // - we don't user patial spec => std::remove_reference_t is ill-formed + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/5_3_void_t_as_tool_for_mass_prod.cpp b/module-1/seminars/seminar20/type_traits/5_3_void_t_as_tool_for_mass_prod.cpp new file mode 100644 index 00000000..0dbffa35 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/5_3_void_t_as_tool_for_mass_prod.cpp @@ -0,0 +1,36 @@ +#include +#include + +template +using void_t = void; + +template +struct ALR_impl { + using type = T; +}; + +template +struct ALR_impl> { + using type = T&; +}; + +template +struct ARR_impl { + using type = T; +}; + +template +struct ARR_impl> { + using type = T&&; +}; + + +template +struct add_lvalue_reference : ALR_impl {}; + +template +struct add_rvalue_reference : ARR_impl {}; + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/6_0_distance_impl.cpp b/module-1/seminars/seminar20/type_traits/6_0_distance_impl.cpp new file mode 100644 index 00000000..c74baea5 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/6_0_distance_impl.cpp @@ -0,0 +1,16 @@ +#include + +template +struct PriorityTag {}; + +auto DistanceImpl(It first, It last, PriorityTag<0>); + +template +auto Distance(It first, It last) { + return DistanceImpl(first, last, PriorityTag<1>{}); +} + +int main() { + + return 0; +} diff --git a/module-1/seminars/seminar20/type_traits/6_1_assignment_result.cpp b/module-1/seminars/seminar20/type_traits/6_1_assignment_result.cpp new file mode 100644 index 00000000..5e7960ee --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/6_1_assignment_result.cpp @@ -0,0 +1,13 @@ +#include +#include + +template +using assignment_result_t = decltype( std::declval() = std::declval() ); + +int main() { + static_assert( std::is_same, int&>::value ); + // CE: ill-formed we can not assign int* to int& + // assignment_result_t x; + // Next: what if the ill-formed expression is a = b? + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/6_2_is_assignable.cpp b/module-1/seminars/seminar20/type_traits/6_2_is_assignable.cpp new file mode 100644 index 00000000..f37a0213 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/6_2_is_assignable.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +template +struct is_assignable_impl : std::false_type {}; + +template +// is_assignable_impl resolution algo: +// 1. ensure well-formedness std::declval() = std::declval() +// 2. cast expression to void +// 3. use void as third parameter (decltype) +// 4. add spec as candidate + +struct is_assignable_impl< T, U, decltype(static_cast( std::declval() = std::declval() ))> : std::true_type {}; + +template +struct is_assignable : is_assignable_impl {}; + +int main() { + std::cout << is_assignable::value; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/6_void_t.cpp b/module-1/seminars/seminar20/type_traits/6_void_t.cpp new file mode 100644 index 00000000..0200e002 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/6_void_t.cpp @@ -0,0 +1,23 @@ +#include +#include + +template +using void_t = void; + +template +struct ALR_impl { + using type = T; +}; + +template +struct ALR_impl> { + using type = T&; +}; + +template +struct add_lvalue_reference : ALR_impl {}; + +int main() { + // add_lvalue_ref == impl == impl> + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/8_expressions_to_trigger_sfinae.cpp b/module-1/seminars/seminar20/type_traits/8_expressions_to_trigger_sfinae.cpp new file mode 100644 index 00000000..1b51e489 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/8_expressions_to_trigger_sfinae.cpp @@ -0,0 +1,12 @@ +#include + +int main() { + using T = int&; + using U = int; + + decltype(void( std::declval() = std::declval() )); + decltype( std::declval() = std::declval(), void()); + std::void_t() = std::declval() )>; + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/9_mass_prod1.cpp b/module-1/seminars/seminar20/type_traits/9_mass_prod1.cpp new file mode 100644 index 00000000..a691ae3b --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/9_mass_prod1.cpp @@ -0,0 +1,16 @@ +#include + +// Via functions + +template +struct ISC_IMPL : std::false_type {}; + +template +struct ISC_IMPL(std::declval())))> : std::true_type {}; + +template +struct is_static_castable : ISC_IMPL {}; + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar20/type_traits/CMakeLists.txt b/module-1/seminars/seminar20/type_traits/CMakeLists.txt new file mode 100644 index 00000000..2b488911 --- /dev/null +++ b/module-1/seminars/seminar20/type_traits/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner 0_spec) \ No newline at end of file diff --git a/module-1/seminars/seminar21/interprocess/CMakeLists.txt b/module-1/seminars/seminar21/interprocess/CMakeLists.txt new file mode 100644 index 00000000..26696b51 --- /dev/null +++ b/module-1/seminars/seminar21/interprocess/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(p2 p2.cpp) \ No newline at end of file diff --git a/module-1/seminars/seminar21/interprocess/p1.cpp b/module-1/seminars/seminar21/interprocess/p1.cpp new file mode 100644 index 00000000..cc5abbf7 --- /dev/null +++ b/module-1/seminars/seminar21/interprocess/p1.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include + +int main() { + // Ptr -> String + int* x = new int(100); + + // connector + std::filesystem::path path_to_connector("connector.txt"); + std::fstream connector(path_to_connector, std::ios::out); + connector << x; + connector.close(); + std::cout << "addr:" << (x) << std::endl; + std::cout << "*addr:" << (*x) << std::endl; + + while (true) {}; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/interprocess/p2.cpp b/module-1/seminars/seminar21/interprocess/p2.cpp new file mode 100644 index 00000000..3ebaa703 --- /dev/null +++ b/module-1/seminars/seminar21/interprocess/p2.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include + +int main() { + + std::string name; + + // connector + std::filesystem::path path_to_connector("connector.txt"); + std::fstream connector(path_to_connector, std::ios::in); + connector >> name; + + std::cout << "name:" << name << std::endl; + // String -> Ptr + std::stringstream ss_in; + ss_in << name; + long long unsigned int i; + ss_in >> std::hex >> i; + int* i_ptr = reinterpret_cast(i); + + std::cout << "*i_ptr:" << (*i_ptr) << std::endl; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/22_0_offset_ptr.cpp b/module-1/seminars/seminar21/type_traits/22_0_offset_ptr.cpp new file mode 100644 index 00000000..c6b72d1e --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/22_0_offset_ptr.cpp @@ -0,0 +1,33 @@ +#include + +// Topic: Conditional explicit constructor +// Boost offset_ptr minimal sample +template +class offset_ptr { +public: + explicit offset_ptr(T* p) { + m_ptr = reinterpret_cast(p) - reinterpret_cast(this); + } + + T* ptr() const noexcept { + return reinterpret_cast(reinterpret_cast(this) + m_ptr); + } + + // Attempt 1 + + // U* is convertible to T* implicitly + template + offset_ptr(const offset_ptr& rhs) : offset_ptr(rhs.ptr()) {} + + // U* is convertible to T* with a static_cast + template + explicit offset_ptr(const offset_ptr& rhs) : offset_ptr(static_cast(rhs.ptr())) {} + + // Result: CE offset_ptr is redeclared. Reason: signatures are the same +private: + uintptr_t m_ptr; +}; + +int main() { + return 0; +} diff --git a/module-1/seminars/seminar21/type_traits/22_1_offset_ptr.cpp b/module-1/seminars/seminar21/type_traits/22_1_offset_ptr.cpp new file mode 100644 index 00000000..f2b330af --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/22_1_offset_ptr.cpp @@ -0,0 +1,47 @@ +#include +#include + +template +struct ISC_IMPL : std::false_type {}; + +template +struct ISC_IMPL(std::declval())))> : std::true_type {}; + +template +struct is_static_castable : ISC_IMPL {}; + +template +constexpr bool is_static_castable_v = is_static_castable::value; + +// Topic: Conditional explicit constructor +// Boost offset_ptr minimal sample + +template +class offset_ptr { +public: + explicit offset_ptr(T* p) { + m_ptr = reinterpret_cast(p) - reinterpret_cast(this); + } + + T* ptr() const noexcept { + return reinterpret_cast(reinterpret_cast(this) + m_ptr); + } + + // Attempt 2 + + // U* is convertible to T* implicitly + template >> + offset_ptr(const offset_ptr& rhs) : offset_ptr(rhs.ptr()) {} + + // U* is convertible to T* with a static_cast + template && !std::is_convertible_v >> + explicit offset_ptr(const offset_ptr& rhs) : offset_ptr(static_cast(rhs.ptr())) {} + + // Result: CE same error Reason: signatures are still the same +private: + uintptr_t m_ptr; +}; + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/22_2_offset_ptr.cpp b/module-1/seminars/seminar21/type_traits/22_2_offset_ptr.cpp new file mode 100644 index 00000000..84403cdb --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/22_2_offset_ptr.cpp @@ -0,0 +1,53 @@ + + +#include +#include + +template +struct ISC_IMPL : std::false_type {}; + +template +struct ISC_IMPL(std::declval())))> : std::true_type {}; + +template +struct is_static_castable : ISC_IMPL {}; + +template +constexpr bool is_static_castable_v = is_static_castable::value; + +// Topic: Conditional explicit constructor +// Boost offset_ptr minimal sample + +template +class offset_ptr { +public: + explicit offset_ptr(T* p) { + m_ptr = reinterpret_cast(p) - reinterpret_cast(this); + } + + T* ptr() const noexcept { + return reinterpret_cast(reinterpret_cast(this) + m_ptr); + } + + // Attempt 3: add dummpy parameter + + // U* is convertible to T* implicitly + // 1. check the signature + // 2. define the type + template >> + offset_ptr(const offset_ptr& rhs, int=0) : offset_ptr(rhs.ptr()) {} + + // U* is convertible to T* with a static_cast + // 1. check the signature + // 2. define the type + template && !std::is_convertible_v >> + explicit offset_ptr(const offset_ptr& rhs, double=0) : offset_ptr(static_cast(rhs.ptr())) {} + + // Cons: we need to introduce new tag type for overloading resolution +private: + uintptr_t m_ptr; +}; + +int main() { + return 0; +} diff --git a/module-1/seminars/seminar21/type_traits/22_3_offset_ptr.cpp b/module-1/seminars/seminar21/type_traits/22_3_offset_ptr.cpp new file mode 100644 index 00000000..ae979ba8 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/22_3_offset_ptr.cpp @@ -0,0 +1,53 @@ +#include +#include + +template +struct ISC_IMPL : std::false_type {}; + +template +struct ISC_IMPL(std::declval())))> : std::true_type {}; + +template +struct is_static_castable : ISC_IMPL {}; + +template +constexpr bool is_static_castable_v = is_static_castable::value; + +template +using bool_if_t = std::enable_if_t; + +// Topic: Conditional explicit constructor +// Boost offset_ptr minimal sample + +template +class offset_ptr { +public: + explicit offset_ptr(T* p) { + m_ptr = reinterpret_cast(p) - reinterpret_cast(this); + } + + T* ptr() const noexcept { + return reinterpret_cast(reinterpret_cast(this) + m_ptr); + } + + // Attempt 4: bool_if_t + + // U* is convertible to T* implicitly + // 1. define the type + // 2. check the signature + template > = true> + offset_ptr(const offset_ptr& rhs) : offset_ptr(rhs.ptr()) {} + + // U* is convertible to T* with a static_cast + // 1. define the type + // 2. check the signature + template && !std::is_convertible_v> = true> + explicit offset_ptr(const offset_ptr& rhs) : offset_ptr(static_cast(rhs.ptr())) {} + +private: + uintptr_t m_ptr; +}; + +int main() { + return 0; +} diff --git a/module-1/seminars/seminar21/type_traits/23_1_pointer_traits.cpp b/module-1/seminars/seminar21/type_traits/23_1_pointer_traits.cpp new file mode 100644 index 00000000..e6ac241c --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/23_1_pointer_traits.cpp @@ -0,0 +1,28 @@ +#include + +template +struct PointerTraits; + +template +struct PointerTraits { + using pointer = T*; + using element_type = T; + using difference_type = std::ptrdiff_t; + + template + using rebind = U*; + + // Attempt 1: + // Cons: T=void -> void& -> CE + static auto PointerTo(T& r) { + return &r; + } +}; + +int main() { + int32_t x = 1; + + int32_t* ptr_x = PointerTraits::PointerTo(x); + void* ptr_void = PointerTraits::PointerTo(x); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/23_2_pointer_traits.cpp b/module-1/seminars/seminar21/type_traits/23_2_pointer_traits.cpp new file mode 100644 index 00000000..fdcf6dfd --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/23_2_pointer_traits.cpp @@ -0,0 +1,33 @@ +#include +#include + +template +struct PointerTraits; + +template +struct PointerTraits { + using pointer = T*; + using element_type = T; + using difference_type = std::ptrdiff_t; + + template + using rebind = U*; + + // Attempt 2: use std::is_void_v + std::enable_if_t + // Result: CE again + // Reson: function signature is argly evaluated (T& evaluates early than std::is_void_v + std::enable_if_t) + template , typename = std::enable_if_t> + static auto PointerTo(T& r) { + return &r; + } + + +}; + +int main() { + int32_t x = 1; + + int32_t* ptr_x = PointerTraits::PointerTo(x); + void* ptr_void = PointerTraits::PointerTo(x); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/23_3_pointer_traits.cpp b/module-1/seminars/seminar21/type_traits/23_3_pointer_traits.cpp new file mode 100644 index 00000000..4c21bcce --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/23_3_pointer_traits.cpp @@ -0,0 +1,32 @@ +#include +#include + +template +struct PointerTraits; + +template +struct PointerTraits { + using pointer = T*; + using element_type = T; + using difference_type = std::ptrdiff_t; + + template + using rebind = U*; + + // Attempt 3: we will try to handle T before usage inside parameter list + // put T to enable_if_t -> use result type (TR) in the signature + // Result: CE again + // Reson: we have T& at enable_if_t (T=void -> void& -> CE) + template , typename TR = std::enable_if_t> + static auto PointerTo(TR r) { + return &r; + } +}; + +int main() { + int32_t x = 1; + + int32_t* ptr_x = PointerTraits::PointerTo(x); + void* ptr_void = PointerTraits::PointerTo(x); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/23_4_pointer_traits.cpp b/module-1/seminars/seminar21/type_traits/23_4_pointer_traits.cpp new file mode 100644 index 00000000..623bb78d --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/23_4_pointer_traits.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +template +struct PointerTraits; + +template +struct PointerTraits { + using pointer = T*; + using element_type = T; + using difference_type = std::ptrdiff_t; + + template + using rebind = U*; + + // Attempt 4: add & after enable_if_t evaluation + // Pros: it compiles + // Cons: it leads to segfault + template , typename TR = std::enable_if_t&> + static auto PointerTo(TR r) { + return &r; + } +}; + +int main() { + int32_t x = 1; + + int32_t* ptr_x = PointerTraits::PointerTo(x); + void* ptr_void = PointerTraits::PointerTo(x); + + // UB: Segfault (GCC: 9.2.0): + std::cout << *ptr_x; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/23_5_pointer_traits.cpp b/module-1/seminars/seminar21/type_traits/23_5_pointer_traits.cpp new file mode 100644 index 00000000..d758ba19 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/23_5_pointer_traits.cpp @@ -0,0 +1,29 @@ +#include +#include + +template +struct PointerTraits; + +template +struct PointerTraits { + using pointer = T*; + using element_type = T; + using difference_type = std::ptrdiff_t; + + template + using rebind = U*; + + // Attempt 5: add constraint to template parameter (std::enable_if_t) + template > + static auto PointerTo(std::enable_if_t& r) { + return &r; + } +}; + +int main() { + int32_t x = 1; + + int32_t* ptr_x = PointerTraits::PointerTo(x); + void* ptr_void = PointerTraits::PointerTo(x); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/CMakeLists.txt b/module-1/seminars/seminar21/type_traits/CMakeLists.txt new file mode 100644 index 00000000..2b488911 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner 0_spec) \ No newline at end of file diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeCache.txt b/module-1/seminars/seminar21/type_traits/build/CMakeCache.txt new file mode 100644 index 00000000..5be9141a --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeCache.txt @@ -0,0 +1,366 @@ +# This is the CMakeCache file. +# For build in directory: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build +# It was generated by CMake: /usr/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//Path to a program. +CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line + +//Path to a program. +CMAKE_AR:FILEPATH=/usr/bin/ar + +//Choose the type of build, options are: None Debug Release RelWithDebInfo +// MinSizeRel ... +CMAKE_BUILD_TYPE:STRING= + +//Enable/Disable color output during build. +CMAKE_COLOR_MAKEFILE:BOOL=ON + +//CXX compiler +CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-9 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-9 + +//Flags used by the CXX compiler during all build types. +CMAKE_CXX_FLAGS:STRING= + +//Flags used by the CXX compiler during DEBUG builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=-g + +//Flags used by the CXX compiler during MINSIZEREL builds. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the CXX compiler during RELEASE builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the CXX compiler during RELWITHDEBINFO builds. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//C compiler +CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-9 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-9 + +//Flags used by the C compiler during all build types. +CMAKE_C_FLAGS:STRING= + +//Flags used by the C compiler during DEBUG builds. +CMAKE_C_FLAGS_DEBUG:STRING=-g + +//Flags used by the C compiler during MINSIZEREL builds. +CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the C compiler during RELEASE builds. +CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the C compiler during RELWITHDEBINFO builds. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//Path to a program. +CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND + +//Flags used by the linker during all build types. +CMAKE_EXE_LINKER_FLAGS:STRING= + +//Flags used by the linker during DEBUG builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during MINSIZEREL builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during RELEASE builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during RELWITHDEBINFO builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Enable/Disable output of compile commands during generation. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF + +//Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +//Path to a program. +CMAKE_LINKER:FILEPATH=/usr/bin/ld + +//Path to a program. +CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make + +//Flags used by the linker during the creation of modules during +// all build types. +CMAKE_MODULE_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of modules during +// DEBUG builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of modules during +// MINSIZEREL builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of modules during +// RELEASE builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of modules during +// RELWITHDEBINFO builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_NM:FILEPATH=/usr/bin/nm + +//Path to a program. +CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy + +//Path to a program. +CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump + +//Value Computed by CMake +CMAKE_PROJECT_DESCRIPTION:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_HOMEPAGE_URL:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=runner + +//Path to a program. +CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib + +//Path to a program. +CMAKE_READELF:FILEPATH=/usr/bin/readelf + +//Flags used by the linker during the creation of shared libraries +// during all build types. +CMAKE_SHARED_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of shared libraries +// during DEBUG builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of shared libraries +// during MINSIZEREL builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of shared libraries +// during RELEASE builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of shared libraries +// during RELWITHDEBINFO builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries +// during all build types. +CMAKE_STATIC_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of static libraries +// during DEBUG builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of static libraries +// during MINSIZEREL builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELEASE builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELWITHDEBINFO builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_STRIP:FILEPATH=/usr/bin/strip + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//Value Computed by CMake +runner_BINARY_DIR:STATIC=/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build + +//Value Computed by CMake +runner_SOURCE_DIR:STATIC=/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: CMAKE_ADDR2LINE +CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_AR +CMAKE_AR-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=16 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 +//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE +CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/usr/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest +//ADVANCED property for variable: CMAKE_CXX_COMPILER +CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR +CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB +CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_AR +CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB +CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_DLLTOOL +CMAKE_DLLTOOL-ADVANCED:INTERNAL=1 +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS +CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Unix Makefiles +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits +//Install .so files without execute permission. +CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1 +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_NM +CMAKE_NM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJCOPY +CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJDUMP +CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RANLIB +CMAKE_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_READELF +CMAKE_READELF-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.16 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STRIP +CMAKE_STRIP-ADVANCED:INTERNAL=1 +//uname command +CMAKE_UNAME:INTERNAL=/usr/bin/uname +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 + diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeCCompiler.cmake b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeCCompiler.cmake new file mode 100644 index 00000000..2692f733 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeCCompiler.cmake @@ -0,0 +1,76 @@ +set(CMAKE_C_COMPILER "/usr/bin/cc") +set(CMAKE_C_COMPILER_ARG1 "") +set(CMAKE_C_COMPILER_ID "GNU") +set(CMAKE_C_COMPILER_VERSION "9.3.0") +set(CMAKE_C_COMPILER_VERSION_INTERNAL "") +set(CMAKE_C_COMPILER_WRAPPER "") +set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "11") +set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert") +set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") +set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros") +set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert") + +set(CMAKE_C_PLATFORM_ID "Linux") +set(CMAKE_C_SIMULATE_ID "") +set(CMAKE_C_COMPILER_FRONTEND_VARIANT "") +set(CMAKE_C_SIMULATE_VERSION "") + + + +set(CMAKE_AR "/usr/bin/ar") +set(CMAKE_C_COMPILER_AR "/usr/bin/gcc-ar-9") +set(CMAKE_RANLIB "/usr/bin/ranlib") +set(CMAKE_C_COMPILER_RANLIB "/usr/bin/gcc-ranlib-9") +set(CMAKE_LINKER "/usr/bin/ld") +set(CMAKE_MT "") +set(CMAKE_COMPILER_IS_GNUCC 1) +set(CMAKE_C_COMPILER_LOADED 1) +set(CMAKE_C_COMPILER_WORKS TRUE) +set(CMAKE_C_ABI_COMPILED TRUE) +set(CMAKE_COMPILER_IS_MINGW ) +set(CMAKE_COMPILER_IS_CYGWIN ) +if(CMAKE_COMPILER_IS_CYGWIN) + set(CYGWIN 1) + set(UNIX 1) +endif() + +set(CMAKE_C_COMPILER_ENV_VAR "CC") + +if(CMAKE_COMPILER_IS_MINGW) + set(MINGW 1) +endif() +set(CMAKE_C_COMPILER_ID_RUN 1) +set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) +set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) +set(CMAKE_C_LINKER_PREFERENCE 10) + +# Save compiler ABI information. +set(CMAKE_C_SIZEOF_DATA_PTR "8") +set(CMAKE_C_COMPILER_ABI "ELF") +set(CMAKE_C_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") + +if(CMAKE_C_SIZEOF_DATA_PTR) + set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") +endif() + +if(CMAKE_C_COMPILER_ABI) + set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") +endif() + +if(CMAKE_C_LIBRARY_ARCHITECTURE) + set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") +endif() + +set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") +if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) + set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") +endif() + + + + + +set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include") +set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "gcc;gcc_s;c;gcc;gcc_s") +set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib") +set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeCXXCompiler.cmake b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeCXXCompiler.cmake new file mode 100644 index 00000000..504c2505 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeCXXCompiler.cmake @@ -0,0 +1,88 @@ +set(CMAKE_CXX_COMPILER "/usr/bin/c++") +set(CMAKE_CXX_COMPILER_ARG1 "") +set(CMAKE_CXX_COMPILER_ID "GNU") +set(CMAKE_CXX_COMPILER_VERSION "9.3.0") +set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "") +set(CMAKE_CXX_COMPILER_WRAPPER "") +set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "14") +set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20") +set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") +set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") +set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") +set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17") +set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20") + +set(CMAKE_CXX_PLATFORM_ID "Linux") +set(CMAKE_CXX_SIMULATE_ID "") +set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "") +set(CMAKE_CXX_SIMULATE_VERSION "") + + + +set(CMAKE_AR "/usr/bin/ar") +set(CMAKE_CXX_COMPILER_AR "/usr/bin/gcc-ar-9") +set(CMAKE_RANLIB "/usr/bin/ranlib") +set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/gcc-ranlib-9") +set(CMAKE_LINKER "/usr/bin/ld") +set(CMAKE_MT "") +set(CMAKE_COMPILER_IS_GNUCXX 1) +set(CMAKE_CXX_COMPILER_LOADED 1) +set(CMAKE_CXX_COMPILER_WORKS TRUE) +set(CMAKE_CXX_ABI_COMPILED TRUE) +set(CMAKE_COMPILER_IS_MINGW ) +set(CMAKE_COMPILER_IS_CYGWIN ) +if(CMAKE_COMPILER_IS_CYGWIN) + set(CYGWIN 1) + set(UNIX 1) +endif() + +set(CMAKE_CXX_COMPILER_ENV_VAR "CXX") + +if(CMAKE_COMPILER_IS_MINGW) + set(MINGW 1) +endif() +set(CMAKE_CXX_COMPILER_ID_RUN 1) +set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;CPP) +set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC) + +foreach (lang C OBJC OBJCXX) + if (CMAKE_${lang}_COMPILER_ID_RUN) + foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS) + list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension}) + endforeach() + endif() +endforeach() + +set(CMAKE_CXX_LINKER_PREFERENCE 30) +set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) + +# Save compiler ABI information. +set(CMAKE_CXX_SIZEOF_DATA_PTR "8") +set(CMAKE_CXX_COMPILER_ABI "ELF") +set(CMAKE_CXX_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") + +if(CMAKE_CXX_SIZEOF_DATA_PTR) + set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}") +endif() + +if(CMAKE_CXX_COMPILER_ABI) + set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}") +endif() + +if(CMAKE_CXX_LIBRARY_ARCHITECTURE) + set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") +endif() + +set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "") +if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX) + set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}") +endif() + + + + + +set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/usr/include/c++/9;/usr/include/x86_64-linux-gnu/c++/9;/usr/include/c++/9/backward;/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include") +set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "stdc++;m;gcc_s;gcc;c;gcc_s;gcc") +set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib") +set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_C.bin b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_C.bin new file mode 100644 index 00000000..a3225b1f Binary files /dev/null and b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_C.bin differ diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_CXX.bin b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_CXX.bin new file mode 100644 index 00000000..89f78821 Binary files /dev/null and b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeDetermineCompilerABI_CXX.bin differ diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeSystem.cmake b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeSystem.cmake new file mode 100644 index 00000000..983006a1 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CMakeSystem.cmake @@ -0,0 +1,15 @@ +set(CMAKE_HOST_SYSTEM "Linux-5.4.72-microsoft-standard-WSL2") +set(CMAKE_HOST_SYSTEM_NAME "Linux") +set(CMAKE_HOST_SYSTEM_VERSION "5.4.72-microsoft-standard-WSL2") +set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") + + + +set(CMAKE_SYSTEM "Linux-5.4.72-microsoft-standard-WSL2") +set(CMAKE_SYSTEM_NAME "Linux") +set(CMAKE_SYSTEM_VERSION "5.4.72-microsoft-standard-WSL2") +set(CMAKE_SYSTEM_PROCESSOR "x86_64") + +set(CMAKE_CROSSCOMPILING "FALSE") + +set(CMAKE_SYSTEM_LOADED 1) diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdC/CMakeCCompilerId.c b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdC/CMakeCCompilerId.c new file mode 100644 index 00000000..d884b509 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdC/CMakeCCompilerId.c @@ -0,0 +1,671 @@ +#ifdef __cplusplus +# error "A C++ compiler has been selected for C." +#endif + +#if defined(__18CXX) +# define ID_VOID_MAIN +#endif +#if defined(__CLASSIC_C__) +/* cv-qualifiers did not exist in K&R C */ +# define const +# define volatile +#endif + + +/* Version number components: V=Version, R=Revision, P=Patch + Version date components: YYYY=Year, MM=Month, DD=Day */ + +#if defined(__INTEL_COMPILER) || defined(__ICC) +# define COMPILER_ID "Intel" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# if defined(__GNUC__) +# define SIMULATE_ID "GNU" +# endif + /* __INTEL_COMPILER = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# if defined(__INTEL_COMPILER_UPDATE) +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) +# else +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# endif +# if defined(__INTEL_COMPILER_BUILD_DATE) + /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ +# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# endif +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# if defined(__GNUC__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUC__) +# elif defined(__GNUG__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUG__) +# endif +# if defined(__GNUC_MINOR__) +# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(__PATHCC__) +# define COMPILER_ID "PathScale" +# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) +# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) +# if defined(__PATHCC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) +# endif + +#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) +# define COMPILER_ID "Embarcadero" +# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) + +#elif defined(__BORLANDC__) +# define COMPILER_ID "Borland" + /* __BORLANDC__ = 0xVRR */ +# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) + +#elif defined(__WATCOMC__) && __WATCOMC__ < 1200 +# define COMPILER_ID "Watcom" + /* __WATCOMC__ = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__WATCOMC__) +# define COMPILER_ID "OpenWatcom" + /* __WATCOMC__ = VVRP + 1100 */ +# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__SUNPRO_C) +# define COMPILER_ID "SunPro" +# if __SUNPRO_C >= 0x5100 + /* __SUNPRO_C = 0xVRRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# else + /* __SUNPRO_CC = 0xVRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# endif + +#elif defined(__HP_cc) +# define COMPILER_ID "HP" + /* __HP_cc = VVRRPP */ +# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) +# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) +# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100) + +#elif defined(__DECC) +# define COMPILER_ID "Compaq" + /* __DECC_VER = VVRRTPPPP */ +# define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000) +# define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100) +# define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000) + +#elif defined(__IBMC__) && defined(__COMPILER_VER__) +# define COMPILER_ID "zOS" + /* __IBMC__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) + +#elif defined(__ibmxl__) && defined(__clang__) +# define COMPILER_ID "XLClang" +# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) +# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) +# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) +# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) + + +#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800 +# define COMPILER_ID "XL" + /* __IBMC__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) + +#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800 +# define COMPILER_ID "VisualAge" + /* __IBMC__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) + +#elif defined(__PGI) +# define COMPILER_ID "PGI" +# define COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# endif + +#elif defined(_CRAYC) +# define COMPILER_ID "Cray" +# define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) +# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) + +#elif defined(__TI_COMPILER_VERSION__) +# define COMPILER_ID "TI" + /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ +# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) +# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) +# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) + +#elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) +# define COMPILER_ID "Fujitsu" + +#elif defined(__ghs__) +# define COMPILER_ID "GHS" +/* __GHS_VERSION_NUMBER = VVVVRP */ +# ifdef __GHS_VERSION_NUMBER +# define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) +# define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) +# define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) +# endif + +#elif defined(__TINYC__) +# define COMPILER_ID "TinyCC" + +#elif defined(__BCC__) +# define COMPILER_ID "Bruce" + +#elif defined(__SCO_VERSION__) +# define COMPILER_ID "SCO" + +#elif defined(__ARMCC_VERSION) && !defined(__clang__) +# define COMPILER_ID "ARMCC" +#if __ARMCC_VERSION >= 1000000 + /* __ARMCC_VERSION = VRRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#else + /* __ARMCC_VERSION = VRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#endif + + +#elif defined(__clang__) && defined(__apple_build_version__) +# define COMPILER_ID "AppleClang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) + +#elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) +# define COMPILER_ID "ARMClang" + # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) +# define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) + +#elif defined(__clang__) +# define COMPILER_ID "Clang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif + +#elif defined(__GNUC__) +# define COMPILER_ID "GNU" +# define COMPILER_VERSION_MAJOR DEC(__GNUC__) +# if defined(__GNUC_MINOR__) +# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(_MSC_VER) +# define COMPILER_ID "MSVC" + /* _MSC_VER = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# if defined(_MSC_FULL_VER) +# if _MSC_VER >= 1400 + /* _MSC_FULL_VER = VVRRPPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# else + /* _MSC_FULL_VER = VVRRPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# endif +# endif +# if defined(_MSC_BUILD) +# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# endif + +#elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) +# define COMPILER_ID "ADSP" +#if defined(__VISUALDSPVERSION__) + /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ +# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) +# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) +#endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# define COMPILER_ID "IAR" +# if defined(__VER__) && defined(__ICCARM__) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) +# define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) +# define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) +# define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) +# define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# endif + +#elif defined(__SDCC_VERSION_MAJOR) || defined(SDCC) +# define COMPILER_ID "SDCC" +# if defined(__SDCC_VERSION_MAJOR) +# define COMPILER_VERSION_MAJOR DEC(__SDCC_VERSION_MAJOR) +# define COMPILER_VERSION_MINOR DEC(__SDCC_VERSION_MINOR) +# define COMPILER_VERSION_PATCH DEC(__SDCC_VERSION_PATCH) +# else + /* SDCC = VRP */ +# define COMPILER_VERSION_MAJOR DEC(SDCC/100) +# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10) +# define COMPILER_VERSION_PATCH DEC(SDCC % 10) +# endif + + +/* These compilers are either not known or too old to define an + identification macro. Try to identify the platform and guess that + it is the native compiler. */ +#elif defined(__hpux) || defined(__hpua) +# define COMPILER_ID "HP" + +#else /* unknown compiler */ +# define COMPILER_ID "" +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; +#ifdef SIMULATE_ID +char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; +#endif + +#ifdef __QNXNTO__ +char const* qnxnto = "INFO" ":" "qnxnto[]"; +#endif + +#if defined(__CRAYXE) || defined(__CRAYXC) +char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; +#endif + +#define STRINGIFY_HELPER(X) #X +#define STRINGIFY(X) STRINGIFY_HELPER(X) + +/* Identify known platforms by name. */ +#if defined(__linux) || defined(__linux__) || defined(linux) +# define PLATFORM_ID "Linux" + +#elif defined(__CYGWIN__) +# define PLATFORM_ID "Cygwin" + +#elif defined(__MINGW32__) +# define PLATFORM_ID "MinGW" + +#elif defined(__APPLE__) +# define PLATFORM_ID "Darwin" + +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +# define PLATFORM_ID "Windows" + +#elif defined(__FreeBSD__) || defined(__FreeBSD) +# define PLATFORM_ID "FreeBSD" + +#elif defined(__NetBSD__) || defined(__NetBSD) +# define PLATFORM_ID "NetBSD" + +#elif defined(__OpenBSD__) || defined(__OPENBSD) +# define PLATFORM_ID "OpenBSD" + +#elif defined(__sun) || defined(sun) +# define PLATFORM_ID "SunOS" + +#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) +# define PLATFORM_ID "AIX" + +#elif defined(__hpux) || defined(__hpux__) +# define PLATFORM_ID "HP-UX" + +#elif defined(__HAIKU__) +# define PLATFORM_ID "Haiku" + +#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) +# define PLATFORM_ID "BeOS" + +#elif defined(__QNX__) || defined(__QNXNTO__) +# define PLATFORM_ID "QNX" + +#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) +# define PLATFORM_ID "Tru64" + +#elif defined(__riscos) || defined(__riscos__) +# define PLATFORM_ID "RISCos" + +#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) +# define PLATFORM_ID "SINIX" + +#elif defined(__UNIX_SV__) +# define PLATFORM_ID "UNIX_SV" + +#elif defined(__bsdos__) +# define PLATFORM_ID "BSDOS" + +#elif defined(_MPRAS) || defined(MPRAS) +# define PLATFORM_ID "MP-RAS" + +#elif defined(__osf) || defined(__osf__) +# define PLATFORM_ID "OSF1" + +#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) +# define PLATFORM_ID "SCO_SV" + +#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) +# define PLATFORM_ID "ULTRIX" + +#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) +# define PLATFORM_ID "Xenix" + +#elif defined(__WATCOMC__) +# if defined(__LINUX__) +# define PLATFORM_ID "Linux" + +# elif defined(__DOS__) +# define PLATFORM_ID "DOS" + +# elif defined(__OS2__) +# define PLATFORM_ID "OS2" + +# elif defined(__WINDOWS__) +# define PLATFORM_ID "Windows3x" + +# else /* unknown platform */ +# define PLATFORM_ID +# endif + +#elif defined(__INTEGRITY) +# if defined(INT_178B) +# define PLATFORM_ID "Integrity178" + +# else /* regular Integrity */ +# define PLATFORM_ID "Integrity" +# endif + +#else /* unknown platform */ +# define PLATFORM_ID + +#endif + +/* For windows compilers MSVC and Intel we can determine + the architecture of the compiler being used. This is because + the compilers do not have flags that can change the architecture, + but rather depend on which compiler is being used +*/ +#if defined(_WIN32) && defined(_MSC_VER) +# if defined(_M_IA64) +# define ARCHITECTURE_ID "IA64" + +# elif defined(_M_X64) || defined(_M_AMD64) +# define ARCHITECTURE_ID "x64" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# elif defined(_M_ARM64) +# define ARCHITECTURE_ID "ARM64" + +# elif defined(_M_ARM) +# if _M_ARM == 4 +# define ARCHITECTURE_ID "ARMV4I" +# elif _M_ARM == 5 +# define ARCHITECTURE_ID "ARMV5I" +# else +# define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) +# endif + +# elif defined(_M_MIPS) +# define ARCHITECTURE_ID "MIPS" + +# elif defined(_M_SH) +# define ARCHITECTURE_ID "SHx" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__WATCOMC__) +# if defined(_M_I86) +# define ARCHITECTURE_ID "I86" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# if defined(__ICCARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__ICCRX__) +# define ARCHITECTURE_ID "RX" + +# elif defined(__ICCRH850__) +# define ARCHITECTURE_ID "RH850" + +# elif defined(__ICCRL78__) +# define ARCHITECTURE_ID "RL78" + +# elif defined(__ICCRISCV__) +# define ARCHITECTURE_ID "RISCV" + +# elif defined(__ICCAVR__) +# define ARCHITECTURE_ID "AVR" + +# elif defined(__ICC430__) +# define ARCHITECTURE_ID "MSP430" + +# elif defined(__ICCV850__) +# define ARCHITECTURE_ID "V850" + +# elif defined(__ICC8051__) +# define ARCHITECTURE_ID "8051" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__ghs__) +# if defined(__PPC64__) +# define ARCHITECTURE_ID "PPC64" + +# elif defined(__ppc__) +# define ARCHITECTURE_ID "PPC" + +# elif defined(__ARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__x86_64__) +# define ARCHITECTURE_ID "x64" + +# elif defined(__i386__) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif +#else +# define ARCHITECTURE_ID +#endif + +/* Convert integer to decimal digit literals. */ +#define DEC(n) \ + ('0' + (((n) / 10000000)%10)), \ + ('0' + (((n) / 1000000)%10)), \ + ('0' + (((n) / 100000)%10)), \ + ('0' + (((n) / 10000)%10)), \ + ('0' + (((n) / 1000)%10)), \ + ('0' + (((n) / 100)%10)), \ + ('0' + (((n) / 10)%10)), \ + ('0' + ((n) % 10)) + +/* Convert integer to hex digit literals. */ +#define HEX(n) \ + ('0' + ((n)>>28 & 0xF)), \ + ('0' + ((n)>>24 & 0xF)), \ + ('0' + ((n)>>20 & 0xF)), \ + ('0' + ((n)>>16 & 0xF)), \ + ('0' + ((n)>>12 & 0xF)), \ + ('0' + ((n)>>8 & 0xF)), \ + ('0' + ((n)>>4 & 0xF)), \ + ('0' + ((n) & 0xF)) + +/* Construct a string literal encoding the version number components. */ +#ifdef COMPILER_VERSION_MAJOR +char const info_version[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', + COMPILER_VERSION_MAJOR, +# ifdef COMPILER_VERSION_MINOR + '.', COMPILER_VERSION_MINOR, +# ifdef COMPILER_VERSION_PATCH + '.', COMPILER_VERSION_PATCH, +# ifdef COMPILER_VERSION_TWEAK + '.', COMPILER_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct a string literal encoding the internal version number. */ +#ifdef COMPILER_VERSION_INTERNAL +char const info_version_internal[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', + 'i','n','t','e','r','n','a','l','[', + COMPILER_VERSION_INTERNAL,']','\0'}; +#endif + +/* Construct a string literal encoding the version number components. */ +#ifdef SIMULATE_VERSION_MAJOR +char const info_simulate_version[] = { + 'I', 'N', 'F', 'O', ':', + 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', + SIMULATE_VERSION_MAJOR, +# ifdef SIMULATE_VERSION_MINOR + '.', SIMULATE_VERSION_MINOR, +# ifdef SIMULATE_VERSION_PATCH + '.', SIMULATE_VERSION_PATCH, +# ifdef SIMULATE_VERSION_TWEAK + '.', SIMULATE_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; +char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; + + + + +#if !defined(__STDC__) +# if (defined(_MSC_VER) && !defined(__clang__)) \ + || (defined(__ibmxl__) || defined(__IBMC__)) +# define C_DIALECT "90" +# else +# define C_DIALECT +# endif +#elif __STDC_VERSION__ >= 201000L +# define C_DIALECT "11" +#elif __STDC_VERSION__ >= 199901L +# define C_DIALECT "99" +#else +# define C_DIALECT "90" +#endif +const char* info_language_dialect_default = + "INFO" ":" "dialect_default[" C_DIALECT "]"; + +/*--------------------------------------------------------------------------*/ + +#ifdef ID_VOID_MAIN +void main() {} +#else +# if defined(__CLASSIC_C__) +int main(argc, argv) int argc; char *argv[]; +# else +int main(int argc, char* argv[]) +# endif +{ + int require = 0; + require += info_compiler[argc]; + require += info_platform[argc]; + require += info_arch[argc]; +#ifdef COMPILER_VERSION_MAJOR + require += info_version[argc]; +#endif +#ifdef COMPILER_VERSION_INTERNAL + require += info_version_internal[argc]; +#endif +#ifdef SIMULATE_ID + require += info_simulate[argc]; +#endif +#ifdef SIMULATE_VERSION_MAJOR + require += info_simulate_version[argc]; +#endif +#if defined(__CRAYXE) || defined(__CRAYXC) + require += info_cray[argc]; +#endif + require += info_language_dialect_default[argc]; + (void)argv; + return require; +} +#endif diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdC/a.out b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdC/a.out new file mode 100644 index 00000000..46f1233d Binary files /dev/null and b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdC/a.out differ diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp new file mode 100644 index 00000000..69cfdba6 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp @@ -0,0 +1,660 @@ +/* This source file must have a .cpp extension so that all C++ compilers + recognize the extension without flags. Borland does not know .cxx for + example. */ +#ifndef __cplusplus +# error "A C compiler has been selected for C++." +#endif + + +/* Version number components: V=Version, R=Revision, P=Patch + Version date components: YYYY=Year, MM=Month, DD=Day */ + +#if defined(__COMO__) +# define COMPILER_ID "Comeau" + /* __COMO_VERSION__ = VRR */ +# define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) +# define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100) + +#elif defined(__INTEL_COMPILER) || defined(__ICC) +# define COMPILER_ID "Intel" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# if defined(__GNUC__) +# define SIMULATE_ID "GNU" +# endif + /* __INTEL_COMPILER = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# if defined(__INTEL_COMPILER_UPDATE) +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) +# else +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# endif +# if defined(__INTEL_COMPILER_BUILD_DATE) + /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ +# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# endif +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# if defined(__GNUC__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUC__) +# elif defined(__GNUG__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUG__) +# endif +# if defined(__GNUC_MINOR__) +# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(__PATHCC__) +# define COMPILER_ID "PathScale" +# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) +# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) +# if defined(__PATHCC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) +# endif + +#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) +# define COMPILER_ID "Embarcadero" +# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) + +#elif defined(__BORLANDC__) +# define COMPILER_ID "Borland" + /* __BORLANDC__ = 0xVRR */ +# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) + +#elif defined(__WATCOMC__) && __WATCOMC__ < 1200 +# define COMPILER_ID "Watcom" + /* __WATCOMC__ = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__WATCOMC__) +# define COMPILER_ID "OpenWatcom" + /* __WATCOMC__ = VVRP + 1100 */ +# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__SUNPRO_CC) +# define COMPILER_ID "SunPro" +# if __SUNPRO_CC >= 0x5100 + /* __SUNPRO_CC = 0xVRRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# else + /* __SUNPRO_CC = 0xVRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# endif + +#elif defined(__HP_aCC) +# define COMPILER_ID "HP" + /* __HP_aCC = VVRRPP */ +# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) +# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) +# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100) + +#elif defined(__DECCXX) +# define COMPILER_ID "Compaq" + /* __DECCXX_VER = VVRRTPPPP */ +# define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) +# define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) +# define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000) + +#elif defined(__IBMCPP__) && defined(__COMPILER_VER__) +# define COMPILER_ID "zOS" + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) + +#elif defined(__ibmxl__) && defined(__clang__) +# define COMPILER_ID "XLClang" +# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) +# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) +# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) +# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) + + +#elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800 +# define COMPILER_ID "XL" + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) + +#elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ < 800 +# define COMPILER_ID "VisualAge" + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) + +#elif defined(__PGI) +# define COMPILER_ID "PGI" +# define COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# endif + +#elif defined(_CRAYC) +# define COMPILER_ID "Cray" +# define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) +# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) + +#elif defined(__TI_COMPILER_VERSION__) +# define COMPILER_ID "TI" + /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ +# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) +# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) +# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) + +#elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) +# define COMPILER_ID "Fujitsu" + +#elif defined(__ghs__) +# define COMPILER_ID "GHS" +/* __GHS_VERSION_NUMBER = VVVVRP */ +# ifdef __GHS_VERSION_NUMBER +# define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) +# define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) +# define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) +# endif + +#elif defined(__SCO_VERSION__) +# define COMPILER_ID "SCO" + +#elif defined(__ARMCC_VERSION) && !defined(__clang__) +# define COMPILER_ID "ARMCC" +#if __ARMCC_VERSION >= 1000000 + /* __ARMCC_VERSION = VRRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#else + /* __ARMCC_VERSION = VRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#endif + + +#elif defined(__clang__) && defined(__apple_build_version__) +# define COMPILER_ID "AppleClang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) + +#elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) +# define COMPILER_ID "ARMClang" + # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) +# define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) + +#elif defined(__clang__) +# define COMPILER_ID "Clang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif + +#elif defined(__GNUC__) || defined(__GNUG__) +# define COMPILER_ID "GNU" +# if defined(__GNUC__) +# define COMPILER_VERSION_MAJOR DEC(__GNUC__) +# else +# define COMPILER_VERSION_MAJOR DEC(__GNUG__) +# endif +# if defined(__GNUC_MINOR__) +# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(_MSC_VER) +# define COMPILER_ID "MSVC" + /* _MSC_VER = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# if defined(_MSC_FULL_VER) +# if _MSC_VER >= 1400 + /* _MSC_FULL_VER = VVRRPPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# else + /* _MSC_FULL_VER = VVRRPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# endif +# endif +# if defined(_MSC_BUILD) +# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# endif + +#elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) +# define COMPILER_ID "ADSP" +#if defined(__VISUALDSPVERSION__) + /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ +# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) +# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) +#endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# define COMPILER_ID "IAR" +# if defined(__VER__) && defined(__ICCARM__) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) +# define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) +# define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) +# define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) +# define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# endif + + +/* These compilers are either not known or too old to define an + identification macro. Try to identify the platform and guess that + it is the native compiler. */ +#elif defined(__hpux) || defined(__hpua) +# define COMPILER_ID "HP" + +#else /* unknown compiler */ +# define COMPILER_ID "" +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; +#ifdef SIMULATE_ID +char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; +#endif + +#ifdef __QNXNTO__ +char const* qnxnto = "INFO" ":" "qnxnto[]"; +#endif + +#if defined(__CRAYXE) || defined(__CRAYXC) +char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; +#endif + +#define STRINGIFY_HELPER(X) #X +#define STRINGIFY(X) STRINGIFY_HELPER(X) + +/* Identify known platforms by name. */ +#if defined(__linux) || defined(__linux__) || defined(linux) +# define PLATFORM_ID "Linux" + +#elif defined(__CYGWIN__) +# define PLATFORM_ID "Cygwin" + +#elif defined(__MINGW32__) +# define PLATFORM_ID "MinGW" + +#elif defined(__APPLE__) +# define PLATFORM_ID "Darwin" + +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +# define PLATFORM_ID "Windows" + +#elif defined(__FreeBSD__) || defined(__FreeBSD) +# define PLATFORM_ID "FreeBSD" + +#elif defined(__NetBSD__) || defined(__NetBSD) +# define PLATFORM_ID "NetBSD" + +#elif defined(__OpenBSD__) || defined(__OPENBSD) +# define PLATFORM_ID "OpenBSD" + +#elif defined(__sun) || defined(sun) +# define PLATFORM_ID "SunOS" + +#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) +# define PLATFORM_ID "AIX" + +#elif defined(__hpux) || defined(__hpux__) +# define PLATFORM_ID "HP-UX" + +#elif defined(__HAIKU__) +# define PLATFORM_ID "Haiku" + +#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) +# define PLATFORM_ID "BeOS" + +#elif defined(__QNX__) || defined(__QNXNTO__) +# define PLATFORM_ID "QNX" + +#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) +# define PLATFORM_ID "Tru64" + +#elif defined(__riscos) || defined(__riscos__) +# define PLATFORM_ID "RISCos" + +#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) +# define PLATFORM_ID "SINIX" + +#elif defined(__UNIX_SV__) +# define PLATFORM_ID "UNIX_SV" + +#elif defined(__bsdos__) +# define PLATFORM_ID "BSDOS" + +#elif defined(_MPRAS) || defined(MPRAS) +# define PLATFORM_ID "MP-RAS" + +#elif defined(__osf) || defined(__osf__) +# define PLATFORM_ID "OSF1" + +#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) +# define PLATFORM_ID "SCO_SV" + +#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) +# define PLATFORM_ID "ULTRIX" + +#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) +# define PLATFORM_ID "Xenix" + +#elif defined(__WATCOMC__) +# if defined(__LINUX__) +# define PLATFORM_ID "Linux" + +# elif defined(__DOS__) +# define PLATFORM_ID "DOS" + +# elif defined(__OS2__) +# define PLATFORM_ID "OS2" + +# elif defined(__WINDOWS__) +# define PLATFORM_ID "Windows3x" + +# else /* unknown platform */ +# define PLATFORM_ID +# endif + +#elif defined(__INTEGRITY) +# if defined(INT_178B) +# define PLATFORM_ID "Integrity178" + +# else /* regular Integrity */ +# define PLATFORM_ID "Integrity" +# endif + +#else /* unknown platform */ +# define PLATFORM_ID + +#endif + +/* For windows compilers MSVC and Intel we can determine + the architecture of the compiler being used. This is because + the compilers do not have flags that can change the architecture, + but rather depend on which compiler is being used +*/ +#if defined(_WIN32) && defined(_MSC_VER) +# if defined(_M_IA64) +# define ARCHITECTURE_ID "IA64" + +# elif defined(_M_X64) || defined(_M_AMD64) +# define ARCHITECTURE_ID "x64" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# elif defined(_M_ARM64) +# define ARCHITECTURE_ID "ARM64" + +# elif defined(_M_ARM) +# if _M_ARM == 4 +# define ARCHITECTURE_ID "ARMV4I" +# elif _M_ARM == 5 +# define ARCHITECTURE_ID "ARMV5I" +# else +# define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) +# endif + +# elif defined(_M_MIPS) +# define ARCHITECTURE_ID "MIPS" + +# elif defined(_M_SH) +# define ARCHITECTURE_ID "SHx" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__WATCOMC__) +# if defined(_M_I86) +# define ARCHITECTURE_ID "I86" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# if defined(__ICCARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__ICCRX__) +# define ARCHITECTURE_ID "RX" + +# elif defined(__ICCRH850__) +# define ARCHITECTURE_ID "RH850" + +# elif defined(__ICCRL78__) +# define ARCHITECTURE_ID "RL78" + +# elif defined(__ICCRISCV__) +# define ARCHITECTURE_ID "RISCV" + +# elif defined(__ICCAVR__) +# define ARCHITECTURE_ID "AVR" + +# elif defined(__ICC430__) +# define ARCHITECTURE_ID "MSP430" + +# elif defined(__ICCV850__) +# define ARCHITECTURE_ID "V850" + +# elif defined(__ICC8051__) +# define ARCHITECTURE_ID "8051" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__ghs__) +# if defined(__PPC64__) +# define ARCHITECTURE_ID "PPC64" + +# elif defined(__ppc__) +# define ARCHITECTURE_ID "PPC" + +# elif defined(__ARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__x86_64__) +# define ARCHITECTURE_ID "x64" + +# elif defined(__i386__) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif +#else +# define ARCHITECTURE_ID +#endif + +/* Convert integer to decimal digit literals. */ +#define DEC(n) \ + ('0' + (((n) / 10000000)%10)), \ + ('0' + (((n) / 1000000)%10)), \ + ('0' + (((n) / 100000)%10)), \ + ('0' + (((n) / 10000)%10)), \ + ('0' + (((n) / 1000)%10)), \ + ('0' + (((n) / 100)%10)), \ + ('0' + (((n) / 10)%10)), \ + ('0' + ((n) % 10)) + +/* Convert integer to hex digit literals. */ +#define HEX(n) \ + ('0' + ((n)>>28 & 0xF)), \ + ('0' + ((n)>>24 & 0xF)), \ + ('0' + ((n)>>20 & 0xF)), \ + ('0' + ((n)>>16 & 0xF)), \ + ('0' + ((n)>>12 & 0xF)), \ + ('0' + ((n)>>8 & 0xF)), \ + ('0' + ((n)>>4 & 0xF)), \ + ('0' + ((n) & 0xF)) + +/* Construct a string literal encoding the version number components. */ +#ifdef COMPILER_VERSION_MAJOR +char const info_version[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', + COMPILER_VERSION_MAJOR, +# ifdef COMPILER_VERSION_MINOR + '.', COMPILER_VERSION_MINOR, +# ifdef COMPILER_VERSION_PATCH + '.', COMPILER_VERSION_PATCH, +# ifdef COMPILER_VERSION_TWEAK + '.', COMPILER_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct a string literal encoding the internal version number. */ +#ifdef COMPILER_VERSION_INTERNAL +char const info_version_internal[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', + 'i','n','t','e','r','n','a','l','[', + COMPILER_VERSION_INTERNAL,']','\0'}; +#endif + +/* Construct a string literal encoding the version number components. */ +#ifdef SIMULATE_VERSION_MAJOR +char const info_simulate_version[] = { + 'I', 'N', 'F', 'O', ':', + 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', + SIMULATE_VERSION_MAJOR, +# ifdef SIMULATE_VERSION_MINOR + '.', SIMULATE_VERSION_MINOR, +# ifdef SIMULATE_VERSION_PATCH + '.', SIMULATE_VERSION_PATCH, +# ifdef SIMULATE_VERSION_TWEAK + '.', SIMULATE_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; +char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; + + + + +#if defined(__INTEL_COMPILER) && defined(_MSVC_LANG) && _MSVC_LANG < 201403L +# if defined(__INTEL_CXX11_MODE__) +# if defined(__cpp_aggregate_nsdmi) +# define CXX_STD 201402L +# else +# define CXX_STD 201103L +# endif +# else +# define CXX_STD 199711L +# endif +#elif defined(_MSC_VER) && defined(_MSVC_LANG) +# define CXX_STD _MSVC_LANG +#else +# define CXX_STD __cplusplus +#endif + +const char* info_language_dialect_default = "INFO" ":" "dialect_default[" +#if CXX_STD > 201703L + "20" +#elif CXX_STD >= 201703L + "17" +#elif CXX_STD >= 201402L + "14" +#elif CXX_STD >= 201103L + "11" +#else + "98" +#endif +"]"; + +/*--------------------------------------------------------------------------*/ + +int main(int argc, char* argv[]) +{ + int require = 0; + require += info_compiler[argc]; + require += info_platform[argc]; +#ifdef COMPILER_VERSION_MAJOR + require += info_version[argc]; +#endif +#ifdef COMPILER_VERSION_INTERNAL + require += info_version_internal[argc]; +#endif +#ifdef SIMULATE_ID + require += info_simulate[argc]; +#endif +#ifdef SIMULATE_VERSION_MAJOR + require += info_simulate_version[argc]; +#endif +#if defined(__CRAYXE) || defined(__CRAYXC) + require += info_cray[argc]; +#endif + require += info_language_dialect_default[argc]; + (void)argv; + return require; +} diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdCXX/a.out b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdCXX/a.out new file mode 100644 index 00000000..c8684265 Binary files /dev/null and b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/3.16.3/CompilerIdCXX/a.out differ diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/CMakeDirectoryInformation.cmake b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/CMakeDirectoryInformation.cmake new file mode 100644 index 00000000..207091f4 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/CMakeDirectoryInformation.cmake @@ -0,0 +1,16 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +# Relative path conversion top directories. +set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits") +set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build") + +# Force unix paths in dependencies. +set(CMAKE_FORCE_UNIX_PATHS 1) + + +# The C and CXX include file regular expressions for this directory. +set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") +set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") +set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) +set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/CMakeOutput.log b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/CMakeOutput.log new file mode 100644 index 00000000..4a92aec6 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/CMakeOutput.log @@ -0,0 +1,461 @@ +The system is: Linux - 5.4.72-microsoft-standard-WSL2 - x86_64 +Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded. +Compiler: /usr/bin/cc +Build flags: +Id flags: + +The output was: +0 + + +Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out" + +The C compiler identification is GNU, found in "/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/3.16.3/CompilerIdC/a.out" + +Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded. +Compiler: /usr/bin/c++ +Build flags: +Id flags: + +The output was: +0 + + +Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out" + +The CXX compiler identification is GNU, found in "/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/3.16.3/CompilerIdCXX/a.out" + +Determining if the C compiler works passed with the following output: +Change Dir: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp + +Run Build Command(s):/usr/bin/make cmTC_18298/fast && /usr/bin/make -f CMakeFiles/cmTC_18298.dir/build.make CMakeFiles/cmTC_18298.dir/build +make[1]: Entering directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' +Building C object CMakeFiles/cmTC_18298.dir/testCCompiler.c.o +/usr/bin/cc -o CMakeFiles/cmTC_18298.dir/testCCompiler.c.o -c /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp/testCCompiler.c +Linking C executable cmTC_18298 +/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_18298.dir/link.txt --verbose=1 +/usr/bin/cc CMakeFiles/cmTC_18298.dir/testCCompiler.c.o -o cmTC_18298 +make[1]: Leaving directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' + + + +Detecting C compiler ABI info compiled with the following output: +Change Dir: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp + +Run Build Command(s):/usr/bin/make cmTC_dc3f3/fast && /usr/bin/make -f CMakeFiles/cmTC_dc3f3.dir/build.make CMakeFiles/cmTC_dc3f3.dir/build +make[1]: Entering directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' +Building C object CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o +/usr/bin/cc -v -o CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -c /usr/share/cmake-3.16/Modules/CMakeCCompilerABI.c +Using built-in specs. +COLLECT_GCC=/usr/bin/cc +OFFLOAD_TARGET_NAMES=nvptx-none:hsa +OFFLOAD_TARGET_DEFAULT=1 +Target: x86_64-linux-gnu +Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu +Thread model: posix +gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) +COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64' + /usr/lib/gcc/x86_64-linux-gnu/9/cc1 -quiet -v -imultiarch x86_64-linux-gnu /usr/share/cmake-3.16/Modules/CMakeCCompilerABI.c -quiet -dumpbase CMakeCCompilerABI.c -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/cc9HR3j4.s +GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu) + compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP + +GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 +ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" +ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/include-fixed" +ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include" +#include "..." search starts here: +#include <...> search starts here: + /usr/lib/gcc/x86_64-linux-gnu/9/include + /usr/local/include + /usr/include/x86_64-linux-gnu + /usr/include +End of search list. +GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu) + compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP + +GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 +Compiler executable checksum: bbf13931d8de1abe14040c9909cb6969 +COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64' + as -v --64 -o CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o /tmp/cc9HR3j4.s +GNU assembler version 2.34 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.34 +COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/ +LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/ +COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64' +Linking C executable cmTC_dc3f3 +/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_dc3f3.dir/link.txt --verbose=1 +/usr/bin/cc -v CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -o cmTC_dc3f3 +Using built-in specs. +COLLECT_GCC=/usr/bin/cc +COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper +OFFLOAD_TARGET_NAMES=nvptx-none:hsa +OFFLOAD_TARGET_DEFAULT=1 +Target: x86_64-linux-gnu +Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu +Thread model: posix +gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) +COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/ +LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/ +COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_dc3f3' '-mtune=generic' '-march=x86-64' + /usr/lib/gcc/x86_64-linux-gnu/9/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccw8YqKv.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_dc3f3 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o +COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_dc3f3' '-mtune=generic' '-march=x86-64' +make[1]: Leaving directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' + + + +Parsed C implicit include dir info from above output: rv=done + found start of include info + found start of implicit include info + add: [/usr/lib/gcc/x86_64-linux-gnu/9/include] + add: [/usr/local/include] + add: [/usr/include/x86_64-linux-gnu] + add: [/usr/include] + end of search list found + collapse include dir [/usr/lib/gcc/x86_64-linux-gnu/9/include] ==> [/usr/lib/gcc/x86_64-linux-gnu/9/include] + collapse include dir [/usr/local/include] ==> [/usr/local/include] + collapse include dir [/usr/include/x86_64-linux-gnu] ==> [/usr/include/x86_64-linux-gnu] + collapse include dir [/usr/include] ==> [/usr/include] + implicit include dirs: [/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include] + + +Parsed C implicit link information from above output: + link line regex: [^( *|.*[/\])(ld|CMAKE_LINK_STARTFILE-NOTFOUND|([^/\]+-)?ld|collect2)[^/\]*( |$)] + ignore line: [Change Dir: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp] + ignore line: [] + ignore line: [Run Build Command(s):/usr/bin/make cmTC_dc3f3/fast && /usr/bin/make -f CMakeFiles/cmTC_dc3f3.dir/build.make CMakeFiles/cmTC_dc3f3.dir/build] + ignore line: [make[1]: Entering directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp'] + ignore line: [Building C object CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o] + ignore line: [/usr/bin/cc -v -o CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -c /usr/share/cmake-3.16/Modules/CMakeCCompilerABI.c] + ignore line: [Using built-in specs.] + ignore line: [COLLECT_GCC=/usr/bin/cc] + ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:hsa] + ignore line: [OFFLOAD_TARGET_DEFAULT=1] + ignore line: [Target: x86_64-linux-gnu] + ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c ada c++ go brig d fortran objc obj-c++ gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu] + ignore line: [Thread model: posix] + ignore line: [gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) ] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'] + ignore line: [ /usr/lib/gcc/x86_64-linux-gnu/9/cc1 -quiet -v -imultiarch x86_64-linux-gnu /usr/share/cmake-3.16/Modules/CMakeCCompilerABI.c -quiet -dumpbase CMakeCCompilerABI.c -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/cc9HR3j4.s] + ignore line: [GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)] + ignore line: [ compiled by GNU C version 9.3.0 GMP version 6.2.0 MPFR version 4.0.2 MPC version 1.1.0 isl version isl-0.22.1-GMP] + ignore line: [] + ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072] + ignore line: [ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"] + ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/include-fixed"] + ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"] + ignore line: [#include "..." search starts here:] + ignore line: [#include <...> search starts here:] + ignore line: [ /usr/lib/gcc/x86_64-linux-gnu/9/include] + ignore line: [ /usr/local/include] + ignore line: [ /usr/include/x86_64-linux-gnu] + ignore line: [ /usr/include] + ignore line: [End of search list.] + ignore line: [GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)] + ignore line: [ compiled by GNU C version 9.3.0 GMP version 6.2.0 MPFR version 4.0.2 MPC version 1.1.0 isl version isl-0.22.1-GMP] + ignore line: [] + ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072] + ignore line: [Compiler executable checksum: bbf13931d8de1abe14040c9909cb6969] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'] + ignore line: [ as -v --64 -o CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o /tmp/cc9HR3j4.s] + ignore line: [GNU assembler version 2.34 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.34] + ignore line: [COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/] + ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'] + ignore line: [Linking C executable cmTC_dc3f3] + ignore line: [/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_dc3f3.dir/link.txt --verbose=1] + ignore line: [/usr/bin/cc -v CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -o cmTC_dc3f3 ] + ignore line: [Using built-in specs.] + ignore line: [COLLECT_GCC=/usr/bin/cc] + ignore line: [COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper] + ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:hsa] + ignore line: [OFFLOAD_TARGET_DEFAULT=1] + ignore line: [Target: x86_64-linux-gnu] + ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c ada c++ go brig d fortran objc obj-c++ gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu] + ignore line: [Thread model: posix] + ignore line: [gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) ] + ignore line: [COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/] + ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_dc3f3' '-mtune=generic' '-march=x86-64'] + link line: [ /usr/lib/gcc/x86_64-linux-gnu/9/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccw8YqKv.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_dc3f3 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o] + arg [/usr/lib/gcc/x86_64-linux-gnu/9/collect2] ==> ignore + arg [-plugin] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so] ==> ignore + arg [-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper] ==> ignore + arg [-plugin-opt=-fresolution=/tmp/ccw8YqKv.res] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore + arg [-plugin-opt=-pass-through=-lc] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore + arg [--build-id] ==> ignore + arg [--eh-frame-hdr] ==> ignore + arg [-m] ==> ignore + arg [elf_x86_64] ==> ignore + arg [--hash-style=gnu] ==> ignore + arg [--as-needed] ==> ignore + arg [-dynamic-linker] ==> ignore + arg [/lib64/ld-linux-x86-64.so.2] ==> ignore + arg [-pie] ==> ignore + arg [-znow] ==> ignore + arg [-zrelro] ==> ignore + arg [-o] ==> ignore + arg [cmTC_dc3f3] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o] ==> ignore + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9] + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu] + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib] + arg [-L/lib/x86_64-linux-gnu] ==> dir [/lib/x86_64-linux-gnu] + arg [-L/lib/../lib] ==> dir [/lib/../lib] + arg [-L/usr/lib/x86_64-linux-gnu] ==> dir [/usr/lib/x86_64-linux-gnu] + arg [-L/usr/lib/../lib] ==> dir [/usr/lib/../lib] + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9/../../..] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../..] + arg [CMakeFiles/cmTC_dc3f3.dir/CMakeCCompilerABI.c.o] ==> ignore + arg [-lgcc] ==> lib [gcc] + arg [--push-state] ==> ignore + arg [--as-needed] ==> ignore + arg [-lgcc_s] ==> lib [gcc_s] + arg [--pop-state] ==> ignore + arg [-lc] ==> lib [c] + arg [-lgcc] ==> lib [gcc] + arg [--push-state] ==> ignore + arg [--as-needed] ==> ignore + arg [-lgcc_s] ==> lib [gcc_s] + arg [--pop-state] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o] ==> ignore + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9] ==> [/usr/lib/gcc/x86_64-linux-gnu/9] + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu] + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib] ==> [/usr/lib] + collapse library dir [/lib/x86_64-linux-gnu] ==> [/lib/x86_64-linux-gnu] + collapse library dir [/lib/../lib] ==> [/lib] + collapse library dir [/usr/lib/x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu] + collapse library dir [/usr/lib/../lib] ==> [/usr/lib] + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../..] ==> [/usr/lib] + implicit libs: [gcc;gcc_s;c;gcc;gcc_s] + implicit dirs: [/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib] + implicit fwks: [] + + +Determining if the CXX compiler works passed with the following output: +Change Dir: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp + +Run Build Command(s):/usr/bin/make cmTC_59337/fast && /usr/bin/make -f CMakeFiles/cmTC_59337.dir/build.make CMakeFiles/cmTC_59337.dir/build +make[1]: Entering directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' +Building CXX object CMakeFiles/cmTC_59337.dir/testCXXCompiler.cxx.o +/usr/bin/c++ -std=gnu++17 -o CMakeFiles/cmTC_59337.dir/testCXXCompiler.cxx.o -c /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx +Linking CXX executable cmTC_59337 +/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_59337.dir/link.txt --verbose=1 +/usr/bin/c++ CMakeFiles/cmTC_59337.dir/testCXXCompiler.cxx.o -o cmTC_59337 +make[1]: Leaving directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' + + + +Detecting CXX compiler ABI info compiled with the following output: +Change Dir: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp + +Run Build Command(s):/usr/bin/make cmTC_9cdd0/fast && /usr/bin/make -f CMakeFiles/cmTC_9cdd0.dir/build.make CMakeFiles/cmTC_9cdd0.dir/build +make[1]: Entering directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' +Building CXX object CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o +/usr/bin/c++ -v -std=gnu++17 -o CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -c /usr/share/cmake-3.16/Modules/CMakeCXXCompilerABI.cpp +Using built-in specs. +COLLECT_GCC=/usr/bin/c++ +OFFLOAD_TARGET_NAMES=nvptx-none:hsa +OFFLOAD_TARGET_DEFAULT=1 +Target: x86_64-linux-gnu +Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu +Thread model: posix +gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) +COLLECT_GCC_OPTIONS='-v' '-std=gnu++17' '-o' 'CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' + /usr/lib/gcc/x86_64-linux-gnu/9/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /usr/share/cmake-3.16/Modules/CMakeCXXCompilerABI.cpp -quiet -dumpbase CMakeCXXCompilerABI.cpp -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -std=gnu++17 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccuWQZ3Y.s +GNU C++17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu) + compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP + +GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 +ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/9" +ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" +ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/include-fixed" +ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include" +#include "..." search starts here: +#include <...> search starts here: + /usr/include/c++/9 + /usr/include/x86_64-linux-gnu/c++/9 + /usr/include/c++/9/backward + /usr/lib/gcc/x86_64-linux-gnu/9/include + /usr/local/include + /usr/include/x86_64-linux-gnu + /usr/include +End of search list. +GNU C++17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu) + compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP + +GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 +Compiler executable checksum: 466f818abe2f30ba03783f22bd12d815 +COLLECT_GCC_OPTIONS='-v' '-std=gnu++17' '-o' 'CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' + as -v --64 -o CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o /tmp/ccuWQZ3Y.s +GNU assembler version 2.34 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.34 +COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/ +LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/ +COLLECT_GCC_OPTIONS='-v' '-std=gnu++17' '-o' 'CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' +Linking CXX executable cmTC_9cdd0 +/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9cdd0.dir/link.txt --verbose=1 +/usr/bin/c++ -v CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -o cmTC_9cdd0 +Using built-in specs. +COLLECT_GCC=/usr/bin/c++ +COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper +OFFLOAD_TARGET_NAMES=nvptx-none:hsa +OFFLOAD_TARGET_DEFAULT=1 +Target: x86_64-linux-gnu +Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu +Thread model: posix +gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) +COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/ +LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/ +COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_9cdd0' '-shared-libgcc' '-mtune=generic' '-march=x86-64' + /usr/lib/gcc/x86_64-linux-gnu/9/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccbXMtir.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_9cdd0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o +COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_9cdd0' '-shared-libgcc' '-mtune=generic' '-march=x86-64' +make[1]: Leaving directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp' + + + +Parsed CXX implicit include dir info from above output: rv=done + found start of include info + found start of implicit include info + add: [/usr/include/c++/9] + add: [/usr/include/x86_64-linux-gnu/c++/9] + add: [/usr/include/c++/9/backward] + add: [/usr/lib/gcc/x86_64-linux-gnu/9/include] + add: [/usr/local/include] + add: [/usr/include/x86_64-linux-gnu] + add: [/usr/include] + end of search list found + collapse include dir [/usr/include/c++/9] ==> [/usr/include/c++/9] + collapse include dir [/usr/include/x86_64-linux-gnu/c++/9] ==> [/usr/include/x86_64-linux-gnu/c++/9] + collapse include dir [/usr/include/c++/9/backward] ==> [/usr/include/c++/9/backward] + collapse include dir [/usr/lib/gcc/x86_64-linux-gnu/9/include] ==> [/usr/lib/gcc/x86_64-linux-gnu/9/include] + collapse include dir [/usr/local/include] ==> [/usr/local/include] + collapse include dir [/usr/include/x86_64-linux-gnu] ==> [/usr/include/x86_64-linux-gnu] + collapse include dir [/usr/include] ==> [/usr/include] + implicit include dirs: [/usr/include/c++/9;/usr/include/x86_64-linux-gnu/c++/9;/usr/include/c++/9/backward;/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include] + + +Parsed CXX implicit link information from above output: + link line regex: [^( *|.*[/\])(ld|CMAKE_LINK_STARTFILE-NOTFOUND|([^/\]+-)?ld|collect2)[^/\]*( |$)] + ignore line: [Change Dir: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp] + ignore line: [] + ignore line: [Run Build Command(s):/usr/bin/make cmTC_9cdd0/fast && /usr/bin/make -f CMakeFiles/cmTC_9cdd0.dir/build.make CMakeFiles/cmTC_9cdd0.dir/build] + ignore line: [make[1]: Entering directory '/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/CMakeTmp'] + ignore line: [Building CXX object CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o] + ignore line: [/usr/bin/c++ -v -std=gnu++17 -o CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -c /usr/share/cmake-3.16/Modules/CMakeCXXCompilerABI.cpp] + ignore line: [Using built-in specs.] + ignore line: [COLLECT_GCC=/usr/bin/c++] + ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:hsa] + ignore line: [OFFLOAD_TARGET_DEFAULT=1] + ignore line: [Target: x86_64-linux-gnu] + ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c ada c++ go brig d fortran objc obj-c++ gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu] + ignore line: [Thread model: posix] + ignore line: [gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) ] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-std=gnu++17' '-o' 'CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64'] + ignore line: [ /usr/lib/gcc/x86_64-linux-gnu/9/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /usr/share/cmake-3.16/Modules/CMakeCXXCompilerABI.cpp -quiet -dumpbase CMakeCXXCompilerABI.cpp -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -std=gnu++17 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccuWQZ3Y.s] + ignore line: [GNU C++17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)] + ignore line: [ compiled by GNU C version 9.3.0 GMP version 6.2.0 MPFR version 4.0.2 MPC version 1.1.0 isl version isl-0.22.1-GMP] + ignore line: [] + ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072] + ignore line: [ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/9"] + ignore line: [ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"] + ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/include-fixed"] + ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"] + ignore line: [#include "..." search starts here:] + ignore line: [#include <...> search starts here:] + ignore line: [ /usr/include/c++/9] + ignore line: [ /usr/include/x86_64-linux-gnu/c++/9] + ignore line: [ /usr/include/c++/9/backward] + ignore line: [ /usr/lib/gcc/x86_64-linux-gnu/9/include] + ignore line: [ /usr/local/include] + ignore line: [ /usr/include/x86_64-linux-gnu] + ignore line: [ /usr/include] + ignore line: [End of search list.] + ignore line: [GNU C++17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)] + ignore line: [ compiled by GNU C version 9.3.0 GMP version 6.2.0 MPFR version 4.0.2 MPC version 1.1.0 isl version isl-0.22.1-GMP] + ignore line: [] + ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072] + ignore line: [Compiler executable checksum: 466f818abe2f30ba03783f22bd12d815] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-std=gnu++17' '-o' 'CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64'] + ignore line: [ as -v --64 -o CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o /tmp/ccuWQZ3Y.s] + ignore line: [GNU assembler version 2.34 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.34] + ignore line: [COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/] + ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-std=gnu++17' '-o' 'CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64'] + ignore line: [Linking CXX executable cmTC_9cdd0] + ignore line: [/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9cdd0.dir/link.txt --verbose=1] + ignore line: [/usr/bin/c++ -v CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -o cmTC_9cdd0 ] + ignore line: [Using built-in specs.] + ignore line: [COLLECT_GCC=/usr/bin/c++] + ignore line: [COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper] + ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:hsa] + ignore line: [OFFLOAD_TARGET_DEFAULT=1] + ignore line: [Target: x86_64-linux-gnu] + ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c ada c++ go brig d fortran objc obj-c++ gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu] + ignore line: [Thread model: posix] + ignore line: [gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) ] + ignore line: [COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/] + ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/] + ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_9cdd0' '-shared-libgcc' '-mtune=generic' '-march=x86-64'] + link line: [ /usr/lib/gcc/x86_64-linux-gnu/9/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccbXMtir.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_9cdd0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o] + arg [/usr/lib/gcc/x86_64-linux-gnu/9/collect2] ==> ignore + arg [-plugin] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so] ==> ignore + arg [-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper] ==> ignore + arg [-plugin-opt=-fresolution=/tmp/ccbXMtir.res] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc] ==> ignore + arg [-plugin-opt=-pass-through=-lc] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore + arg [-plugin-opt=-pass-through=-lgcc] ==> ignore + arg [--build-id] ==> ignore + arg [--eh-frame-hdr] ==> ignore + arg [-m] ==> ignore + arg [elf_x86_64] ==> ignore + arg [--hash-style=gnu] ==> ignore + arg [--as-needed] ==> ignore + arg [-dynamic-linker] ==> ignore + arg [/lib64/ld-linux-x86-64.so.2] ==> ignore + arg [-pie] ==> ignore + arg [-znow] ==> ignore + arg [-zrelro] ==> ignore + arg [-o] ==> ignore + arg [cmTC_9cdd0] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o] ==> ignore + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9] + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu] + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib] + arg [-L/lib/x86_64-linux-gnu] ==> dir [/lib/x86_64-linux-gnu] + arg [-L/lib/../lib] ==> dir [/lib/../lib] + arg [-L/usr/lib/x86_64-linux-gnu] ==> dir [/usr/lib/x86_64-linux-gnu] + arg [-L/usr/lib/../lib] ==> dir [/usr/lib/../lib] + arg [-L/usr/lib/gcc/x86_64-linux-gnu/9/../../..] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../..] + arg [CMakeFiles/cmTC_9cdd0.dir/CMakeCXXCompilerABI.cpp.o] ==> ignore + arg [-lstdc++] ==> lib [stdc++] + arg [-lm] ==> lib [m] + arg [-lgcc_s] ==> lib [gcc_s] + arg [-lgcc] ==> lib [gcc] + arg [-lc] ==> lib [c] + arg [-lgcc_s] ==> lib [gcc_s] + arg [-lgcc] ==> lib [gcc] + arg [/usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o] ==> ignore + arg [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o] ==> ignore + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9] ==> [/usr/lib/gcc/x86_64-linux-gnu/9] + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu] + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib] ==> [/usr/lib] + collapse library dir [/lib/x86_64-linux-gnu] ==> [/lib/x86_64-linux-gnu] + collapse library dir [/lib/../lib] ==> [/lib] + collapse library dir [/usr/lib/x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu] + collapse library dir [/usr/lib/../lib] ==> [/usr/lib] + collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/9/../../..] ==> [/usr/lib] + implicit libs: [stdc++;m;gcc_s;gcc;c;gcc_s;gcc] + implicit dirs: [/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib] + implicit fwks: [] + + diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/Makefile.cmake b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/Makefile.cmake new file mode 100644 index 00000000..1cde416c --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/Makefile.cmake @@ -0,0 +1,120 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +# The generator used is: +set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles") + +# The top level Makefile was generated from the following files: +set(CMAKE_MAKEFILE_DEPENDS + "CMakeCache.txt" + "../CMakeLists.txt" + "CMakeFiles/3.16.3/CMakeCCompiler.cmake" + "CMakeFiles/3.16.3/CMakeCXXCompiler.cmake" + "CMakeFiles/3.16.3/CMakeSystem.cmake" + "/usr/share/cmake-3.16/Modules/CMakeCCompiler.cmake.in" + "/usr/share/cmake-3.16/Modules/CMakeCCompilerABI.c" + "/usr/share/cmake-3.16/Modules/CMakeCInformation.cmake" + "/usr/share/cmake-3.16/Modules/CMakeCXXCompiler.cmake.in" + "/usr/share/cmake-3.16/Modules/CMakeCXXCompilerABI.cpp" + "/usr/share/cmake-3.16/Modules/CMakeCXXInformation.cmake" + "/usr/share/cmake-3.16/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake" + "/usr/share/cmake-3.16/Modules/CMakeCommonLanguageInclude.cmake" + "/usr/share/cmake-3.16/Modules/CMakeCompilerIdDetection.cmake" + "/usr/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake" + "/usr/share/cmake-3.16/Modules/CMakeDetermineCXXCompiler.cmake" + "/usr/share/cmake-3.16/Modules/CMakeDetermineCompileFeatures.cmake" + "/usr/share/cmake-3.16/Modules/CMakeDetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/CMakeDetermineCompilerABI.cmake" + "/usr/share/cmake-3.16/Modules/CMakeDetermineCompilerId.cmake" + "/usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake" + "/usr/share/cmake-3.16/Modules/CMakeFindBinUtils.cmake" + "/usr/share/cmake-3.16/Modules/CMakeGenericSystem.cmake" + "/usr/share/cmake-3.16/Modules/CMakeInitializeConfigs.cmake" + "/usr/share/cmake-3.16/Modules/CMakeLanguageInformation.cmake" + "/usr/share/cmake-3.16/Modules/CMakeParseImplicitIncludeInfo.cmake" + "/usr/share/cmake-3.16/Modules/CMakeParseImplicitLinkInfo.cmake" + "/usr/share/cmake-3.16/Modules/CMakeSystem.cmake.in" + "/usr/share/cmake-3.16/Modules/CMakeSystemSpecificInformation.cmake" + "/usr/share/cmake-3.16/Modules/CMakeSystemSpecificInitialize.cmake" + "/usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake" + "/usr/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake" + "/usr/share/cmake-3.16/Modules/CMakeTestCompilerCommon.cmake" + "/usr/share/cmake-3.16/Modules/CMakeUnixFindMake.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/ADSP-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/ARMCC-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/ARMClang-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/AppleClang-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Borland-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Bruce-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/CMakeCommonCompilerMacros.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Clang-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Clang-DetermineCompilerInternal.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Compaq-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Cray-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Embarcadero-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Fujitsu-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/GHS-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/GNU-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/GNU-C.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/GNU-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/GNU-CXX.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/GNU-FindBinUtils.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/GNU.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/HP-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/HP-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/IAR-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Intel-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/MSVC-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/NVIDIA-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/PGI-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/PathScale-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/SCO-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/SDCC-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/SunPro-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/TI-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/TinyCC-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/VisualAge-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/Watcom-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/XL-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/XL-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/XLClang-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/XLClang-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/zOS-C-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake" + "/usr/share/cmake-3.16/Modules/Internal/CMakeCheckCompilerFlag.cmake" + "/usr/share/cmake-3.16/Modules/Internal/FeatureTesting.cmake" + "/usr/share/cmake-3.16/Modules/Platform/Linux-Determine-CXX.cmake" + "/usr/share/cmake-3.16/Modules/Platform/Linux-GNU-C.cmake" + "/usr/share/cmake-3.16/Modules/Platform/Linux-GNU-CXX.cmake" + "/usr/share/cmake-3.16/Modules/Platform/Linux-GNU.cmake" + "/usr/share/cmake-3.16/Modules/Platform/Linux.cmake" + "/usr/share/cmake-3.16/Modules/Platform/UnixPaths.cmake" + ) + +# The corresponding makefile is: +set(CMAKE_MAKEFILE_OUTPUTS + "Makefile" + "CMakeFiles/cmake.check_cache" + ) + +# Byproducts of CMake generate step: +set(CMAKE_MAKEFILE_PRODUCTS + "CMakeFiles/3.16.3/CMakeSystem.cmake" + "CMakeFiles/3.16.3/CMakeCCompiler.cmake" + "CMakeFiles/3.16.3/CMakeCXXCompiler.cmake" + "CMakeFiles/3.16.3/CMakeCCompiler.cmake" + "CMakeFiles/3.16.3/CMakeCXXCompiler.cmake" + "CMakeFiles/CMakeDirectoryInformation.cmake" + ) + +# Dependency information for all targets: +set(CMAKE_DEPEND_INFO_FILES + "CMakeFiles/runner.dir/DependInfo.cmake" + ) diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/Makefile2 b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/Makefile2 new file mode 100644 index 00000000..afc4cf16 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/Makefile2 @@ -0,0 +1,106 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +# Default target executed when no arguments are given to make. +default_target: all + +.PHONY : default_target + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + + +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build + +#============================================================================= +# Directory level rules for the build root directory + +# The main recursive "all" target. +all: CMakeFiles/runner.dir/all + +.PHONY : all + +# The main recursive "preinstall" target. +preinstall: + +.PHONY : preinstall + +# The main recursive "clean" target. +clean: CMakeFiles/runner.dir/clean + +.PHONY : clean + +#============================================================================= +# Target rules for target CMakeFiles/runner.dir + +# All Build rule for target. +CMakeFiles/runner.dir/all: + $(MAKE) -f CMakeFiles/runner.dir/build.make CMakeFiles/runner.dir/depend + $(MAKE) -f CMakeFiles/runner.dir/build.make CMakeFiles/runner.dir/build + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles --progress-num=1,2 "Built target runner" +.PHONY : CMakeFiles/runner.dir/all + +# Build rule for subdir invocation for target. +CMakeFiles/runner.dir/rule: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles 2 + $(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/runner.dir/all + $(CMAKE_COMMAND) -E cmake_progress_start /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles 0 +.PHONY : CMakeFiles/runner.dir/rule + +# Convenience name for target. +runner: CMakeFiles/runner.dir/rule + +.PHONY : runner + +# clean rule for target. +CMakeFiles/runner.dir/clean: + $(MAKE) -f CMakeFiles/runner.dir/build.make CMakeFiles/runner.dir/clean +.PHONY : CMakeFiles/runner.dir/clean + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/TargetDirectories.txt b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/TargetDirectories.txt new file mode 100644 index 00000000..3c15cfd3 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/TargetDirectories.txt @@ -0,0 +1,3 @@ +/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/rebuild_cache.dir +/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/edit_cache.dir +/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/runner.dir diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/cmake.check_cache b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/cmake.check_cache new file mode 100644 index 00000000..3dccd731 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/progress.marks b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/progress.marks new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/progress.marks @@ -0,0 +1 @@ +2 diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/0_spec.cpp.o b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/0_spec.cpp.o new file mode 100644 index 00000000..40728620 Binary files /dev/null and b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/0_spec.cpp.o differ diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/CXX.includecache b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/CXX.includecache new file mode 100644 index 00000000..86031ab7 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/CXX.includecache @@ -0,0 +1,12 @@ +#IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">]) + +#IncludeRegexScan: ^.*$ + +#IncludeRegexComplain: ^$ + +#IncludeRegexTransform: + +/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/0_spec.cpp +iostream +- + diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/DependInfo.cmake b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/DependInfo.cmake new file mode 100644 index 00000000..68a53073 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/DependInfo.cmake @@ -0,0 +1,20 @@ +# The set of languages for which implicit dependencies are needed: +set(CMAKE_DEPENDS_LANGUAGES + "CXX" + ) +# The set of files for implicit dependencies of each language: +set(CMAKE_DEPENDS_CHECK_CXX + "/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/0_spec.cpp" "/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/runner.dir/0_spec.cpp.o" + ) +set(CMAKE_CXX_COMPILER_ID "GNU") + +# The include file search paths: +set(CMAKE_CXX_TARGET_INCLUDE_PATH + ) + +# Targets to which this target links. +set(CMAKE_TARGET_LINKED_INFO_FILES + ) + +# Fortran module output directory. +set(CMAKE_Fortran_TARGET_MODULE_DIR "") diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/build.make b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/build.make new file mode 100644 index 00000000..734aaf5b --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/build.make @@ -0,0 +1,98 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +# Delete rule output on recipe failure. +.DELETE_ON_ERROR: + + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + + +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build + +# Include any dependencies generated for this target. +include CMakeFiles/runner.dir/depend.make + +# Include the progress variables for this target. +include CMakeFiles/runner.dir/progress.make + +# Include the compile flags for this target's objects. +include CMakeFiles/runner.dir/flags.make + +CMakeFiles/runner.dir/0_spec.cpp.o: CMakeFiles/runner.dir/flags.make +CMakeFiles/runner.dir/0_spec.cpp.o: ../0_spec.cpp + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/runner.dir/0_spec.cpp.o" + /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/runner.dir/0_spec.cpp.o -c /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/0_spec.cpp + +CMakeFiles/runner.dir/0_spec.cpp.i: cmake_force + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/runner.dir/0_spec.cpp.i" + /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/0_spec.cpp > CMakeFiles/runner.dir/0_spec.cpp.i + +CMakeFiles/runner.dir/0_spec.cpp.s: cmake_force + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/runner.dir/0_spec.cpp.s" + /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/0_spec.cpp -o CMakeFiles/runner.dir/0_spec.cpp.s + +# Object files for target runner +runner_OBJECTS = \ +"CMakeFiles/runner.dir/0_spec.cpp.o" + +# External object files for target runner +runner_EXTERNAL_OBJECTS = + +runner: CMakeFiles/runner.dir/0_spec.cpp.o +runner: CMakeFiles/runner.dir/build.make +runner: CMakeFiles/runner.dir/link.txt + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable runner" + $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/runner.dir/link.txt --verbose=$(VERBOSE) + +# Rule to build all files generated by this target. +CMakeFiles/runner.dir/build: runner + +.PHONY : CMakeFiles/runner.dir/build + +CMakeFiles/runner.dir/clean: + $(CMAKE_COMMAND) -P CMakeFiles/runner.dir/cmake_clean.cmake +.PHONY : CMakeFiles/runner.dir/clean + +CMakeFiles/runner.dir/depend: + cd /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/runner.dir/DependInfo.cmake --color=$(COLOR) +.PHONY : CMakeFiles/runner.dir/depend + diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/cmake_clean.cmake b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/cmake_clean.cmake new file mode 100644 index 00000000..20ddb78d --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/cmake_clean.cmake @@ -0,0 +1,10 @@ +file(REMOVE_RECURSE + "CMakeFiles/runner.dir/0_spec.cpp.o" + "runner" + "runner.pdb" +) + +# Per-language clean rules from dependency scanning. +foreach(lang CXX) + include(CMakeFiles/runner.dir/cmake_clean_${lang}.cmake OPTIONAL) +endforeach() diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/depend.internal b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/depend.internal new file mode 100644 index 00000000..f59d63dc --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/depend.internal @@ -0,0 +1,5 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +CMakeFiles/runner.dir/0_spec.cpp.o + /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/0_spec.cpp diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/depend.make b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/depend.make new file mode 100644 index 00000000..cfc3a3f5 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/depend.make @@ -0,0 +1,5 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +CMakeFiles/runner.dir/0_spec.cpp.o: ../0_spec.cpp + diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/flags.make b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/flags.make new file mode 100644 index 00000000..5788ee6a --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/flags.make @@ -0,0 +1,10 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +# compile CXX with /usr/bin/c++ +CXX_FLAGS = -std=gnu++17 + +CXX_DEFINES = + +CXX_INCLUDES = + diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/link.txt b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/link.txt new file mode 100644 index 00000000..85e3155f --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/link.txt @@ -0,0 +1 @@ +/usr/bin/c++ CMakeFiles/runner.dir/0_spec.cpp.o -o runner diff --git a/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/progress.make b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/progress.make new file mode 100644 index 00000000..abadeb0c --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/CMakeFiles/runner.dir/progress.make @@ -0,0 +1,3 @@ +CMAKE_PROGRESS_1 = 1 +CMAKE_PROGRESS_2 = 2 + diff --git a/module-1/seminars/seminar21/type_traits/build/Makefile b/module-1/seminars/seminar21/type_traits/build/Makefile new file mode 100644 index 00000000..40ba7173 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/Makefile @@ -0,0 +1,178 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +# Default target executed when no arguments are given to make. +default_target: all + +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + + +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache + +.PHONY : rebuild_cache/fast + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." + /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache + +.PHONY : edit_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean + +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named runner + +# Build rule for target. +runner: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 runner +.PHONY : runner + +# fast build rule for target. +runner/fast: + $(MAKE) -f CMakeFiles/runner.dir/build.make CMakeFiles/runner.dir/build +.PHONY : runner/fast + +0_spec.o: 0_spec.cpp.o + +.PHONY : 0_spec.o + +# target to build an object file +0_spec.cpp.o: + $(MAKE) -f CMakeFiles/runner.dir/build.make CMakeFiles/runner.dir/0_spec.cpp.o +.PHONY : 0_spec.cpp.o + +0_spec.i: 0_spec.cpp.i + +.PHONY : 0_spec.i + +# target to preprocess a source file +0_spec.cpp.i: + $(MAKE) -f CMakeFiles/runner.dir/build.make CMakeFiles/runner.dir/0_spec.cpp.i +.PHONY : 0_spec.cpp.i + +0_spec.s: 0_spec.cpp.s + +.PHONY : 0_spec.s + +# target to generate assembly for a file +0_spec.cpp.s: + $(MAKE) -f CMakeFiles/runner.dir/build.make CMakeFiles/runner.dir/0_spec.cpp.s +.PHONY : 0_spec.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... rebuild_cache" + @echo "... edit_cache" + @echo "... runner" + @echo "... 0_spec.o" + @echo "... 0_spec.i" + @echo "... 0_spec.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/module-1/seminars/seminar21/type_traits/build/cmake_install.cmake b/module-1/seminars/seminar21/type_traits/build/cmake_install.cmake new file mode 100644 index 00000000..0e0d2323 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/build/cmake_install.cmake @@ -0,0 +1,49 @@ +# Install script for directory: /home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits + +# Set the install prefix +if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/usr/local") +endif() +string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + +# Set the install configuration name. +if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) + if(BUILD_TYPE) + string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" + CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") + else() + set(CMAKE_INSTALL_CONFIG_NAME "") + endif() + message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") +endif() + +# Set the component getting installed. +if(NOT CMAKE_INSTALL_COMPONENT) + if(COMPONENT) + message(STATUS "Install component: \"${COMPONENT}\"") + set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") + else() + set(CMAKE_INSTALL_COMPONENT) + endif() +endif() + +# Install shared libraries without execute permission? +if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) + set(CMAKE_INSTALL_SO_NO_EXE "1") +endif() + +# Is this installation the result of a crosscompile? +if(NOT DEFINED CMAKE_CROSSCOMPILING) + set(CMAKE_CROSSCOMPILING "FALSE") +endif() + +if(CMAKE_INSTALL_COMPONENT) + set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") +else() + set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") +endif() + +string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT + "${CMAKE_INSTALL_MANIFEST_FILES}") +file(WRITE "/home/morell/projects/HSE-Course-Private/module-1/lectures/lecture19/type_traits/build/${CMAKE_INSTALL_MANIFEST}" + "${CMAKE_INSTALL_MANIFEST_CONTENT}") diff --git a/module-1/seminars/seminar21/type_traits/build/runner b/module-1/seminars/seminar21/type_traits/build/runner new file mode 100644 index 00000000..b1979795 Binary files /dev/null and b/module-1/seminars/seminar21/type_traits/build/runner differ diff --git a/module-1/seminars/seminar21/type_traits/runner.py b/module-1/seminars/seminar21/type_traits/runner.py new file mode 100644 index 00000000..626ff948 --- /dev/null +++ b/module-1/seminars/seminar21/type_traits/runner.py @@ -0,0 +1,23 @@ +""" +CE checker +""" + +import os +import subprocess + + +def main(): + """ + CE checker + """ + for file_name in os.listdir(os.path.dirname(__file__)): + if file_name.endswith('cpp'): + process = subprocess.Popen(['g++', '-o', 'out', file_name], stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + _, err = process.communicate() + if err.decode('utf-8'): + print('CE: {}'.format(file_name)) + + +if __name__ == '__main__': + main() diff --git a/module-1/seminars/seminar22/.gitignore b/module-1/seminars/seminar22/.gitignore new file mode 100644 index 00000000..c795b054 --- /dev/null +++ b/module-1/seminars/seminar22/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/module-1/seminars/seminar22/0_consexpr_function.cpp b/module-1/seminars/seminar22/0_consexpr_function.cpp new file mode 100644 index 00000000..1f93dfe4 --- /dev/null +++ b/module-1/seminars/seminar22/0_consexpr_function.cpp @@ -0,0 +1,119 @@ +#include +#include + +// 0. parameter type and return type must be a literal type + +// CE: +constexpr std::string Foo() {return "Foo";}; + +// CE: +constexpr void Foo(std::string s) {}; + +// OK: +constexpr const char* Foo() {return "Foo";}; + +// CE: +constexpr void Foo(const char* s) {}; + +// The standard claims 1. it must not be virtual BEFORE: C++20 +// Actual: GCC 9.2.0: C++11 compiles +// Clang 9.0.0: C++11 fails +struct Foo { + // CE: + int32_t constexpr virtual Bar() {return 1;}; +}; + +// 2. The class must not have virtual base class +// Actual: GCC:9.2.0 C++11 compiles +// Clang 9.0.0: C++11 fails +struct Base {}; + +struct Derived : virtual Base { + // CE: + int32_t constexpr Bar() {return 1;}; +}; + +// 3. Single statement function body BEFORE: C++14 + +// OK!: +constexpr const char* IsEven(int32_t value) { + return (value % 2) != 0 ? "odd" : "even"; +} + +// CE: +constexpr const char* IsEven(int32_t value) { + if ((value % 2) != 0) { + return "odd"; + } else { + return "even"; + } +} + +// 3. C++14 gives us to use multiple statements in a function body +// OK! +constexpr const char* IsEven(int32_t value) { + if ((value % 2) != 0) { + return "odd"; + } else { + return "even"; + } +} + +// Constructor: function requirements + 4. +// 4. every BASE class non-static data member and every non-static data member must be initialized + +// Base class non-static data member +struct Base { + int32_t non_static_member; +}; + +struct Derived : Base { + constexpr Derived() = default; +}; + +void Foo() { + // CE: Base class non-static data member must be initialized + Derived d; +}; + + +struct Base { + int32_t non_static_member = 0; +}; + +struct Derived : Base { + constexpr Derived() = default; +}; + +void Foo() { + // OK!: + Derived d; +}; + +// Base class non-static data member + +struct Derived { + int32_t non_static_member = 0; + constexpr Derived() = default; +}; + +void Foo() { + // CE: class non-static data member must be initialized + Derived d; +}; + +struct Derived { + int32_t non_static_member = 0; + constexpr Derived() = default; +}; + +void Foo() { + // OK!: + Derived d; +}; + + +int main() { + + return 0; +} diff --git a/module-1/seminars/seminar22/0_constant_expressions.cpp b/module-1/seminars/seminar22/0_constant_expressions.cpp new file mode 100644 index 00000000..2877914c --- /dev/null +++ b/module-1/seminars/seminar22/0_constant_expressions.cpp @@ -0,0 +1,36 @@ +#include + +// Constant Expressions motivation: +// Pros: +// Similar to template metaprogramming but syntax much simpler and familiar with C++ +// Easy to maintain +// No runtime cost +// errors detection at compile time + +constexpr size_t Size() {return 1;} + +template +struct Array {}; + +int main() { + + const size_t size = 1; + + // constant expressions can be used as non-type template parameters + Array a1; + Array a2; + + // constant expressions can be used as array sizes + + // OK! + int32_t arr1[size]; + + // OK! + int32_t arr2[Size()]; + + // CE + int32_t cn = 0; + int32_t arr3[cn]; + + return 0; +} diff --git a/module-1/seminars/seminar22/0_constexpr_variable.cpp b/module-1/seminars/seminar22/0_constexpr_variable.cpp new file mode 100644 index 00000000..ea1fe35e --- /dev/null +++ b/module-1/seminars/seminar22/0_constexpr_variable.cpp @@ -0,0 +1,22 @@ +#include +#include + +int main() { + + // constexpr variable + + // 0. it must have a literal type + // CE: std::string is not a literal type + constexpr std::string s; + + // 1. it must be immediatly initialized + + // OK:! + constexpr int32_t x = 0; + + // CE: + constexpr int32_t y; + y = 0; + + return 0; +} diff --git a/module-1/seminars/seminar22/1_struct.cpp b/module-1/seminars/seminar22/1_struct.cpp new file mode 100644 index 00000000..259d96db --- /dev/null +++ b/module-1/seminars/seminar22/1_struct.cpp @@ -0,0 +1,12 @@ + +struct my_struct { + // combine static_assert with constexpr (self check) + static constexpr char who[] = "World"; + static_assert(who[0] == 'W', "OK!"); + static constexpr const char* a = &who[1]; + static_assert(*a == 'a', "FAIL: expected 'a'"); +}; + +int main() { + return 0; +} diff --git a/module-1/seminars/seminar22/2_core_f4.cpp b/module-1/seminars/seminar22/2_core_f4.cpp new file mode 100644 index 00000000..75829463 --- /dev/null +++ b/module-1/seminars/seminar22/2_core_f4.cpp @@ -0,0 +1,26 @@ +#include + + +// F.4: If a function might have to be evaluated at compile time, declare it constexpr + +constexpr int32_t Fac(int32_t n) { + int32_t x = 1; + for (int32_t i = 2; i <= n; ++i) { + x *= i; + } + return x; +} + +constexpr int32_t Min(int32_t x, int32_t y) { return x < y ? x : y; } + +void Test(int32_t v) { + int32_t m1 = Min(-1, 2); // probably compile-time evaluation + constexpr int32_t m2 = Min(-1, 2); // compile-time evaluation + int32_t m3 = Min(-1, v); // run-time evaluation + constexpr int32_t m4 = Min(-1, v); // error: cannot evaluate at compile time +} + +int main() { + Test(); + return 0; +} diff --git a/module-1/seminars/seminar22/CMakeLists.txt b/module-1/seminars/seminar22/CMakeLists.txt new file mode 100644 index 00000000..5e44bb1a --- /dev/null +++ b/module-1/seminars/seminar22/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.16) + +include(GoogleTest) + +project("runner") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +################ clang-tidy ################ +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--fix-errors;-header-filter=.") + +add_executable(runner 0_consexpr_function.cpp) + +################ clang-format ################ +list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake) +include(ClangFormat) +target_clangformat_setup(runner) \ No newline at end of file diff --git a/module-1/seminars/seminar23/.gitignore b/module-1/seminars/seminar23/.gitignore new file mode 100644 index 00000000..c795b054 --- /dev/null +++ b/module-1/seminars/seminar23/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/module-1/seminars/seminar23/0_min_element.cpp b/module-1/seminars/seminar23/0_min_element.cpp new file mode 100644 index 00000000..83a3410e --- /dev/null +++ b/module-1/seminars/seminar23/0_min_element.cpp @@ -0,0 +1,32 @@ +// Overloading allows to extend the domain of the function +// Problem: overloading does not give you facilities to change function semantic + +int* MinElement(int* first, int* last) { + if (first == last) { + return first; + } + int* min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + +double* MinElement(double* first, double* last) { + if (first == last) { + return first; + } + double* min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/10_min_element_requirements_extraction.cpp b/module-1/seminars/seminar23/10_min_element_requirements_extraction.cpp new file mode 100644 index 00000000..de973b0e --- /dev/null +++ b/module-1/seminars/seminar23/10_min_element_requirements_extraction.cpp @@ -0,0 +1,32 @@ + +#include +#include + +// Let's write down our requirements for Iter: +// 1. return first (Move constructible) +// 2. Iter min = first (Copy constructible) +// 3. min = first (CopyAssignable) +// 4. first == last (Equality) + + +// 5. ++first (Incrementable) +// 6. *first < *min (Dereferencable) + +template +Iter MinElement(Iter first, Iter last) { + if (first == last) { + return first; + } + Iter min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/11_min_element_concepts_extraction.cpp b/module-1/seminars/seminar23/11_min_element_concepts_extraction.cpp new file mode 100644 index 00000000..79090331 --- /dev/null +++ b/module-1/seminars/seminar23/11_min_element_concepts_extraction.cpp @@ -0,0 +1,27 @@ + +#include +#include + +// Let's write down our concepts +// Concepts for Iter: +// -Regular +// -ForwardIterator + +template +Iter* MinElement(Iter* first, Iter* last) { + if (first == last) { + return first; + } + Iter* min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/12_min_element_concept_implementation.cpp b/module-1/seminars/seminar23/12_min_element_concept_implementation.cpp new file mode 100644 index 00000000..68a2ff35 --- /dev/null +++ b/module-1/seminars/seminar23/12_min_element_concept_implementation.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +// Concepts as constraints +// Anything template argument must satisfy the syntactic and semantic requirement of ForwardIterator +// -Regular +// -Incrementable +// -Dereferencable + + +// Application benefit: we can use a constrained declration (here we talk about the moment of a template instantiation) +// if is constraints are satisfied +// Example: MinElement(1, 2) <- instantiation of the MinElement with pair of ints -> +// -> Instantiation fails because T=int does not satisfy one of the ForwardIterator requirement: +// an object of T must be dereferenceable + +template +concept forward_iterator = + std::equality_comparable && requires(I i) { + typename std::incrementable_traits::difference_type; + typename std::indirectly_readable_traits::value_type; + typename std::common_reference_t&&, + typename std::indirectly_readable_traits::value_type&>; + *i++; + typename std::common_reference_t::value_type&>; + requires std::signed_integral::difference_type>; + }; + +template +requires forward_iterator && std::totally_ordered +Iter MinElement(Iter first, Iter last) { + if (first == last) { + return first; + } + Iter min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + +int main() { + int32_t p[] = {10, 1, 2}; + std::vector v{10, -1, 2}; + // OK: + std::cout << *MinElement(p, p+2) << std::endl; + // OK: + std::cout << *MinElement(v.begin(), v.end()) << std::endl; + // CE: the required expression '*(i ++)' is invalid (i is an object of int) + //std::cout << MinElement(1, 2) << std::endl; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/13_min_element_concept_alternative_impl.cpp b/module-1/seminars/seminar23/13_min_element_concept_alternative_impl.cpp new file mode 100644 index 00000000..7e9116bf --- /dev/null +++ b/module-1/seminars/seminar23/13_min_element_concept_alternative_impl.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +template +concept forward_iterator = + std::equality_comparable && requires(I i) { + typename std::incrementable_traits::difference_type; + typename std::indirectly_readable_traits::value_type; + typename std::common_reference_t&&, + typename std::indirectly_readable_traits::value_type&>; + *i++; + typename std::common_reference_t::value_type&>; + requires std::signed_integral::difference_type>; + }; + +// It is more convenient to move forward_iterator to the template parameter list +template +requires std::totally_ordered +Iter MinElement(Iter first, Iter last) { + if (first == last) { + return first; + } + Iter min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + +int main() { + int32_t p[] = {10, 1, 2}; + std::vector v{10, -1, 2}; + // OK: + std::cout << *MinElement(p, p+2) << std::endl; + // OK: + std::cout << *MinElement(v.begin(), v.end()) << std::endl; + // CE: the required expression '*(i ++)' is invalid (i is an object of int) + //std::cout << MinElement(1, 2) << std::endl; + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/14_overconstraining_overgeneralizing.cpp b/module-1/seminars/seminar23/14_overconstraining_overgeneralizing.cpp new file mode 100644 index 00000000..9d65c22e --- /dev/null +++ b/module-1/seminars/seminar23/14_overconstraining_overgeneralizing.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +int main() { + // We should not expose implementation details + // We should find generic constraints and expose them + + + // Overconstraining is not a bad thing: + // 1. start with abstractions that have strong requirements + // 2. allows greater freedom in implementation details + + + // We should not overgeneralizing templates + // 1. weaker semantics; make it harder to reason about the behavior + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/15_what_we_can_constrain.cpp b/module-1/seminars/seminar23/15_what_we_can_constrain.cpp new file mode 100644 index 00000000..e9ada9b1 --- /dev/null +++ b/module-1/seminars/seminar23/15_what_we_can_constrain.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include + +// Constraining classes +template +concept ObjectType = std::is_object::value; +template > +class Vector { + +}; + +void VectorExmaple() { + // OK! + Vector v1; + + // CE: template constraint failure for 'template requires ObjectType class Vector' + // Vector v2; + + // CE: template constraint failure for 'template requires ObjectType class Vecto + // Vector* p; +} + +// Constrainting variable templates +template +concept FloatingPoint = std::is_floating_point_v; +template T pi = 3.1451; + +void VariableExample() { + std::cout << pi << std::endl; + std::cout << pi << std::endl; +} + +// Constraining alias templates +template +using VectorAlias = std::vector; + +void AliasExample() { + VectorAlias v; + + // CE: error: template constraint failure for 'template requires ObjectType + // VectorAlias v; +} + +template +concept ConvertibleTo = + std::is_convertible_v && + requires(std::add_rvalue_reference_t (&f)()) { + static_cast(f()); + }; + +// Constraining template members +template +struct Pair { + template X, ConvertibleTo Y> + Pair(const X& x, const Y& y) : + first(x), + second(y) + {} + + T first; + U second; +}; + +void TemplateMembersExample() { + // OK! + Pair p1('a', 'b'); + // CE: + Pair p2(nullptr, 0); +} + + +// Non-template members +// Non-template members +template +concept Copyable = + std::copy_constructible && + std::movable && + std::assignable_from && + std::assignable_from && + std::assignable_from; + +template +struct Pair { + Pair() = default; + + Pair(const Pair& p) requires Copyable && Copyable + : first(p.first), second(p.second) {}; + T first; + U second; +}; + +void NonTemplateMembersExample() { + Pair, int> p1; + // CE: required for the satisfaction of 'copy_constructible' [with T = std::unique_ptr, int> p2{p1}; +} + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/16_specializations.cpp b/module-1/seminars/seminar23/16_specializations.cpp new file mode 100644 index 00000000..63ac30c6 --- /dev/null +++ b/module-1/seminars/seminar23/16_specializations.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +// We need to implement RandomAccessContainer concept ... + +// type-based specialization - we overload operations for specific types +// that have more efficient implementation strategies +template +void Sort(Cont& vec) { + std::sort(vec.begin(), vec.end()); +} + +template > +void Sort(std::list& lst) { + std::vector vec(lst.begin(), lst.end()); + std::sort(vec.begin(), vec.end()); + std::copy(vec.begin(), vec.end(), lst.begin()); +} + +// concept-based specialization - overload operations for concepts with more stronger requirements +// Example: BidirectionalIterator refines ForwardIterator + +// We need to implement InputIterator concept... + +template +int Distance(Iter first, Iter last) { + int n = 0; + while (first != last) { + ++n; + } + return n; +} + +// We need to implement InputIterator concept... + +template +int Distance(Iter first, Iter last) { + return last - first; +} + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/1_min_element.cpp b/module-1/seminars/seminar23/1_min_element.cpp new file mode 100644 index 00000000..f67162b0 --- /dev/null +++ b/module-1/seminars/seminar23/1_min_element.cpp @@ -0,0 +1,19 @@ +double* MinElement(double* first, double* last) { + if (first == last) { + return first; + } + double* min = first; + while (++first != last) { + // Problem: comparing double not actually get defined behaviour + // Reason: floating point numbers have not a number + // Solution: add restrictions + if (*first < *min) { + min = first; + } + } + return min; +} + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/2_min_element_ptr.cpp b/module-1/seminars/seminar23/2_min_element_ptr.cpp new file mode 100644 index 00000000..2e82a4c0 --- /dev/null +++ b/module-1/seminars/seminar23/2_min_element_ptr.cpp @@ -0,0 +1,20 @@ +int** MinElement(int** first, int** last) { + if (first == last) { + return first; + } + int** min = first; + while (++first != last) { + // We have some difficulties in interpretation of the expression (*first < *min) + if (*first < *min) { + min = first; + } + } + return min; +} + +// Conclusion: we take a single algorithm and extended it a bunch of times -> now we have different domains +// we have figure out how all of it fits same syntactic pattern -> we can make it generic + +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/4_min_element_auto.cpp b/module-1/seminars/seminar23/4_min_element_auto.cpp new file mode 100644 index 00000000..2550e51b --- /dev/null +++ b/module-1/seminars/seminar23/4_min_element_auto.cpp @@ -0,0 +1,26 @@ +// You want your code more generic? +#include +#include + +// Auto to the rescue +// This algorithm is overly general! +auto MinElement(auto first, auto last) { + if (first == last) { + return first; + } + auto min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + +int main() { + int a[] = {5, 4, -1, 1, 2}; + int* p = MinElement(a, a + 5); + assert(p == &a[2]); + std::cout << *(p); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/5_min_element_template_parameter.cpp b/module-1/seminars/seminar23/5_min_element_template_parameter.cpp new file mode 100644 index 00000000..566b4f61 --- /dev/null +++ b/module-1/seminars/seminar23/5_min_element_template_parameter.cpp @@ -0,0 +1,29 @@ +#include +#include + +// What about to introduce the template parameter? +// And this algorithm is still overly generic + +// Problem: we cannot say what can be under the Iter + +template +Iter MinElement(Iter first, Iter last) { + if (first == last) { + return first; + } + Iter min = first; + while (++first != last) { + if (*first < *min) { + min = first; + } + } + return min; +} + +int main() { + int a[] = {5, 4, -1, 1, 2}; + int* p = MinElement(a, a + 5); + assert(p == &a[2]); + std::cout << *(p); + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/6_vector_ref.cpp b/module-1/seminars/seminar23/6_vector_ref.cpp new file mode 100644 index 00000000..24d0cc4f --- /dev/null +++ b/module-1/seminars/seminar23/6_vector_ref.cpp @@ -0,0 +1,28 @@ + +#include +#include + +int main() { + std::vector vec; + + // CE: + // Reason: ptr to a reference; but ... this is a symptom + // with gcc 10.1.0 you will see + // /opt/wandbox/gcc-10.1.0/include/c++/10.1.0/bits/alloc_traits.h:416:13: error: forming pointer to reference type 'int&' + // 416 | using pointer = _Tp*; + // + // Yes, the output to the terminal is long, but if you search, you will find the line with error message =) + // + // Fundamental reason: "int32_t& IS NOT AN OBJECT" + + // What do we want? + // We want: to see the following error message "int& IS NOT AN OBJECT" + + // How will we solve the problem? + // Concepts to the rescue! + // 1. Declare concept + // 2. Put the concept to the requirements for the type when you write your container + + // Note: Concepts can't customize error messages yet, but they still will help us + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/7_syntactic_semantic_requirements.cpp b/module-1/seminars/seminar23/7_syntactic_semantic_requirements.cpp new file mode 100644 index 00000000..1e110b17 --- /dev/null +++ b/module-1/seminars/seminar23/7_syntactic_semantic_requirements.cpp @@ -0,0 +1,21 @@ + +#include +#include + +int main() { + // What is a concept? + // A named predicate expressing requirements on template arguments + // Syntactic requirements - what operations, associated types are needed + // Semantic requirements - behaviours are required of operations + // Complexity requirements - perfomance requirements of operations + + // Ex. ForwardIterator: + // For some value i - this is semantic requirement + // Syntactic requirement: "++i" must be correct expression + // Semantic requirement: + // 1. when you make ++ "i" moves to the next element + // 2. you can dereference "i" to access an element in the range unless + // it's the last element in the range + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/8_language_construction.cpp b/module-1/seminars/seminar23/8_language_construction.cpp new file mode 100644 index 00000000..93ef3f79 --- /dev/null +++ b/module-1/seminars/seminar23/8_language_construction.cpp @@ -0,0 +1,12 @@ + +#include +#include + +int main() { + // What meaningful construction do we want to add to the language so that it can be used? + // our consciousness tells us: + // ForwardIterator + // if T models ForwardIterator requirements -> return yes + // if T does not model ForwardIterator requirements -> return no + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/9_operations_for _concept.cpp b/module-1/seminars/seminar23/9_operations_for _concept.cpp new file mode 100644 index 00000000..766b2a0c --- /dev/null +++ b/module-1/seminars/seminar23/9_operations_for _concept.cpp @@ -0,0 +1,13 @@ + +#include +#include + +int main() { + // A constraint is a logical expression, that says if we can use a type with a template + // (conjunction or disjunction) + + // Also we want to compose our concepts -> thus we need add && + MutableIterator = ForwardIterator && OutputIterator + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar23/CMakeLists.txt b/module-1/seminars/seminar23/CMakeLists.txt new file mode 100644 index 00000000..2b488911 --- /dev/null +++ b/module-1/seminars/seminar23/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project("runner") + +add_executable(runner 0_spec) \ No newline at end of file diff --git a/module-1/seminars/seminar23/intro.cpp b/module-1/seminars/seminar23/intro.cpp new file mode 100644 index 00000000..99fbd75a --- /dev/null +++ b/module-1/seminars/seminar23/intro.cpp @@ -0,0 +1,19 @@ +// The C+20 concept library is not supported by all compilers (01.04.2021) +// LLVM: +// std::totally_ordered was added 02.04.2021 (https://github.com/llvm/llvm-project/commit/7959d59028dd126416cdf10dbbd22162922e1336) +// thus clang 13.0.0 HEAD(fcdf7f6224610a51dc2ff47f2f1e3377329b64a7) +// does not support std::totally_ordered https://github.com/llvm/llvm-project/commit/fcdf7f6224610a51dc2ff47f2f1e3377329b64a7 +// +// GCC: +// std::totally_ordered was add may in 2020: +// https://github.com/gcc-mirror/gcc/commit/c9313582d82e0768a3a68250dc97d82a9ad3c116#diff-d31b758993c80e8ffbae4f72d59f9b40674080760ff2d7092a9bb2107d5c9786 +// +// +// C++20 contracts (expects, ensures, assert) is not supported by any compiler (01.04.2021) +// Standard: https://doc.bccnsoft.com/docs/cppreference2018/en/cpp/language/attributes/contract.html +// There is a custom implementation for clang and proposal to clang: +// Proposal: https://llvm.org/devmtg/2019-04/slides/Poster-Lopez-Gomez-Adding_support_for_C++_contracts_to_Clang.pdf +// Implementation: https://github.com/arcosuc3m/clang-contracts/ +int main() { + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar3/README.md b/module-1/seminars/seminar3/README.md new file mode 100644 index 00000000..7b6b27c1 --- /dev/null +++ b/module-1/seminars/seminar3/README.md @@ -0,0 +1,5 @@ +# Seminar + +Разобран паттерн [Flyweight](https://refactoring.guru/design-patterns/flyweight). + +Реализовали [пример](https://refactoring.guru/design-patterns/flyweight/cpp/example) \ No newline at end of file diff --git a/module-1/seminars/seminar4/README.md b/module-1/seminars/seminar4/README.md new file mode 100644 index 00000000..113d9a49 --- /dev/null +++ b/module-1/seminars/seminar4/README.md @@ -0,0 +1,31 @@ +# Seminar + +Разобран паттерн [Builder](https://refactoring.guru/design-patterns/builder) + +Код не сохранился + +Формулировка задачи: + + +Требуется на карте отслеживать: +* расположение имеющихся поездов +* поезда из 8 вагонов +* отслеживание по координатам головного вагона +* система координат локальная: считаем землю плоской +* начало отсчета от красной площади + +Начинаем создавать инфраструктуру, описывающую задачу: классы и логику их взаимодействия + +Каждый Builder переопределяет методы для: +* построения сидений +* построения окон +* построение крыши +* построение колеса + +Иерархия вагонов: +* головной +* обычный + +Замечание: +* поезд хранит список вагонов и координаты головного +* builder собирает вагон по частям далее вагон добавляется в поезд diff --git a/module-1/seminars/seminar5/README.md b/module-1/seminars/seminar5/README.md new file mode 100644 index 00000000..5732725a --- /dev/null +++ b/module-1/seminars/seminar5/README.md @@ -0,0 +1,28 @@ +# Seminar + +Разобран паттерн [Composite](https://refactoring.guru/design-patterns/builder) + +Код не сохранился + +Формулировка задачи: + +Иерархия: Managing Director <- Senior VP <- VP <- Banking Associate <- Banking Analyst + +Классы облажают методами: +* Banking Analyst: +* MakePresentation +* GetCompanyIndicator + +Banking Associate: +* GatherCompaniesIndicators +* PutCompanyIndicator + +VP: +* PreparePitchBook + +Senior VP: +* PrepareMeeting + +ManagingDir: +* DrinkCoffee +* Deadline: пробрасывает сообщение подчиненным -> вызывает DrinkCoffee \ No newline at end of file diff --git a/module-1/seminars/seminar6-8/README.md b/module-1/seminars/seminar6-8/README.md new file mode 100644 index 00000000..6730ed9e --- /dev/null +++ b/module-1/seminars/seminar6-8/README.md @@ -0,0 +1,6 @@ +# Seminar + +Разобран паттерны: +* [Mediator](https://refactoring.guru/design-patterns/builder) +* [Composite](https://refactoring.guru/design-patterns/composite) +* [Prototype](https://refactoring.guru/design-patterns/prototype) \ No newline at end of file diff --git a/module-1/seminars/seminar6-8/mediator.cpp b/module-1/seminars/seminar6-8/mediator.cpp new file mode 100644 index 00000000..0d5d7d3c --- /dev/null +++ b/module-1/seminars/seminar6-8/mediator.cpp @@ -0,0 +1,177 @@ +#include +#include +#include +#include +#include +#include + + +class Worker; + +enum Commands { + LOAD, + SORT, + PRINT +}; + +class Mediator { +public: + virtual void Notify(Worker* worker, Commands cmd) const = 0; +}; + +class Worker { +public: + Worker() : mediator(nullptr) {}; + + void SetMediator(Mediator* mediator); + +protected: + Mediator* mediator; +}; + +void Worker::SetMediator(Mediator* mediator) { + this->mediator = mediator; +} + +class SortingWorker : public Worker { +public: + virtual void Sort(std::vector& v) = 0; +}; + +class QuickSortWorker : public SortingWorker { +public: + void Sort(std::vector& v) override { + + qsort(v, 0, v.size()); + + mediator->Notify(this, SORT); + } +private: + void qsort(std::vector& v, std::size_t left, std::size_t right) { + if ( left < right ) { + std::size_t pos = Partition(v, left, right); + qsort(v, left, pos); + qsort(v, pos + 1, right); + } + } + int Partition(std::vector& v, std::size_t left, std::size_t right) { + std::size_t pivot = v[static_cast(left + right) / 2]; + std::size_t i = left; + std::size_t j = right; + + while (i <= j ) { + while (v[i] < pivot) { + i++; + } + while (v[j] > pivot) { + j--; + } + + if (i >= j) { + break; + } + std::swap(v[i++], v[j--]); + } + } +}; + +class Decorator : public SortingWorker { + protected: + SortingWorker* component; + + public: + Decorator(SortingWorker* component) : component(component) {} + void Sort(std::vector& v) { + component->Sort(v); + } +}; + +class TimerDecorator : public Decorator { + public: + TimerDecorator(QuickSortWorker* component) : Decorator(component) {} + void Sort(std::vector& v) { + auto start = std::chrono::high_resolution_clock::now(); + Decorator::Sort(v); + auto finish = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = finish - start; + std::cout << elapsed.count() << std::endl; + } +}; + +class DataLoaderWorker : public Worker { +public: + DataLoaderWorker(std::filesystem::path& path) : path_(std::move(path)) {} + + void Load() { + std::cout << "Load:completed" << std::endl; + std::fstream fs; + fs.open(this->path_); + int num; + fs >> num; + while (!fs.eof() && fs >> num) { + v.push_back(num); + } + mediator->Notify(this, LOAD); + } + + std::vector& Get() { + return v; + } + +private: + std::filesystem::path path_; + std::vector v; +}; + +class PrinterWorker : public Worker { +public: + void Print(const std::vector& v) { + std::cout << "Print:completed" << std::endl; + for (auto x: v) { + std::cout << x << std::endl; + } + } +}; + +class SortMediator : public Mediator { +public: + SortMediator(DataLoaderWorker* dataloader, SortingWorker* sorter, PrinterWorker* printer) : + dataloader(dataloader), + sorter(sorter), + printer(printer) { + dataloader->SetMediator(this); + sorter->SetMediator(this); + printer->SetMediator(this); + }; + + void Notify(Commands cmd) const override { + switch (cmd) { + case Commands::LOAD: { + sorter->Sort(dataloader->Get()); + break; + } + case Commands::SORT: { + printer->Print(dataloader->Get()); + break; + } + } + } +private: + DataLoaderWorker* dataloader; + SortingWorker* sorter; + PrinterWorker* printer; +}; + +// int main() { + +// std::filesystem::path path = "./input.txt"; +// DataLoaderWorker* dataloader = new DataLoaderWorker(path); +// SortingWorker* qsort_worker = new QuickSortWorker; +// PrinterWorker* print_worker = new PrinterWorker; +// Decorator* qsort_docrator = new Decorator(qsort_worker); + +// SortMediator* qsort_mediator = new SortMediator(dataloader, qsort_docrator, print_worker); +// dataloader->Load(); + +// return 0; +// } \ No newline at end of file diff --git a/module-1/seminars/seminar6-8/observer.cpp b/module-1/seminars/seminar6-8/observer.cpp new file mode 100644 index 00000000..f5321f37 --- /dev/null +++ b/module-1/seminars/seminar6-8/observer.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +struct Person { + std::string name; + + Person(std::string& name_) : name(std::move(name_)) {} +}; + +struct Order { + std::string name; + + Order(std::string& name_) : name(std::move(name_)) {} +}; + +struct KFCOrder : public Order {}; + +struct McDonaldsOrder : public Order {}; + +class Restourant { + public: + Restourant() = delete; + + private: + std::unordered_map orders; +}; + +class KFC : public Restourant { + +}; + +class McDonalds : public Restourant { + +}; + + +int main() { + + return 0; +} \ No newline at end of file diff --git a/module-1/seminars/seminar6-8/prototype.cpp b/module-1/seminars/seminar6-8/prototype.cpp new file mode 100644 index 00000000..809030ae --- /dev/null +++ b/module-1/seminars/seminar6-8/prototype.cpp @@ -0,0 +1,137 @@ + +// прототип объектов, которые не требуется часто создавать, но надо получать +#include +#include +#include + +enum SquareFigureName { + STAR +}; + +const char* enum_name2string_name[] = { + "STAR", + "a" +}; + +class SquareFigure; +std::ostream& operator<<(std::ostream& out, const SquareFigure& prot); + +class SquareFigure { +public: + + SquareFigure(const char _symbol, int _width, unsigned short int _height) : + symbol(_symbol), + width( _width), + height(_height) {}; + + virtual ~SquareFigure() = default; + + virtual SquareFigure* Clone() const = 0; + + int GetWidth() const { return width; } + unsigned short int GetHeight() const { return height; } + const char GetSymbol() const { return symbol; } + void Print() { + std::cout << (*this); + } + +protected: + const char symbol; + const unsigned short int height; + int width; +}; + +std::ostream& operator<<(std::ostream& out, const SquareFigure& prot) { + for (unsigned short int i = 0; i < prot.GetHeight(); i++) { + out << std::string(prot.GetWidth(), prot.GetSymbol()); + out.put('\n'); + } + return out; +} + +class StarSquareFigure : public SquareFigure { +public: + + StarSquareFigure(int _width, unsigned short int _height) : SquareFigure('*', _width, _height) {} + + SquareFigure* Clone() const override { + return new StarSquareFigure(*this); + } +}; + +class SquareFigureFactory { +private: + std::unordered_map> name2figure; + +public: + SquareFigureFactory() { + name2figure[SquareFigureName::STAR] = nullptr; + } + + void SetPrototype(SquareFigureName name, SquareFigure* figure) { + std::cout << "SquareFigure Name:" << enum_name2string_name[name] << " width:" << figure->GetWidth() << " setted!" << std::endl; + name2figure[name] = figure; + } + + SquareFigure* CreateSquareFigure(SquareFigureName name) { + std::cout << "SquareFigure Name:" << enum_name2string_name[name] << " created!" << std::endl; + return name2figure[name]->Clone(); + } + + ~SquareFigureFactory() { + if ( name2figure[SquareFigureName::STAR] ) { + delete name2figure[SquareFigureName::STAR]; + } + } +}; + +class SquareFigureProxy : public StarSquareFigure { +public: + ~SquareFigureProxy() { + if (fig) { + delete fig; + } + } + + void Print() { + if (hasSquareFigure()) { + fig->Print(); + return; + } + std::cout << "No figure setted!" << std::endl; + setDefault(); + } + + void SetFigure(StarSquareFigure* _fig) { + std::cout << "Proxy: upd!" << std::endl; + fig = _fig; + } + +private: + bool hasSquareFigure() { + return fig != nullptr; + } + + void setDefault() { + std::cout << "Default setted!" << std::endl; + fig = new StarSquareFigure(3, 3); + } + + StarSquareFigure* fig = nullptr; +}; + +int main() { + SquareFigureFactory factory; + SquareFigure* fig1 = new StarSquareFigure(2, 3); + + factory.SetPrototype(SquareFigureName::STAR, fig1); + + std::cout << *fig1 << std::endl; + SquareFigure* fig1_clone = factory.CreateSquareFigure(SquareFigureName::STAR); + + std::cout << "Clone Printed:" << std::endl; + std::cout << *fig1_clone; + + SquareFigureProxy p(); + return 0; +} \ No newline at end of file