Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions homework/transform-containers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
Expand All @@ -18,7 +18,8 @@ FetchContent_MakeAvailable(googletest)
project(transformContainers)
enable_testing()

add_executable(${PROJECT_NAME}-ut test.cpp) # add your cpp file here after test.cpp
add_executable(${PROJECT_NAME} main.cpp)
add_executable(${PROJECT_NAME}-ut test.cpp transform_containers.cpp) # add your cpp file here after test.cpp
# if this is problematic take a look into CMakeLists.txt files in other exercises

add_compile_options(${PROJECT_NAME}-ut -Wall -Wextra -Wconversion -pedantic -Werror)
Expand Down
5 changes: 5 additions & 0 deletions homework/transform-containers/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "transform_containers.hpp"

int main() {
return 0;
}
1 change: 1 addition & 0 deletions homework/transform-containers/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gtest/gtest.h"

// TODO: add proper includes
#include "transform_containers.hpp"

TEST(transformContainerTests, ShouldReturnUniqueMap) {
std::map<int, std::string> expected_result{
Expand Down
19 changes: 19 additions & 0 deletions homework/transform-containers/transform_containers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "transform_containers.hpp"

std::map<int, std::string> removeDuplicateAndTranformToMap(std::list<std::string> words, std::deque<int> nums) {
std::map<int, std::string> transformed{};

std::ranges::sort(nums);
auto new_end = std::unique(nums.begin(), nums.end());
nums.erase(new_end, nums.end());

words.sort();
words.unique();

std::vector<std::pair<int, std::string>> temp;
temp.reserve(std::min(nums.size(), words.size()));
auto f = [](int num, std::string& word) { return std::make_pair(num, word); };
std::transform(nums.begin(), nums.end(), words.begin(), std::back_inserter(temp), f);
transformed.insert(temp.begin(), temp.end());
return transformed;
}
10 changes: 10 additions & 0 deletions homework/transform-containers/transform_containers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <ranges>
#include <string>
#include <vector>

std::map<int, std::string> removeDuplicateAndTranformToMap(std::list<std::string> list, std::deque<int> deque);
Loading