Skip to content

Commit 9f8233a

Browse files
committed
Update on "Replace c10::guts::stuff with std::stuff"
Since we now have C++14, we don't need these c10::guts helpers anymore - c10::guts::make_unique -> std::make_unique - c10::guts::integer_sequence -> std::integer_sequence - c10::guts::index_sequence -> std::index_sequence - c10::guts::make_integer_sequence -> std::make_integer_sequence - c10::guts::make_index_sequence -> std::make_index_sequence - c10::guts::index_sequence_for -> std::index_sequence_for - c10::guts::conditional_t -> std::conditional_t - c10::guts::enable_if_t -> std::enable_if_t - c10::guts::add_lvalue_reference_t -> std::add_lvalue_reference_t - c10::guts::remove_reference_t -> std::remove_reference_t - c10::guts::remove_cv_t -> std::remove_cv_t - c10::guts::result_of_t -> std::result_of_t - c10::guts::decay_t -> std::decay_t - c10::guts::remove_const_t -> std::remove_const_t - c10::guts::remove_pointer_t -> std::remove_pointer_t - c10::guts::common_type_t -> std::common_type_t Differential Revision: [D18869639](https://our.internmc.facebook.com/intern/diff/D18869639/) [ghstack-poisoned]
1 parent 90374de commit 9f8233a

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

c10/test/util/C++17_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
#include <c10/util/C++17.h>
22

3+
using c10::guts::max;
4+
using c10::guts::min;
5+
6+
static_assert(min(3, 5) == 3, "");
7+
static_assert(min(5, 3) == 3, "");
8+
static_assert(min(3, 3) == 3, "");
9+
static_assert(min(3.0, 3.1) == 3.0, "");
10+
11+
static_assert(max(3, 5) == 5, "");
12+
static_assert(max(5, 3) == 5, "");
13+
static_assert(max(3, 3) == 3, "");
14+
static_assert(max(3.0, 3.1) == 3.1, "");

c10/util/C++17.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ template<class T> inline std::string to_string(T value) {
189189
return detail::to_string_<T>::call(value);
190190
}
191191

192+
template <class T>
193+
constexpr const T& min(const T& a, const T& b) {
194+
return (b < a) ? b : a;
195+
}
196+
197+
template <class T>
198+
constexpr const T& max(const T& a, const T& b) {
199+
return (a < b) ? b : a;
200+
}
201+
192202
}}
193203

194204
#endif // C10_UTIL_CPP17_H_

c10/util/string_view.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class basic_string_view final {
180180
c10::guts::to_string(pos) +
181181
", size: " + c10::guts::to_string(size()));
182182
}
183-
size_type copy_length = std::min(count, size_ - pos);
183+
size_type copy_length = guts::min(count, size_ - pos);
184184
for (auto iter = begin() + pos, end = iter + copy_length; iter != end;) {
185185
*(dest++) = *(iter++);
186186
}
@@ -205,7 +205,7 @@ class basic_string_view final {
205205
constexpr int compare(basic_string_view rhs) const noexcept {
206206
#if __cpp_constexpr >= 201304
207207
// if we are in C++14, write it iteratively. This is faster.
208-
for (size_t i = 0, end = std::min(size(), rhs.size()); i < end; ++i) {
208+
for (size_t i = 0, end = guts::min(size(), rhs.size()); i < end; ++i) {
209209
if (at_(i) < rhs.at_(i)) {
210210
return -1;
211211
} else if (at_(i) > rhs.at_(i)) {
@@ -378,7 +378,7 @@ class basic_string_view final {
378378
}
379379

380380
if (v.size() <= size()) {
381-
pos = std::min(size() - v.size(), pos);
381+
pos = guts::min(size() - v.size(), pos);
382382
do {
383383
if (v.at_(0) == at_(pos) &&
384384
v.substr_(1).equals_(substr_(pos + 1, v.size() - 1))) {
@@ -524,7 +524,7 @@ class basic_string_view final {
524524

525525
constexpr basic_string_view substr_(size_type pos = 0, size_type count = npos)
526526
const {
527-
return basic_string_view{begin_ + pos, std::min(count, size() - pos)};
527+
return basic_string_view{begin_ + pos, guts::min(count, size() - pos)};
528528
}
529529

530530
template <class Condition>
@@ -556,7 +556,7 @@ class basic_string_view final {
556556
#if __cpp_constexpr >= 201304
557557
// if we are in C++14, write it iteratively. This is faster.
558558
if (size() > 0) {
559-
pos = std::min(size() - 1, pos);
559+
pos = guts::min(size() - 1, pos);
560560
do {
561561
if (condition(at_(pos))) {
562562
return pos;

caffe2/utils/threadpool/WorkersPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class alignas(kGEMMLOWPCacheLineSize) Worker {
231231
: task_(nullptr),
232232
state_(State::ThreadStartup),
233233
counter_to_decrement_when_ready_(counter_to_decrement_when_ready) {
234-
thread_ = make_unique<std::thread>([this]() { this->ThreadFunc(); });
234+
thread_ = std::make_unique<std::thread>([this]() { this->ThreadFunc(); });
235235
}
236236

237237
~Worker() {

0 commit comments

Comments
 (0)