Skip to content
Merged
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
4 changes: 2 additions & 2 deletions blocks/http/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct Request final {

// A shortcut to allow `[](Request r) { r("OK"); }` instead of `r.connection.SendHTTPResponse("OK")`.
template <typename T, typename... TS>
std::enable_if_t<!std::is_base_of_v<IHasDoRespondViaHTTP, current::decay_t<T>>> operator()(T&& arg, TS&&... args) {
std::enable_if_t<!std::is_base_of<IHasDoRespondViaHTTP, current::decay_t<T>>::value> operator()(T&& arg, TS&&... args) {
if (!unique_connection) {
CURRENT_THROW(net::AttemptedToSendHTTPResponseMoreThanOnce());
}
Expand All @@ -106,7 +106,7 @@ struct Request final {

// Support `Response`, as well as custom objects with user-defined HTTP response handlers.
template <class T>
std::enable_if_t<std::is_base_of_v<IHasDoRespondViaHTTP, current::decay_t<T>>> operator()(T&& response) {
std::enable_if_t<std::is_base_of<IHasDoRespondViaHTTP, current::decay_t<T>>::value> operator()(T&& response) {
if (!unique_connection) {
CURRENT_THROW(net::AttemptedToSendHTTPResponseMoreThanOnce());
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/http/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct Response final : IHasDoRespondViaHTTP {
Response& operator=(const Response&) = default;
Response& operator=(Response&&) = default;

template <typename ARG, typename... ARGS, class = std::enable_if_t<!std::is_same_v<Response, current::decay_t<ARG>>>>
template <typename ARG, typename... ARGS, class = std::enable_if_t<!std::is_same<Response, current::decay_t<ARG>>::value>>
Response(ARG&& arg, ARGS&&... args) : initialized(true) {
Construct(std::forward<ARG>(arg), std::forward<ARGS>(args)...);
}
Expand Down
4 changes: 2 additions & 2 deletions blocks/ss/persister.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ class EntryPersister : public GenericEntryPersister<ENTRY>, public IMPL {
// For `static_assert`-s.
template <typename T>
struct IsPersister {
static constexpr bool value = std::is_base_of_v<GenericPersister, T>;
static constexpr bool value = std::is_base_of<GenericPersister, T>::value;
};

template <typename T, typename E>
struct IsEntryPersister {
static constexpr bool value = std::is_base_of_v<GenericEntryPersister<E>, T>;
static constexpr bool value = std::is_base_of<GenericEntryPersister<E>, T>::value;
};

} // namespace ss
Expand Down
12 changes: 6 additions & 6 deletions blocks/ss/pubsub.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ class StreamPublisher : public GenericStreamPublisher<ENTRY>, public EntryPublis
// TODO(dkorolev): `Variant` stream types, and publishing those?
template <typename T>
struct IsPublisher {
static constexpr bool value = std::is_base_of_v<GenericPublisher, current::decay_t<T>>;
static constexpr bool value = std::is_base_of<GenericPublisher, current::decay_t<T>>::value;
};

template <typename T, typename E>
struct IsEntryPublisher {
static constexpr bool value = std::is_base_of_v<GenericEntryPublisher<current::decay_t<E>>, current::decay_t<T>>;
static constexpr bool value = std::is_base_of<GenericEntryPublisher<current::decay_t<E>>, current::decay_t<T>>::value;
};

template <typename T, typename E>
struct IsStreamPublisher {
static constexpr bool value = std::is_base_of_v<GenericStreamPublisher<current::decay_t<E>>, current::decay_t<T>>;
static constexpr bool value = std::is_base_of<GenericStreamPublisher<current::decay_t<E>>, current::decay_t<T>>::value;
};

enum class EntryResponse { Done = 0, More = 1 };
Expand Down Expand Up @@ -162,17 +162,17 @@ class StreamSubscriber : public GenericStreamSubscriber<ENTRY>, public EntrySubs
// For `static_assert`-s. Must `decay_t<>` for template xvalue references support.
template <typename T>
struct IsSubscriber {
static constexpr bool value = std::is_base_of_v<GenericSubscriber, current::decay_t<T>>;
static constexpr bool value = std::is_base_of<GenericSubscriber, current::decay_t<T>>::value;
};

template <typename T, typename E>
struct IsEntrySubscriber {
static constexpr bool value = std::is_base_of_v<GenericEntrySubscriber<current::decay_t<E>>, current::decay_t<T>>;
static constexpr bool value = std::is_base_of<GenericEntrySubscriber<current::decay_t<E>>, current::decay_t<T>>::value;
};

template <typename T, typename E>
struct IsStreamSubscriber {
static constexpr bool value = std::is_base_of_v<GenericStreamSubscriber<current::decay_t<E>>, current::decay_t<T>>;
static constexpr bool value = std::is_base_of<GenericStreamSubscriber<current::decay_t<E>>, current::decay_t<T>>::value;
};

namespace impl {
Expand Down
2 changes: 1 addition & 1 deletion blocks/ss/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ template <typename ENTRY, typename STREAM_ENTRY>
#ifndef CURRENT_FOR_CPP14
inline
#endif // CURRENT_FOR_CPP14
constexpr bool can_publish_v = std::is_constructible_v<STREAM_ENTRY, ENTRY>;
constexpr bool can_publish_v = std::is_constructible<STREAM_ENTRY, ENTRY>::value;

} // namespace ss
} // namespace current
Expand Down
2 changes: 1 addition & 1 deletion blocks/xterm/progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ProgressLine final {
}

// The `std::enable_if_t` is necessary, as well as `current::decay`, because of `vt100::Color`. -- D.K.
template <typename T, class = std::enable_if_t<!std::is_base_of_v<vt100::E, current::decay_t<T>>>>
template <typename T, class = std::enable_if_t<!std::is_base_of<vt100::E, current::decay_t<T>>::value>>
Status& operator<<(T&& whatever) {
oss_text << whatever;
oss_text_with_no_vt100_escape_sequences << whatever;
Expand Down
2 changes: 1 addition & 1 deletion bricks/dflags/dflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class FlagRegisterer : public FlagRegistererBase {
}
}

bool IsBooleanFlag() const override { return std::is_same_v<FLAG_TYPE, bool>; }
bool IsBooleanFlag() const override { return std::is_same<FLAG_TYPE, bool>::value; }

std::string TypeAsString() const override { return type_; }

Expand Down
31 changes: 17 additions & 14 deletions bricks/dflags/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ SOFTWARE.
#include <string>
#include <sstream>

template <typename A, typename B>
constexpr bool is_same_v = std::is_same<A, B>::value;

TEST(DFlags, DefinesAFlag) {
::dflags::FlagsManager::DefaultRegisterer local_registerer;
auto local_registerer_scope = ::dflags::FlagsManager::ScopedSingletonInjector(local_registerer);
DEFINE_int8(foo, 42, "");
DEFINE_uint8(bar, 42, "");
static_assert(std::is_same_v<decltype(FLAGS_foo), int8_t>, "");
static_assert(std::is_same_v<decltype(FLAGS_bar), uint8_t>, "");
static_assert(is_same_v<decltype(FLAGS_foo), int8_t>, "");
static_assert(is_same_v<decltype(FLAGS_bar), uint8_t>, "");
EXPECT_EQ(42, FLAGS_foo);
EXPECT_EQ(42, FLAGS_bar);
FLAGS_foo = -1;
Expand All @@ -56,7 +59,7 @@ TEST(DFlags, ParsesAFlagUsingSingleDash) {
::dflags::FlagsManager::DefaultRegisterer local_registerer;
auto local_registerer_scope = ::dflags::FlagsManager::ScopedSingletonInjector(local_registerer);
DEFINE_int16(foo, 1, "");
static_assert(std::is_same_v<decltype(FLAGS_foo), int16_t>, "");
static_assert(is_same_v<decltype(FLAGS_foo), int16_t>, "");
EXPECT_EQ(1, FLAGS_foo);
int argc = 3;
char p1[] = "./ParsesAFlagUsingSingleDash";
Expand All @@ -74,7 +77,7 @@ TEST(DFlags, ParsesAFlagUsingDoubleDash) {
::dflags::FlagsManager::DefaultRegisterer local_registerer;
auto local_registerer_scope = ::dflags::FlagsManager::ScopedSingletonInjector(local_registerer);
DEFINE_uint16(bar, 1, "");
static_assert(std::is_same_v<decltype(FLAGS_bar), uint16_t>, "");
static_assert(is_same_v<decltype(FLAGS_bar), uint16_t>, "");
EXPECT_EQ(1, FLAGS_bar);
int argc = 3;
char p1[] = "./ParsesAFlagUsingDoubleDash";
Expand All @@ -92,7 +95,7 @@ TEST(DFlags, ParsesAFlagUsingSingleDashEquals) {
::dflags::FlagsManager::DefaultRegisterer local_registerer;
auto local_registerer_scope = ::dflags::FlagsManager::ScopedSingletonInjector(local_registerer);
DEFINE_int32(baz, 1, "");
static_assert(std::is_same_v<decltype(FLAGS_baz), int32_t>, "");
static_assert(is_same_v<decltype(FLAGS_baz), int32_t>, "");
EXPECT_EQ(1, FLAGS_baz);
int argc = 2;
char p1[] = "./ParsesAFlagUsingSingleDashEquals";
Expand All @@ -109,7 +112,7 @@ TEST(DFlags, ParsesAFlagUsingDoubleDashEquals) {
::dflags::FlagsManager::DefaultRegisterer local_registerer;
auto local_registerer_scope = ::dflags::FlagsManager::ScopedSingletonInjector(local_registerer);
DEFINE_uint32(meh, 1, "");
static_assert(std::is_same_v<decltype(FLAGS_meh), uint32_t>, "");
static_assert(is_same_v<decltype(FLAGS_meh), uint32_t>, "");
EXPECT_EQ(1u, FLAGS_meh);
int argc = 2;
char p1[] = "./ParsesAFlagUsingDoubleDashEquals";
Expand Down Expand Up @@ -142,12 +145,12 @@ TEST(DFlags, ParsesMultipleFlags) {
DEFINE_int64(flag_int64, 0, "");
DEFINE_uint64(flag_uint64, 0u, "");
DEFINE_size_t(flag_size_t, 0u, "");
static_assert(std::is_same_v<decltype(FLAGS_flag_string), std::string>, "");
static_assert(std::is_same_v<decltype(FLAGS_flag_bool1), bool>, "");
static_assert(std::is_same_v<decltype(FLAGS_flag_bool2), bool>, "");
static_assert(std::is_same_v<decltype(FLAGS_flag_int64), int64_t>, "");
static_assert(std::is_same_v<decltype(FLAGS_flag_uint64), uint64_t>, "");
static_assert(std::is_same_v<decltype(FLAGS_flag_size_t), size_t>, "");
static_assert(is_same_v<decltype(FLAGS_flag_string), std::string>, "");
static_assert(is_same_v<decltype(FLAGS_flag_bool1), bool>, "");
static_assert(is_same_v<decltype(FLAGS_flag_bool2), bool>, "");
static_assert(is_same_v<decltype(FLAGS_flag_int64), int64_t>, "");
static_assert(is_same_v<decltype(FLAGS_flag_uint64), uint64_t>, "");
static_assert(is_same_v<decltype(FLAGS_flag_size_t), size_t>, "");
EXPECT_EQ("", FLAGS_flag_string);
EXPECT_FALSE(FLAGS_flag_bool1);
EXPECT_TRUE(FLAGS_flag_bool2);
Expand Down Expand Up @@ -182,7 +185,7 @@ TEST(DFlags, ParsesEmptyString) {
::dflags::FlagsManager::DefaultRegisterer local_registerer;
auto local_registerer_scope = ::dflags::FlagsManager::ScopedSingletonInjector(local_registerer);
DEFINE_string(empty_string, "not yet", "");
static_assert(std::is_same_v<decltype(FLAGS_empty_string), std::string>, "");
static_assert(is_same_v<decltype(FLAGS_empty_string), std::string>, "");
EXPECT_EQ("not yet", FLAGS_empty_string);
int argc = 3;
char p1[] = "./ParsesEmptyString";
Expand All @@ -198,7 +201,7 @@ TEST(DFlags, ParsesEmptyStringUsingEquals) {
::dflags::FlagsManager::DefaultRegisterer local_registerer;
auto local_registerer_scope = ::dflags::FlagsManager::ScopedSingletonInjector(local_registerer);
DEFINE_string(empty_string, "not yet", "");
static_assert(std::is_same_v<decltype(FLAGS_empty_string), std::string>, "");
static_assert(is_same_v<decltype(FLAGS_empty_string), std::string>, "");
EXPECT_EQ("not yet", FLAGS_empty_string);
int argc = 2;
char p1[] = "./ParsesEmptyStringUsingEquals";
Expand Down
14 changes: 6 additions & 8 deletions bricks/distributed/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,26 @@ SOFTWARE.
using namespace std::chrono_literals;

TEST(VectorClock, SmokeTest) {
auto v = VectorClock();
auto v = VectorClock<>();
v.Step();

auto data = DiscreteClocks(1);
EXPECT_FALSE(v.AdvanceTo(data)) << "Merge from future should return false.";
EXPECT_EQ(v.State().size(), static_cast<size_t>(1));

auto v2 = VectorClock(data, 0);
auto v2 = VectorClock<>(data, 0);
EXPECT_TRUE(v2.AdvanceTo(data)) << "Test lte t==t'.";
}

TEST(VectorClock, ToString) {
DiscreteClocks c1 = {1, 2};
auto v = VectorClock(c1, 0);
auto v = VectorClock<>(c1, 0);
EXPECT_EQ(v.ToString(), "VCLOCK ID=0: [1, 2]");
}

TEST(VectorClock, Merge) {
auto base_time = current::time::Now();
DiscreteClocks c1 = {1, 2};
auto v = VectorClock(c1, 0);
auto v = VectorClock<>(c1, 0);

// Merge correct update
DiscreteClocks c2 = {2, 3};
Expand All @@ -65,14 +64,14 @@ TEST(VectorClock, Merge) {
EXPECT_EQ(v.State()[1], cur_state[1]);

// Merge partially equals using lte validation
v = VectorClock(c1, 0);
v = VectorClock<>(c1, 0);
c2 = {1, 3};
EXPECT_TRUE(v.AdvanceTo(c2)) << "0 is equals, 1 is greater - ok to merge.";
cur_state = v.State();
EXPECT_GT(cur_state[0], c2[0]) << "Local time should be updated after merge.";
EXPECT_EQ(c2[1], cur_state[1]) << "Merged time should be equal c2[1].";

v = VectorClock(c1, 0);
v = VectorClock<>(c1, 0);
cur_state = v.State();
c2 = DiscreteClocks({1, 0});
EXPECT_FALSE(v.AdvanceTo(c2)) << "Merge partially incorrect.";
Expand All @@ -96,7 +95,6 @@ TEST(VectorClock, ContinuousTime) {
}

TEST(VectorClock, StrictMerge) {
auto base_time = current::time::Now();
DiscreteClocks c1 = {1, 2};
auto v = VectorClock<DiscreteClocks, StrictMergeStrategy>(c1, 0);

Expand Down
6 changes: 3 additions & 3 deletions bricks/net/http/impl/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,9 @@ class GenericHTTPServerConnection final : public HTTPResponder {

// Only support STL containers of chars and bytes, this does not yet cover std::string.
template <typename T>
inline std::enable_if_t<std::is_same_v<typename T::value_type, char> ||
std::is_same_v<typename T::value_type, uint8_t> ||
std::is_same_v<typename T::value_type, int8_t>>
inline std::enable_if_t<std::is_same<typename T::value_type, char>::value ||
std::is_same<typename T::value_type, uint8_t>::value ||
std::is_same<typename T::value_type, int8_t>::value>
Send(T&& data, ChunkFlush flush) {
SendImpl(std::forward<T>(data), flush);
}
Expand Down
2 changes: 1 addition & 1 deletion bricks/net/tcp/impl/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class ReserveLocalPortImpl final {
uint16_t port,
NagleAlgorithm nagle_algorithm_policy = kDefaultNagleAlgorithmPolicy,
MaxServerQueuedConnectionsValue max_connections = kMaxServerQueuedConnections) {
auto hold_port_or_throw = current::net::SocketHandle(current::net::SocketHandle::BindAndListen(),
current::net::SocketHandle hold_port_or_throw(current::net::SocketHandle::BindAndListen(),
current::net::BarePort(port),
nagle_algorithm_policy,
max_connections);
Expand Down
12 changes: 9 additions & 3 deletions bricks/strings/join.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,24 @@ namespace sfinae {
template <typename T, typename = void>
struct is_container : std::false_type {};

// NOTE(dkorolev): To avoid `std::void_t` in C++14.
template <typename... TS>
struct make_void {
typedef void type;
};

template <typename T>
struct is_container<
T,
std::void_t<decltype(std::declval<T>().begin()), decltype(std::declval<T>().end()), typename T::value_type>>
typename make_void<decltype(std::declval<T>().begin()), decltype(std::declval<T>().end()), typename T::value_type>::type>
: std::true_type {};

#ifndef CURRENT_FOR_CPP14

template <typename T>
constexpr bool is_container_of_strings() {
if constexpr (is_container<T>::value) {
return std::is_same_v<typename T::value_type, std::string>;
return std::is_same<typename T::value_type, std::string>::value;
}
return false;
}
Expand All @@ -92,7 +98,7 @@ struct is_container_of_strings_impl final {

template <typename T>
struct is_container_of_strings_impl<true, T> final {
constexpr static bool value = std::is_same_v<typename T::value_type, std::string>;
constexpr static bool value = std::is_same<typename T::value_type, std::string>::value;
};

template <typename T>
Expand Down
16 changes: 8 additions & 8 deletions bricks/strings/split.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct DefaultSeparator<ByLines> {
} // namespace impl

template <typename SEPARATOR, typename PROCESSOR>
inline std::enable_if_t<!std::is_same_v<PROCESSOR, EmptyFields>, size_t> Split(
inline std::enable_if_t<!std::is_same<PROCESSOR, EmptyFields>::value, size_t> Split(
const std::string& s,
SEPARATOR&& separator,
PROCESSOR&& processor,
Expand Down Expand Up @@ -186,7 +186,7 @@ inline size_t Split(char* s,

// `Split(std::string&, ...)` maps to `Split(char*, size_t, ...)`.
template <typename SEPARATOR, typename PROCESSOR>
inline std::enable_if_t<!std::is_same_v<PROCESSOR, EmptyFields>, size_t> Split(
inline std::enable_if_t<!std::is_same<PROCESSOR, EmptyFields>::value, size_t> Split(
std::string& string,
SEPARATOR&& separator,
PROCESSOR&& processor,
Expand Down Expand Up @@ -214,7 +214,7 @@ inline size_t Split(char* string,
}

template <typename SEPARATOR, typename PROCESSOR>
inline std::enable_if_t<!std::is_same_v<PROCESSOR, EmptyFields>, size_t> Split(
inline std::enable_if_t<!std::is_same<PROCESSOR, EmptyFields>::value, size_t> Split(
const char* string,
SEPARATOR&& separator,
PROCESSOR&& processor,
Expand All @@ -228,7 +228,7 @@ inline std::enable_if_t<!std::is_same_v<PROCESSOR, EmptyFields>, size_t> Split(
// Special case for `Chunk`: Treat even the `const` Chunk-s as mutable.
// We assume the users of `Chunk` a) expect performance, and b) know what they are doing.
template <typename SEPARATOR, typename PROCESSOR>
inline std::enable_if_t<!std::is_same_v<PROCESSOR, EmptyFields>, size_t> Split(
inline std::enable_if_t<!std::is_same<PROCESSOR, EmptyFields>::value, size_t> Split(
const Chunk& chunk,
SEPARATOR&& separator,
PROCESSOR&& processor,
Expand All @@ -251,7 +251,7 @@ inline size_t Split(STRING&& s, PROCESSOR&& processor, EmptyFields empty_fields_

// The version returning an `std::vector<Chunk>`, which is somewhat performant.
template <typename SEPARATOR>
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same_v<SEPARATOR, EmptyFields>,
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same<SEPARATOR, EmptyFields>::value,
std::vector<Chunk>>
SplitIntoChunks(Chunk chunk,
SEPARATOR&& separator = impl::DefaultSeparator<SEPARATOR>::value(),
Expand All @@ -266,7 +266,7 @@ SplitIntoChunks(Chunk chunk,
}

template <typename SEPARATOR>
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same_v<SEPARATOR, EmptyFields>,
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same<SEPARATOR, EmptyFields>::value,
std::vector<Chunk>>
SplitIntoChunks(char* s,
SEPARATOR&& separator = impl::DefaultSeparator<SEPARATOR>::value(),
Expand All @@ -275,7 +275,7 @@ SplitIntoChunks(char* s,
}

template <typename SEPARATOR>
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same_v<SEPARATOR, EmptyFields>,
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same<SEPARATOR, EmptyFields>::value,
std::vector<Chunk>>
SplitIntoChunks(const std::string& s,
SEPARATOR&& separator = impl::DefaultSeparator<SEPARATOR>::value(),
Expand All @@ -285,7 +285,7 @@ SplitIntoChunks(const std::string& s,

// The versions returning an `std::vector<std::string>`, for those not caring about performance.
template <typename SEPARATOR, typename STRING>
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same_v<SEPARATOR, EmptyFields>,
inline std::enable_if_t<impl::IsValidSeparator<SEPARATOR>::value && !std::is_same<SEPARATOR, EmptyFields>::value,
std::vector<std::string>>
Split(STRING&& s,
SEPARATOR&& separator = impl::DefaultSeparator<SEPARATOR>::value(),
Expand Down
Loading