Skip to content

Commit

Permalink
Remove C++17 features
Browse files Browse the repository at this point in the history
  • Loading branch information
metopa committed Mar 8, 2018
1 parent bf596e8 commit 6728abc
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 50 deletions.
1 change: 1 addition & 0 deletions epi_judge_cpp/test_framework/any.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @library
#pragma once

#include <memory>
Expand Down
1 change: 1 addition & 0 deletions epi_judge_cpp/test_framework/fmt_print.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @library
#pragma once

#include <ostream>
Expand Down
1 change: 1 addition & 0 deletions epi_judge_cpp/test_framework/fmt_print_fwd.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @library
#pragma once

#include <iosfwd>
Expand Down
1 change: 0 additions & 1 deletion epi_judge_cpp/test_framework/generic_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ TestResult GenericTestMain(const std::vector<std::string>& commandline_args,
template <typename Function, typename Comparator>
TestResult RunTests(GenericTestHandler<Function, Comparator>& handler,
const TestConfig& config) {
using handler_t = GenericTestHandler<Function, Comparator>;

auto test_data = SplitTsvFile(config.test_data_dir + config.test_data_file);
handler.ParseSignature(test_data[0]);
Expand Down
2 changes: 0 additions & 2 deletions epi_judge_cpp/test_framework/generic_test_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class GenericTestHandler {
*/
void ParseSignature(const std::vector<std::string>& signature) {
using arg_tuple_t = typename func_traits::arg_tuple_t;
using ret_t = typename func_traits::return_t;

MatchFunctionSignature<expected_value_t, arg_tuple_t>(
std::cbegin(signature), std::cend(signature));
Expand All @@ -94,7 +93,6 @@ class GenericTestHandler {
TestTimer RunTest(const std::chrono::milliseconds& timeout_ms,
const std::vector<std::string>& test_args) const {
using arg_tuple_t = typename func_traits::arg_tuple_t;
using ret_t = typename func_traits::return_t;
auto args = ParseSerializedArgs<arg_tuple_t>(
std::cbegin(test_args),
std::cend(test_args) - (ExpectedIsVoid() ? 0 : 1));
Expand Down
22 changes: 11 additions & 11 deletions epi_judge_cpp/test_framework/test_utils_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ struct No {};
template <typename T, typename EqualTo>
struct HasEqualOpImpl {
template <typename U, typename V>
static auto Test(U*) -> decltype(std::declval<U>() == std::declval<V>());
static auto Test(U*) -> decltype(std::declval<U&>() == std::declval<V&>());

template <typename, typename>
static auto Test(...) -> No;

using type = std::bool_constant<
!std::is_same<decltype(Test<T, EqualTo>(0)), No>::value>;
using type = std::integral_constant<
bool, !std::is_same<decltype(Test<T, EqualTo>(0)), No>::value>;
};

/**
Expand All @@ -288,13 +288,13 @@ struct HasEqualOpImpl {
template <typename S, typename T>
struct HasLeftShiftOpImpl {
template <typename U, typename V>
static auto Test(U*) -> decltype(std::declval<U>() << std::declval<V>());
static auto Test(U*) -> decltype(std::declval<U&>() << std::declval<V&>());

template <typename, typename>
static auto Test(...) -> No;

using type =
std::bool_constant<!std::is_same<decltype(Test<S, T>(0)), No>::value>;
using type = std::integral_constant<
bool, !std::is_same<decltype(Test<S, T>(0)), No>::value>;
};

// Additional namespace is introduced to escape
Expand All @@ -306,20 +306,20 @@ using std::end;
template <typename T>
struct HasBeginEndImpl {
template <typename U>
static auto TestBegin(U*) -> decltype(begin(std::declval<U>()));
static auto TestBegin(U*) -> decltype(begin(std::declval<U&>()));

template <typename U>
static auto TestEnd(U*) -> decltype(end(std::declval<U>()));
static auto TestEnd(U*) -> decltype(end(std::declval<U&>()));

template <typename>
static auto TestBegin(...) -> No;

template <typename>
static auto TestEnd(...) -> No;

using type = std::bool_constant<
!std::is_same<decltype(TestBegin<T>(0)), No>::value &&
!std::is_same<decltype(TestEnd<T>(0)), No>::value>;
using type = std::integral_constant<
bool, !std::is_same<decltype(TestBegin<T>(0)), No>::value &&
!std::is_same<decltype(TestEnd<T>(0)), No>::value>;
};
} // namespace std_import

Expand Down
78 changes: 43 additions & 35 deletions epi_judge_cpp/test_framework/test_utils_meta_test.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @library
#pragma once

#include <ostream>
Expand All @@ -6,54 +7,61 @@

#include "test_utils_meta.h"

static_assert(std::is_same<remove_ref_cv_t<int>, int>::value);
static_assert(std::is_same<remove_ref_cv_t<const int&>, int>::value);
static_assert(std::is_same<remove_ref_cv_t<int>, int>::value, "");
static_assert(std::is_same<remove_ref_cv_t<const int&>, int>::value, "");

static_assert(is_pure_type<int>::value == true);
static_assert(is_pure_type<int&>::value == false);
static_assert(is_pure_type<const int>::value == false);
static_assert(is_pure_type<int>::value == true, "");
static_assert(is_pure_type<int&>::value == false, "");
static_assert(is_pure_type<const int>::value == false, "");

static_assert(FirstFalseArg() == 0);
static_assert(FirstFalseArg(false) == 1);
static_assert(FirstFalseArg(true) == 0);
static_assert(FirstFalseArg(true, false) == 2);
static_assert(FirstFalseArg(true, true, true, false) == 4);
static_assert(FirstFalseArg(false, true, true, false) == 1);
static_assert(FirstFalseArg() == 0, "");
static_assert(FirstFalseArg(false) == 1, "");
static_assert(FirstFalseArg(true) == 0, "");
static_assert(FirstFalseArg(true, false) == 2, "");
static_assert(FirstFalseArg(true, true, true, false) == 4, "");
static_assert(FirstFalseArg(false, true, true, false) == 1, "");

namespace detail {
namespace test {
void WithExecutorHook(TimedExecutor&, int);
void WithoutExecutorHook(int, int);

static_assert(
FunctionalTraits<decltype(&WithExecutorHook)>::HasExecutorHook() == true);
FunctionalTraits<decltype(&WithExecutorHook)>::HasExecutorHook() == true,
"");
static_assert(
FunctionalTraits<decltype(&WithoutExecutorHook)>::HasExecutorHook() ==
false);
false,
"");
} // namespace test
} // namespace detail

static_assert(
std::is_same<SubTuple<std::tuple<char, short, int, long>, 0, 4>::type,
std::tuple<char, short, int, long>>::value);
std::tuple<char, short, int, long>>::value,
"");

static_assert(
std::is_same<SubTuple<std::tuple<char, short, int, long>, 0, 0>::type,
std::tuple<>>::value);
std::tuple<>>::value,
"");

static_assert(
std::is_same<SubTuple<std::tuple<char, short, int, long>, 4, 4>::type,
std::tuple<>>::value);
std::tuple<>>::value,
"");

static_assert(
std::is_same<SubTuple<std::tuple<char, short, int, long>, 0, 2>::type,
std::tuple<char, short>>::value);
std::tuple<char, short>>::value,
"");
static_assert(
std::is_same<SubTuple<std::tuple<char, short, int, long>, 2, 4>::type,
std::tuple<int, long>>::value);
std::tuple<int, long>>::value,
"");

static_assert(std::is_same<escape_void_t<int>, int>::value);
static_assert(std::is_same<escape_void_t<void>, VoidPlaceholder>::value);
static_assert(std::is_same<escape_void_t<int>, int>::value, "");
static_assert(std::is_same<escape_void_t<void>, VoidPlaceholder>::value, "");

namespace detail {
namespace test {
Expand All @@ -66,19 +74,19 @@ bool operator==(const NormalOperator&, const NormalOperator&);
WeirdOperator operator==(WeirdOperator, WeirdOperator);
bool operator==(const InvalidOperator&, const WeirdOperator&);

static_assert(HasEqualOp<NoOperator>::value == false);
static_assert(HasEqualOp<NormalOperator>::value == true);
static_assert(HasEqualOp<WeirdOperator>::value == true);
static_assert(HasEqualOp<InvalidOperator>::value == false);
static_assert(HasEqualOp<NoOperator>::value == false, "");
static_assert(HasEqualOp<NormalOperator>::value == true, "");
static_assert(HasEqualOp<WeirdOperator>::value == true, "");
static_assert(HasEqualOp<InvalidOperator>::value == false, "");

std::ostream& operator<<(std::ostream&, const NormalOperator&);
void operator<<(std::ostream&, WeirdOperator);
std::ostream& operator<<(InvalidOperator&, InvalidOperator);

static_assert(HasOStreamOp<NoOperator>::value == false);
static_assert(HasOStreamOp<NormalOperator>::value == true);
static_assert(HasOStreamOp<WeirdOperator>::value == true);
static_assert(HasOStreamOp<InvalidOperator>::value == false);
static_assert(HasOStreamOp<NoOperator>::value == false, "");
static_assert(HasOStreamOp<NormalOperator>::value == true, "");
static_assert(HasOStreamOp<WeirdOperator>::value == true, "");
static_assert(HasOStreamOp<InvalidOperator>::value == false, "");

struct UserCollection1 {
int begin() const;
Expand All @@ -93,12 +101,12 @@ class InvalidUserCollection {
int begin();
};

static_assert(HasBeginEnd<int>::value == false);
static_assert(HasBeginEnd<NoOperator>::value == false);
static_assert(HasBeginEnd<std::vector<int>>::value == true);
static_assert(HasBeginEnd<std::set<int>>::value == true);
static_assert(HasBeginEnd<InvalidUserCollection>::value == false);
static_assert(HasBeginEnd<UserCollection1>::value == true);
static_assert(HasBeginEnd<UserCollection2>::value == true);
static_assert(HasBeginEnd<int>::value == false, "");
static_assert(HasBeginEnd<NoOperator>::value == false, "");
static_assert(HasBeginEnd<std::vector<int>>::value == true, "");
static_assert(HasBeginEnd<std::set<int>>::value == true, "");
static_assert(HasBeginEnd<InvalidUserCollection>::value == false, "");
static_assert(HasBeginEnd<UserCollection1>::value == true, "");
static_assert(HasBeginEnd<UserCollection2>::value == true, "");
} // namespace test
} // namespace detail
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ struct SerializationTraits : NoSpecializationTag {
};

template <typename T>
using HasSerializationTraitsSpecialization = std::bool_constant<
using HasSerializationTraitsSpecialization = std::integral_constant<
bool,
!std::is_base_of<NoSpecializationTag, SerializationTraits<T>>::value>;

/**
Expand Down

0 comments on commit 6728abc

Please sign in to comment.