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
2 changes: 1 addition & 1 deletion homework/transform-containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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}-ut test.cpp transform.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
2 changes: 1 addition & 1 deletion homework/transform-containers/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"

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

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

std::map<int, std::string> removeDuplicateAndTranformToMap(std::list<std::string>& slist, std::deque<int>& ideq) {
slist.sort();
slist.unique();
std::sort(ideq.begin(), ideq.end());
ideq.erase(std::unique(ideq.begin(), ideq.end()), ideq.end());

std::vector<std::pair<int, std::string>> tempPair;

std::transform(slist.begin(), slist.end(), ideq.begin(), std::back_inserter(tempPair), [](const std::string& str, int num) {
return std::make_pair(num, str);
});

std::map<int, std::string> resultMap;
for (const auto& [key, val] : tempPair) {
resultMap.emplace(key, val);
}

return resultMap;
}
9 changes: 9 additions & 0 deletions homework/transform-containers/transform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <string>
#include <vector>

std::map<int, std::string> removeDuplicateAndTranformToMap(std::list<std::string>& slist, std::deque<int>& ideq);