-
Notifications
You must be signed in to change notification settings - Fork 24
Lesson 27 09 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Lesson 27 09 #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| void Bar() {} | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,26 @@ | ||||||
| #include <bits/atomic_wait.h> | ||||||
| #include <iostream> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: included header atomic_wait.h is not used directly [misc-include-cleaner]
Suggested change
|
||||||
|
|
||||||
| int main() { return 0; } | ||||||
| #include "utils.hpp" | ||||||
|
|
||||||
| int main() { | ||||||
| utils::IntArray a(10); | ||||||
|
|
||||||
| for (int i = 0; i < a.GetSize(); ++i) { | ||||||
| a[i] = i; | ||||||
| } | ||||||
|
|
||||||
| int sum = 0; | ||||||
| for (int i = 0; i < a.GetSize(); ++i) { | ||||||
| sum += a[i]; | ||||||
| } | ||||||
|
|
||||||
| std::cout << sum << '\n'; | ||||||
|
|
||||||
| utils::IntArray adda; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: call to deleted constructor of 'utils::IntArray' [clang-diagnostic-error] utils::IntArray adda;
^Additional contextsandbox/template/src/utils.hpp:16: 'IntArray' has been explicitly marked deleted here IntArray() = delete;
^ |
||||||
| utils::IntArray b(1, 1); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'b' of type 'utils::IntArray' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
|
|
||||||
| { utils::IntArray a; } | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: call to deleted constructor of 'utils::IntArray' [clang-diagnostic-error] { utils::IntArray a; }
^Additional contextsandbox/template/src/utils.hpp:16: 'IntArray' has been explicitly marked deleted here IntArray() = delete;
^ |
||||||
|
|
||||||
| return 0; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1 +1,52 @@ | ||||||
| #include "utils.hpp" | ||||||
| #include <climits> | ||||||
| #include <cstddef> | ||||||
| #include <iostream> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: included header cstddef is not used directly [misc-include-cleaner]
Suggested change
|
||||||
| #include <stdexcept> | ||||||
|
|
||||||
| namespace utils { | ||||||
|
|
||||||
| // IntArray::IntArray() : data_(nullptr), size_(0), bar("Bar"), foo() { | ||||||
| // std::cout << "IntArray::IntArray()\n"; | ||||||
| // } | ||||||
|
|
||||||
| IntArray::IntArray(int size) : foo(size), bar("Bar") { | ||||||
| std::cout << "IntArray::IntArray(int size = " << size << ")\n "; | ||||||
| data_ = new int[size]; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'data_' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer] sandbox/template/src/utils.cpp:12: - IntArray::IntArray(int size) : foo(size), bar("Bar") {
+ IntArray::IntArray(int size) : foo(size), bar("Bar"), data_(new int[size]) {
Suggested change
|
||||||
| size_ = size; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'size_' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer] sandbox/template/src/utils.cpp:12: - IntArray::IntArray(int size) : foo(size), bar("Bar") {
+ IntArray::IntArray(int size) : foo(size), bar("Bar"), size_(size) {
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| IntArray::IntArray(int num, int size) { | ||||||
| std::cout << "IntArray::IntArray(int num = " << num << "int size " << size | ||||||
| << ")\n"; | ||||||
| data_ = new int[size]; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'data_' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer] sandbox/template/src/utils.cpp:18: - IntArray::IntArray(int num, int size) {
+ IntArray::IntArray(int num, int size) : data_(new int[size]) {
Suggested change
|
||||||
| size_ = size; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'size_' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer] sandbox/template/src/utils.cpp:18: - IntArray::IntArray(int num, int size) {
+ IntArray::IntArray(int num, int size), size_(size) {
Suggested change
|
||||||
| for (int i = 0; i < size; ++i) { | ||||||
| data_[i] = num; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| IntArray::~IntArray() { | ||||||
| Clear(); | ||||||
| std::cout << "IntArray::~IntArray()\n"; | ||||||
| } | ||||||
|
|
||||||
| int IntArray::GetSize() const { return size_; } | ||||||
|
|
||||||
| bool IntArray::IsEmpty() const { return !size_; } | ||||||
|
|
||||||
| int &IntArray::operator[](int index) { | ||||||
| if (index < 0) | ||||||
| throw std::out_of_range("index is negative"); | ||||||
| if (index >= size_) | ||||||
| throw std::out_of_range("index is too big"); | ||||||
| return data_[index]; | ||||||
| } | ||||||
|
|
||||||
| void IntArray::Clear() { | ||||||
| delete[] data_; | ||||||
| data_ = nullptr; | ||||||
| size_ = 0; | ||||||
| } | ||||||
|
|
||||||
| } // namespace utils | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,39 @@ | ||
| #pragma once | ||
|
|
||
| #include <iostream> | ||
|
|
||
| namespace utils { | ||
|
|
||
| class Foo { | ||
| public: | ||
| Foo() { std::cout << "Foo()\n"; } | ||
| Foo(int) { std::cout << "Foo(int)\n"; } | ||
| Foo(const std::string &s) { std::cout << s << "(string)\n"; } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "std::string" is directly included [misc-include-cleaner] sandbox/template/src/utils.hpp:3: + #include <string> |
||
| ~Foo() { std::cout << "~Foo()\n"; } | ||
| }; | ||
|
|
||
| class IntArray { | ||
| public: | ||
| IntArray() = delete; | ||
| IntArray(int size); | ||
| IntArray(int num, int size); | ||
| ~IntArray(); | ||
|
|
||
| int GetSize() const; | ||
|
|
||
| bool IsEmpty() const; | ||
|
|
||
| void Resize(int size); | ||
|
|
||
| int &operator[](int index); | ||
|
|
||
| void Clear(); | ||
|
|
||
| private: | ||
| Foo foo; | ||
| Foo bar; | ||
| int *data_; | ||
| int size_; | ||
| }; | ||
|
|
||
| } // namespace utils | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { return 0; } | ||
| int main() { | ||
| std::cout << "Hello, world!\n"; | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||||||||||||
| #include "sum.hpp" | ||||||||||||||
|
|
||||||||||||||
| int Sum(int first_number, int second_number, int third_number) { return 6; } | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 'first_number' is unused [misc-unused-parameters]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 'second_number' is unused [misc-unused-parameters]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: parameter 'third_number' is unused [misc-unused-parameters]
Suggested change
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| int Sum(int first_number, int second_number, int third_number) { return 6; } | ||
| int Sum(int first_number, int second_number, int third_number); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| cmake_minimum_required(VERSION 3.10) | ||
|
|
||
| get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) | ||
| string(REPLACE " " "_" PROJECT_NAME ${PROJECT_NAME}) | ||
| project(${PROJECT_NAME} C CXX) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
|
||
| file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp") | ||
| file(GLOB_RECURSE lib_source_list "../lib/src/*.cpp" "../lib/src/*.hpp") | ||
| file(GLOB_RECURSE main_source_list "src/main.cpp") | ||
| file(GLOB_RECURSE test_source_list "src/*.cpp") | ||
| file(GLOB_RECURSE test_list "src/*test.cpp") | ||
|
|
||
| list(REMOVE_ITEM test_source_list ${main_source_list}) | ||
| list(REMOVE_ITEM source_list ${test_list}) | ||
|
|
||
| include_directories(${PROJECT_NAME} PUBLIC src) | ||
| include_directories(${PROJECT_NAME} PUBLIC ../lib/src) | ||
|
|
||
| add_executable(${PROJECT_NAME} ${source_list}) | ||
| target_link_libraries(${PROJECT_NAME} PUBLIC Utils) | ||
|
|
||
| # Locate GTest | ||
| enable_testing() | ||
| find_package(GTest REQUIRED) | ||
| include_directories(${GTEST_INCLUDE_DIRS}) | ||
|
|
||
| # Link runTests with what we want to test and the GTest and pthread library | ||
| add_executable(${PROJECT_NAME}_tests ${test_source_list}) | ||
| target_link_libraries( | ||
| ${PROJECT_NAME}_tests | ||
| GTest::gtest_main | ||
| Utils | ||
| ) | ||
|
|
||
| include(GoogleTest) | ||
| gtest_discover_tests(${PROJECT_NAME}_tests) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Сдвиг элементов | ||
|
|
||
| Создайте функцию, которая принимает указатель на массив целых чисел, его размер, и целое число N. Функция должна сдвинуть все элементы массива на N позиций вправо, чтобы первые элементы стали последними. Элементы, которые "выталкиваются" из массива, должны появиться с левой стороны. |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||
| #include <iostream> | ||||
|
|
||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: included header iostream is not used directly [misc-include-cleaner]
Suggested change
|
||||
| int main() { return 0; } | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| TEST(TopologySort, Simple) { | ||
| ASSERT_EQ(1, 1); // Stack [] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'Bar' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
Additional context
sandbox/template/src/foo.hpp:2: make as 'inline'