Skip to content

Commit

Permalink
Fixes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
metopa committed May 5, 2018
1 parent 53ab748 commit 4f3cab3
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 32 deletions.
2 changes: 1 addition & 1 deletion epi_judge_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(epi_judge_cpp)
set(CMAKE_CXX_STANDARD 14)

if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4018 -wd4800 -wd4805)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4018 -wd4244 -wd4800 -wd4805)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-unused-variable -Wno-sign-compare")
link_libraries(pthread)
Expand Down
8 changes: 5 additions & 3 deletions epi_judge_cpp/drawing_skyline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ Skyline ComputeSkyline(const vector<Rectangle>& buildings) {
bool operator==(const Rectangle& a, const Rectangle& b) {
return a.left == b.left && a.right == b.right && a.height == b.height;
}
} // namespace drawing_skyline

template <>
struct SerializationTraits<Rectangle>
: UserSerTraits<Rectangle, int, int, int> {};
struct SerializationTraits<drawing_skyline::Rectangle>
: UserSerTraits<drawing_skyline::Rectangle, int, int, int> {};

std::ostream& operator<<(std::ostream& out, const Rectangle& r) {
std::ostream& operator<<(std::ostream& out,
const drawing_skyline::Rectangle& r) {
return PrintTo(out, std::make_tuple(r.left, r.right, r.height));
}

Expand Down
12 changes: 8 additions & 4 deletions epi_judge_cpp/rectangle_intersection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ bool operator==(const Rectangle& r1, const Rectangle& r2) {
std::tie(r2.x, r2.y, r2.width, r2.height);
}

} // namespace rectangle_intersection

template <>
struct SerializationTraits<Rectangle>
: UserSerTraits<Rectangle, int, int, int, int> {
struct SerializationTraits<rectangle_intersection::Rectangle>
: UserSerTraits<rectangle_intersection::Rectangle, int, int, int, int> {
static std::vector<std::string> GetMetricNames(const std::string& arg_name) {
return {FmtStr("area({})", arg_name), FmtStr("perimeter({})", arg_name),
FmtStr("max(w, h)({})", arg_name)};
}

static std::vector<int> GetMetrics(const Rectangle& x) {
static std::vector<int> GetMetrics(
const rectangle_intersection::Rectangle& x) {
return {x.height * x.width, 2 * (x.height + x.width),
std::max(x.height, x.width)};
}
};

std::ostream& operator<<(std::ostream& out, const Rectangle& r) {
std::ostream& operator<<(std::ostream& out,
const rectangle_intersection::Rectangle& r) {
return PrintTo(out, std::make_tuple(r.x, r.y, r.width, r.height));
}

Expand Down
16 changes: 10 additions & 6 deletions epi_judge_cpp/test_framework/binary_tree_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ void TreeGenerateHelper(const Node& tree, std::vector<T>* result, int order) {
}
}

//TODO Try type extractor pattern
template <template <typename...> class SmartPtr,
template <typename...> class Node, typename T>
std::vector<T> GeneratePreorder(const SmartPtr<Node<T>>& tree) {
template <typename...> class Node, typename T,
typename... MsvcWorkaround>
std::vector<T> GeneratePreorder(const SmartPtr<Node<T>, MsvcWorkaround...>& tree) {
std::vector<T> result;
TreeGenerateHelper(tree, &result, -1);
return result;
}

template <template <typename...> class SmartPtr,
template <typename...> class Node, typename T>
std::vector<T> GenerateInorder(const SmartPtr<Node<T>>& tree) {
template <typename...> class Node, typename T,
typename... MsvcWorkaround>
std::vector<T> GenerateInorder(const SmartPtr<Node<T>, MsvcWorkaround...>& tree) {
std::vector<T> result;
TreeGenerateHelper(tree, &result, 0);
return result;
}

template <template <typename...> class SmartPtr,
template <typename...> class Node, typename T>
std::vector<T> GeneratePostorder(const SmartPtr<Node<T>>& tree) {
template <typename...> class Node, typename T,
typename... MsvcWorkaround>
std::vector<T> GeneratePostorder(const SmartPtr<Node<T>, MsvcWorkaround...>& tree) {
std::vector<T> result;
TreeGenerateHelper(tree, &result, 1);
return result;
Expand Down
2 changes: 2 additions & 0 deletions epi_judge_cpp/test_framework/console_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <iostream>

#ifdef PLATFORM_WIN
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion epi_judge_cpp/test_framework/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* function.
*/

#if _WINDOWS || __MINGW__ || __CYGWIN__
#if _WINDOWS || __MINGW32__ || __CYGWIN__
#define PLATFORM_WIN
#endif

Expand Down
2 changes: 1 addition & 1 deletion epi_judge_cpp_solutions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(epi_judge_cpp_solutions)
set(CMAKE_CXX_STANDARD 17)

if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4018 -wd4800 -wd4805)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4018 -wd4244 -wd4800 -wd4805)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-unused-variable -Wno-sign-compare")
link_libraries(pthread)
Expand Down
9 changes: 6 additions & 3 deletions epi_judge_cpp_solutions/drawing_skyline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using std::min;
using std::numeric_limits;
using std::vector;

namespace drawing_skyline {
struct Rectangle;
typedef vector<Rectangle> Skyline;

Expand Down Expand Up @@ -49,12 +50,14 @@ Skyline ComputeSkyline(const vector<Rectangle>& buildings) {
bool operator==(const Rectangle& a, const Rectangle& b) {
return a.left == b.left && a.right == b.right && a.height == b.height;
}
} // namespace drawing_skyline

template <>
struct SerializationTraits<Rectangle>
: UserSerTraits<Rectangle, int, int, int> {};
struct SerializationTraits<drawing_skyline::Rectangle>
: UserSerTraits<drawing_skyline::Rectangle, int, int, int> {};

std::ostream& operator<<(std::ostream& out, const Rectangle& r) {
std::ostream& operator<<(std::ostream& out,
const drawing_skyline::Rectangle& r) {
return PrintTo(out, std::make_tuple(r.left, r.right, r.height));
}

Expand Down
14 changes: 10 additions & 4 deletions epi_judge_cpp_solutions/rectangle_intersection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using std::max;
using std::min;

namespace rectangle_intersection {
struct Rectangle;

bool IsIntersect(const Rectangle&, const Rectangle&);

struct Rectangle {
Expand All @@ -34,21 +36,25 @@ bool operator==(const Rectangle& r1, const Rectangle& r2) {
std::tie(r2.x, r2.y, r2.width, r2.height);
}

} // namespace rectangle_intersection

template <>
struct SerializationTraits<Rectangle>
: UserSerTraits<Rectangle, int, int, int, int> {
struct SerializationTraits<rectangle_intersection::Rectangle>
: UserSerTraits<rectangle_intersection::Rectangle, int, int, int, int> {
static std::vector<std::string> GetMetricNames(const std::string& arg_name) {
return {FmtStr("area({})", arg_name), FmtStr("perimeter({})", arg_name),
FmtStr("max(w, h)({})", arg_name)};
}

static std::vector<int> GetMetrics(const Rectangle& x) {
static std::vector<int> GetMetrics(
const rectangle_intersection::Rectangle& x) {
return {x.height * x.width, 2 * (x.height + x.width),
std::max(x.height, x.width)};
}
};

std::ostream& operator<<(std::ostream& out, const Rectangle& r) {
std::ostream& operator<<(std::ostream& out,
const rectangle_intersection::Rectangle& r) {
return PrintTo(out, std::make_tuple(r.x, r.y, r.width, r.height));
}

Expand Down
4 changes: 2 additions & 2 deletions epi_judge_cpp_solutions/search_unknown_length_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int BinarySearchUnknownLength(const vector<int>& A, int k) {
} else if (A.at(idx) > k) {
break;
}
} catch (const exception& e) {
} catch (const exception&) {
break;
}
++p;
Expand All @@ -34,7 +34,7 @@ int BinarySearchUnknownLength(const vector<int>& A, int k) {
} else { // A.at(mid) < k
left = mid + 1;
}
} catch (const exception& e) {
} catch (const exception&) {
right = mid - 1; // Search the left part if out-of-bound.
}
}
Expand Down
16 changes: 10 additions & 6 deletions epi_judge_cpp_solutions/test_framework/binary_tree_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ void TreeGenerateHelper(const Node& tree, std::vector<T>* result, int order) {
}
}

//TODO Try type extractor pattern
template <template <typename...> class SmartPtr,
template <typename...> class Node, typename T>
std::vector<T> GeneratePreorder(const SmartPtr<Node<T>>& tree) {
template <typename...> class Node, typename T,
typename... MsvcWorkaround>
std::vector<T> GeneratePreorder(const SmartPtr<Node<T>, MsvcWorkaround...>& tree) {
std::vector<T> result;
TreeGenerateHelper(tree, &result, -1);
return result;
}

template <template <typename...> class SmartPtr,
template <typename...> class Node, typename T>
std::vector<T> GenerateInorder(const SmartPtr<Node<T>>& tree) {
template <typename...> class Node, typename T,
typename... MsvcWorkaround>
std::vector<T> GenerateInorder(const SmartPtr<Node<T>, MsvcWorkaround...>& tree) {
std::vector<T> result;
TreeGenerateHelper(tree, &result, 0);
return result;
}

template <template <typename...> class SmartPtr,
template <typename...> class Node, typename T>
std::vector<T> GeneratePostorder(const SmartPtr<Node<T>>& tree) {
template <typename...> class Node, typename T,
typename... MsvcWorkaround>
std::vector<T> GeneratePostorder(const SmartPtr<Node<T>, MsvcWorkaround...>& tree) {
std::vector<T> result;
TreeGenerateHelper(tree, &result, 1);
return result;
Expand Down
2 changes: 2 additions & 0 deletions epi_judge_cpp_solutions/test_framework/console_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <iostream>

#ifdef PLATFORM_WIN
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion epi_judge_cpp_solutions/test_framework/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* function.
*/

#if _WINDOWS || __MINGW__ || __CYGWIN__
#if _WINDOWS || __MINGW32__ || __CYGWIN__
#define PLATFORM_WIN
#endif

Expand Down

0 comments on commit 4f3cab3

Please sign in to comment.