From 8757bc471b9cc5627516ca4ca8c59ddcbaa8d4b0 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 7 Jul 2019 15:44:43 -0700 Subject: [PATCH] Remove pre-C++17 shims (#1752) Now that all compilers support C++17, remove some old C++14/C++17 shims. --- .../native/cpp/ConfigurableSourceImpl.cpp | 2 +- cscore/src/main/native/cpp/HttpCameraImpl.cpp | 11 +- .../src/main/native/cpp/PropertyContainer.cpp | 2 +- cscore/src/main/native/cpp/SourceImpl.cpp | 3 +- .../src/main/native/linux/UsbCameraImpl.cpp | 4 +- .../main/native/linux/UsbCameraProperty.cpp | 5 +- .../src/main/native/windows/UsbCameraImpl.cpp | 2 +- wpiutil/src/main/native/cpp/llvm/Error.cpp | 2 +- wpiutil/src/main/native/include/wpi/Error.h | 2 +- wpiutil/src/main/native/include/wpi/Format.h | 6 +- .../src/main/native/include/wpi/STLExtras.h | 173 ++++-------------- .../main/native/include/wpi/WorkerThread.h | 7 +- .../src/main/native/include/wpi/deprecated.h | 20 +- wpiutil/src/main/native/include/wpi/json.h | 89 ++------- .../src/main/native/include/wpi/uv/Async.h | 5 +- .../native/include/wpi/uv/AsyncFunction.h | 9 +- 16 files changed, 71 insertions(+), 271 deletions(-) diff --git a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp index d4c4ecc827..119be0c3bd 100644 --- a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp +++ b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp @@ -64,7 +64,7 @@ int ConfigurableSourceImpl::CreateProperty(const wpi::Twine& name, std::lock_guard lock(m_mutex); int ndx = CreateOrUpdateProperty(name, [=] { - return wpi::make_unique( + return std::make_unique( name, kind, minimum, maximum, step, defaultValue, value); }, diff --git a/cscore/src/main/native/cpp/HttpCameraImpl.cpp b/cscore/src/main/native/cpp/HttpCameraImpl.cpp index f5a9b2ee72..cd6807a2f7 100644 --- a/cscore/src/main/native/cpp/HttpCameraImpl.cpp +++ b/cscore/src/main/native/cpp/HttpCameraImpl.cpp @@ -8,7 +8,6 @@ #include "HttpCameraImpl.h" #include -#include #include #include @@ -149,7 +148,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect( if (!m_active || !stream) return nullptr; - auto connPtr = wpi::make_unique(std::move(stream), 1); + auto connPtr = std::make_unique(std::move(stream), 1); wpi::HttpConnection* conn = connPtr.get(); // update m_streamConn @@ -322,7 +321,7 @@ void HttpCameraImpl::DeviceSendSettings(wpi::HttpRequest& req) { if (!m_active || !stream) return; - auto connPtr = wpi::make_unique(std::move(stream), 1); + auto connPtr = std::make_unique(std::move(stream), 1); wpi::HttpConnection* conn = connPtr.get(); // update m_settingsConn @@ -377,7 +376,7 @@ void HttpCameraImpl::CreateProperty(const wpi::Twine& name, int minimum, int maximum, int step, int defaultValue, int value) const { std::lock_guard lock(m_mutex); - m_propertyData.emplace_back(wpi::make_unique( + m_propertyData.emplace_back(std::make_unique( name, httpParam, viaSettings, kind, minimum, maximum, step, defaultValue, value)); @@ -391,7 +390,7 @@ void HttpCameraImpl::CreateEnumProperty( const wpi::Twine& name, const wpi::Twine& httpParam, bool viaSettings, int defaultValue, int value, std::initializer_list choices) const { std::lock_guard lock(m_mutex); - m_propertyData.emplace_back(wpi::make_unique( + m_propertyData.emplace_back(std::make_unique( name, httpParam, viaSettings, CS_PROP_ENUM, 0, choices.size() - 1, 1, defaultValue, value)); @@ -409,7 +408,7 @@ void HttpCameraImpl::CreateEnumProperty( std::unique_ptr HttpCameraImpl::CreateEmptyProperty( const wpi::Twine& name) const { - return wpi::make_unique(name); + return std::make_unique(name); } bool HttpCameraImpl::CacheProperties(CS_Status* status) const { diff --git a/cscore/src/main/native/cpp/PropertyContainer.cpp b/cscore/src/main/native/cpp/PropertyContainer.cpp index 4446b30562..3002467e77 100644 --- a/cscore/src/main/native/cpp/PropertyContainer.cpp +++ b/cscore/src/main/native/cpp/PropertyContainer.cpp @@ -201,7 +201,7 @@ std::vector PropertyContainer::GetEnumPropertyChoices( std::unique_ptr PropertyContainer::CreateEmptyProperty( const wpi::Twine& name) const { - return wpi::make_unique(name); + return std::make_unique(name); } bool PropertyContainer::CacheProperties(CS_Status* status) const { diff --git a/cscore/src/main/native/cpp/SourceImpl.cpp b/cscore/src/main/native/cpp/SourceImpl.cpp index 8868319290..ced838ae79 100644 --- a/cscore/src/main/native/cpp/SourceImpl.cpp +++ b/cscore/src/main/native/cpp/SourceImpl.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -514,7 +513,7 @@ void SourceImpl::ReleaseImage(std::unique_ptr image) { std::unique_ptr SourceImpl::AllocFrameImpl() { std::lock_guard lock{m_poolMutex}; - if (m_framesAvail.empty()) return wpi::make_unique(*this); + if (m_framesAvail.empty()) return std::make_unique(*this); auto impl = std::move(m_framesAvail.back()); m_framesAvail.pop_back(); diff --git a/cscore/src/main/native/linux/UsbCameraImpl.cpp b/cscore/src/main/native/linux/UsbCameraImpl.cpp index cc5156ad5c..2a423cdb89 100644 --- a/cscore/src/main/native/linux/UsbCameraImpl.cpp +++ b/cscore/src/main/native/linux/UsbCameraImpl.cpp @@ -907,7 +907,7 @@ void UsbCameraImpl::DeviceCacheProperty( std::unique_ptr perProp; if (IsPercentageProperty(rawProp->name)) { perProp = - wpi::make_unique(rawProp->name, 0, *rawProp, 0, 0); + std::make_unique(rawProp->name, 0, *rawProp, 0, 0); rawProp->name = "raw_" + perProp->name; } @@ -1130,7 +1130,7 @@ void UsbCameraImpl::Send(Message&& msg) const { std::unique_ptr UsbCameraImpl::CreateEmptyProperty( const wpi::Twine& name) const { - return wpi::make_unique(name); + return std::make_unique(name); } bool UsbCameraImpl::CacheProperties(CS_Status* status) const { diff --git a/cscore/src/main/native/linux/UsbCameraProperty.cpp b/cscore/src/main/native/linux/UsbCameraProperty.cpp index 090f07a6a9..4dfa39cc7d 100644 --- a/cscore/src/main/native/linux/UsbCameraProperty.cpp +++ b/cscore/src/main/native/linux/UsbCameraProperty.cpp @@ -7,7 +7,6 @@ #include "UsbCameraProperty.h" -#include #include #include @@ -224,7 +223,7 @@ std::unique_ptr UsbCameraProperty::DeviceQuery(int fd, *id = qc_ext.id; // copy back // We don't support array types if (qc_ext.elems > 1 || qc_ext.nr_of_dims > 0) return nullptr; - prop = wpi::make_unique(qc_ext); + prop = std::make_unique(qc_ext); } #endif if (!prop) { @@ -235,7 +234,7 @@ std::unique_ptr UsbCameraProperty::DeviceQuery(int fd, rc = TryIoctl(fd, VIDIOC_QUERYCTRL, &qc); *id = qc.id; // copy back if (rc != 0) return nullptr; - prop = wpi::make_unique(qc); + prop = std::make_unique(qc); } // Cache enum property choices diff --git a/cscore/src/main/native/windows/UsbCameraImpl.cpp b/cscore/src/main/native/windows/UsbCameraImpl.cpp index 141ebbedc1..948a62915e 100644 --- a/cscore/src/main/native/windows/UsbCameraImpl.cpp +++ b/cscore/src/main/native/windows/UsbCameraImpl.cpp @@ -595,7 +595,7 @@ void UsbCameraImpl::DeviceCacheProperty( std::unique_ptr perProp; if (IsPercentageProperty(rawProp->name)) { perProp = - wpi::make_unique(rawProp->name, 0, *rawProp, 0, 0); + std::make_unique(rawProp->name, 0, *rawProp, 0, 0); rawProp->name = "raw_" + perProp->name; } diff --git a/wpiutil/src/main/native/cpp/llvm/Error.cpp b/wpiutil/src/main/native/cpp/llvm/Error.cpp index 5b87ae6b16..7bf9c5f4de 100644 --- a/wpiutil/src/main/native/cpp/llvm/Error.cpp +++ b/wpiutil/src/main/native/cpp/llvm/Error.cpp @@ -88,7 +88,7 @@ std::error_code FileError::convertToErrorCode() const { Error errorCodeToError(std::error_code EC) { if (!EC) return Error::success(); - return Error(wpi::make_unique(ECError(EC))); + return Error(std::make_unique(ECError(EC))); } std::error_code errorToErrorCode(Error Err) { diff --git a/wpiutil/src/main/native/include/wpi/Error.h b/wpiutil/src/main/native/include/wpi/Error.h index 7dd820709d..1821a495a1 100644 --- a/wpiutil/src/main/native/include/wpi/Error.h +++ b/wpiutil/src/main/native/include/wpi/Error.h @@ -298,7 +298,7 @@ inline ErrorSuccess Error::success() { return ErrorSuccess(); } /// Make a Error instance representing failure using the given error info /// type. template Error make_error(ArgTs &&... Args) { - return Error(wpi::make_unique(std::forward(Args)...)); + return Error(std::make_unique(std::forward(Args)...)); } /// Base class for user error types. Users should declare their error types diff --git a/wpiutil/src/main/native/include/wpi/Format.h b/wpiutil/src/main/native/include/wpi/Format.h index 2e38b587db..cb8b26b809 100644 --- a/wpiutil/src/main/native/include/wpi/Format.h +++ b/wpiutil/src/main/native/include/wpi/Format.h @@ -24,13 +24,13 @@ #define WPIUTIL_WPI_FORMAT_H #include "wpi/ArrayRef.h" -#include "wpi/STLExtras.h" #include "wpi/StringRef.h" #include #include #include #include #include +#include namespace wpi { @@ -93,7 +93,7 @@ class format_object final : public format_object_base { template int snprint_tuple(char *Buffer, unsigned BufferSize, - index_sequence) const { + std::index_sequence) const { #ifdef _MSC_VER return _snprintf_s(Buffer, BufferSize, BufferSize, Fmt, std::get(Vals)...); #else @@ -115,7 +115,7 @@ public: } int snprint(char *Buffer, unsigned BufferSize) const override { - return snprint_tuple(Buffer, BufferSize, index_sequence_for()); + return snprint_tuple(Buffer, BufferSize, std::index_sequence_for()); } }; diff --git a/wpiutil/src/main/native/include/wpi/STLExtras.h b/wpiutil/src/main/native/include/wpi/STLExtras.h index 3e85e2c6fc..d7ddd9286d 100644 --- a/wpiutil/src/main/native/include/wpi/STLExtras.h +++ b/wpiutil/src/main/native/include/wpi/STLExtras.h @@ -57,15 +57,6 @@ using ValueOfRange = typename std::remove_reference //===----------------------------------------------------------------------===// -template -struct negation : std::integral_constant {}; - -template struct conjunction : std::true_type {}; -template struct conjunction : B1 {}; -template -struct conjunction - : std::conditional, B1>::type {}; - template struct make_const_ptr { using type = typename std::add_pointer::type>::type; @@ -436,10 +427,6 @@ bool all_of(R &&range, UnaryPredicate P); template bool any_of(R &&range, UnaryPredicate P); -template struct index_sequence; - -template struct index_sequence_for; - namespace detail { using std::declval; @@ -474,38 +461,38 @@ struct zip_common : public zip_traits { std::tuple iterators; protected: - template value_type deref(index_sequence) const { + template value_type deref(std::index_sequence) const { return value_type(*std::get(iterators)...); } template - decltype(iterators) tup_inc(index_sequence) const { + decltype(iterators) tup_inc(std::index_sequence) const { return std::tuple(std::next(std::get(iterators))...); } template - decltype(iterators) tup_dec(index_sequence) const { + decltype(iterators) tup_dec(std::index_sequence) const { return std::tuple(std::prev(std::get(iterators))...); } public: zip_common(Iters &&... ts) : iterators(std::forward(ts)...) {} - value_type operator*() { return deref(index_sequence_for{}); } + value_type operator*() { return deref(std::index_sequence_for{}); } const value_type operator*() const { - return deref(index_sequence_for{}); + return deref(std::index_sequence_for{}); } ZipType &operator++() { - iterators = tup_inc(index_sequence_for{}); + iterators = tup_inc(std::index_sequence_for{}); return *reinterpret_cast(this); } ZipType &operator--() { static_assert(Base::IsBidirectional, "All inner iterators must be at least bidirectional."); - iterators = tup_dec(index_sequence_for{}); + iterators = tup_dec(std::index_sequence_for{}); return *reinterpret_cast(this); } }; @@ -524,7 +511,7 @@ struct zip_first : public zip_common, Iters...> { template class zip_shortest : public zip_common, Iters...> { template - bool test(const zip_shortest &other, index_sequence) const { + bool test(const zip_shortest &other, std::index_sequence) const { return all_of(std::initializer_list{std::get(this->iterators) != std::get(other.iterators)...}, identity{}); @@ -536,7 +523,7 @@ public: zip_shortest(Iters &&... ts) : Base(std::forward(ts)...) {} bool operator==(const zip_shortest &other) const { - return !test(other, index_sequence_for{}); + return !test(other, std::index_sequence_for{}); } }; @@ -552,18 +539,18 @@ public: private: std::tuple ts; - template iterator begin_impl(index_sequence) const { + template iterator begin_impl(std::index_sequence) const { return iterator(std::begin(std::get(ts))...); } - template iterator end_impl(index_sequence) const { + template iterator end_impl(std::index_sequence) const { return iterator(std::end(std::get(ts))...); } public: zippy(Args &&... ts_) : ts(std::forward(ts_)...) {} - iterator begin() const { return begin_impl(index_sequence_for{}); } - iterator end() const { return end_impl(index_sequence_for{}); } + iterator begin() const { return begin_impl(std::index_sequence_for{}); } + iterator end() const { return end_impl(std::index_sequence_for{}); } }; } // end namespace detail @@ -633,20 +620,20 @@ private: template bool test(const zip_longest_iterator &other, - index_sequence) const { + std::index_sequence) const { return wpi::any_of( std::initializer_list{std::get(this->iterators) != std::get(other.iterators)...}, identity{}); } - template value_type deref(index_sequence) const { + template value_type deref(std::index_sequence) const { return value_type( deref_or_none(std::get(iterators), std::get(end_iterators))...); } template - decltype(iterators) tup_inc(index_sequence) const { + decltype(iterators) tup_inc(std::index_sequence) const { return std::tuple( next_or_end(std::get(iterators), std::get(end_iterators))...); } @@ -656,17 +643,17 @@ public: : iterators(std::forward(ts.first)...), end_iterators(std::forward(ts.second)...) {} - value_type operator*() { return deref(index_sequence_for{}); } + value_type operator*() { return deref(std::index_sequence_for{}); } - value_type operator*() const { return deref(index_sequence_for{}); } + value_type operator*() const { return deref(std::index_sequence_for{}); } zip_longest_iterator &operator++() { - iterators = tup_inc(index_sequence_for{}); + iterators = tup_inc(std::index_sequence_for{}); return *this; } bool operator==(const zip_longest_iterator &other) const { - return !test(other, index_sequence_for{}); + return !test(other, std::index_sequence_for{}); } }; @@ -683,12 +670,12 @@ public: private: std::tuple ts; - template iterator begin_impl(index_sequence) const { + template iterator begin_impl(std::index_sequence) const { return iterator(std::make_pair(adl_begin(std::get(ts)), adl_end(std::get(ts)))...); } - template iterator end_impl(index_sequence) const { + template iterator end_impl(std::index_sequence) const { return iterator(std::make_pair(adl_end(std::get(ts)), adl_end(std::get(ts)))...); } @@ -696,8 +683,8 @@ private: public: zip_longest_range(Args &&... ts_) : ts(std::forward(ts_)...) {} - iterator begin() const { return begin_impl(index_sequence_for{}); } - iterator end() const { return end_impl(index_sequence_for{}); } + iterator begin() const { return begin_impl(std::index_sequence_for{}); } + iterator end() const { return end_impl(std::index_sequence_for{}); } }; } // namespace detail @@ -753,7 +740,7 @@ class concat_iterator /// Increments the first non-end iterator. /// /// It is an error to call this with all iterators at the end. - template void increment(index_sequence) { + template void increment(std::index_sequence) { // Build a sequence of functions to increment each iterator if possible. bool (concat_iterator::*IncrementHelperFns[])() = { &concat_iterator::incrementHelper...}; @@ -782,7 +769,7 @@ class concat_iterator /// reference. /// /// It is an error to call this with all iterators at the end. - template ValueT &get(index_sequence) const { + template ValueT &get(std::index_sequence) const { // Build a sequence of functions to get from iterator if possible. ValueT *(concat_iterator::*GetHelperFns[])() const = { &concat_iterator::getHelper...}; @@ -807,11 +794,11 @@ public: using BaseT::operator++; concat_iterator &operator++() { - increment(index_sequence_for()); + increment(std::index_sequence_for()); return *this; } - ValueT &operator*() const { return get(index_sequence_for()); } + ValueT &operator*() const { return get(std::index_sequence_for()); } bool operator==(const concat_iterator &RHS) const { return Begins == RHS.Begins && Ends == RHS.Ends; @@ -834,10 +821,10 @@ public: private: std::tuple Ranges; - template iterator begin_impl(index_sequence) { + template iterator begin_impl(std::index_sequence) { return iterator(std::get(Ranges)...); } - template iterator end_impl(index_sequence) { + template iterator end_impl(std::index_sequence) { return iterator(make_range(std::end(std::get(Ranges)), std::end(std::get(Ranges)))...); } @@ -846,8 +833,8 @@ public: concat_range(RangeTs &&... Ranges) : Ranges(std::forward(Ranges)...) {} - iterator begin() { return begin_impl(index_sequence_for{}); } - iterator end() { return end_impl(index_sequence_for{}); } + iterator begin() { return begin_impl(std::index_sequence_for{}); } + iterator end() { return end_impl(std::index_sequence_for{}); } }; } // end namespace detail @@ -896,28 +883,6 @@ struct on_first { } }; -// A subset of N3658. More stuff can be added as-needed. - -/// Represents a compile-time sequence of integers. -template struct integer_sequence { - using value_type = T; - - static constexpr size_t size() { return sizeof...(I); } -}; - -/// Alias for the common case of a sequence of size_ts. -template -struct index_sequence : integer_sequence {}; - -template -struct build_index_impl : build_index_impl {}; -template -struct build_index_impl<0, I...> : index_sequence {}; - -/// Creates a compile-time integer sequence for a parameter pack. -template -struct index_sequence_for : build_index_impl {}; - /// Utility type to build an inheritance chain that makes it easy to rank /// overload candidates. template struct rank : rank {}; @@ -1210,41 +1175,6 @@ void erase_if(Container &C, UnaryPredicate P) { // Extra additions to //===----------------------------------------------------------------------===// -// Implement make_unique according to N3656. - -/// Constructs a `new T()` with the given args and returns a -/// `unique_ptr` which owns the object. -/// -/// Example: -/// -/// auto p = make_unique(); -/// auto p = make_unique>(0, 1); -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(Args &&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -/// Constructs a `new T[n]` with the given args and returns a -/// `unique_ptr` which owns the object. -/// -/// \param n size of the new array. -/// -/// Example: -/// -/// auto p = make_unique(2); // value-initializes the array with 0's. -template -typename std::enable_if::value && std::extent::value == 0, - std::unique_ptr>::type -make_unique(size_t n) { - return std::unique_ptr(new typename std::remove_extent::type[n]()); -} - -/// This function isn't used and is only here to provide better compile errors. -template -typename std::enable_if::value != 0>::type -make_unique(Args &&...) = delete; - struct FreeDeleter { void operator()(void* v) { ::free(v); @@ -1258,20 +1188,6 @@ struct pair_hash { } }; -/// A functor like C++14's std::less in its absence. -struct less { - template bool operator()(A &&a, B &&b) const { - return std::forward(a) < std::forward(b); - } -}; - -/// A functor like C++14's std::equal in its absence. -struct equal { - template bool operator()(A &&a, B &&b) const { - return std::forward(a) == std::forward(b); - } -}; - /// Binary functor that adapts to any other binary functor after dereferencing /// operands. template struct deref { @@ -1393,31 +1309,6 @@ template detail::enumerator enumerate(R &&TheRange) { return detail::enumerator(std::forward(TheRange)); } -namespace detail { - -template -auto apply_tuple_impl(F &&f, Tuple &&t, index_sequence) - -> decltype(std::forward(f)(std::get(std::forward(t))...)) { - return std::forward(f)(std::get(std::forward(t))...); -} - -} // end namespace detail - -/// Given an input tuple (a1, a2, ..., an), pass the arguments of the -/// tuple variadically to f as if by calling f(a1, a2, ..., an) and -/// return the result. -template -auto apply_tuple(F &&f, Tuple &&t) -> decltype(detail::apply_tuple_impl( - std::forward(f), std::forward(t), - build_index_impl< - std::tuple_size::type>::value>{})) { - using Indices = build_index_impl< - std::tuple_size::type>::value>; - - return detail::apply_tuple_impl(std::forward(f), std::forward(t), - Indices{}); -} - /// Return true if the sequence [Begin, End) has exactly N items. Runs in O(N) /// time. Not meant for use with random-access iterators. template diff --git a/wpiutil/src/main/native/include/wpi/WorkerThread.h b/wpiutil/src/main/native/include/wpi/WorkerThread.h index 9a04f1aa5b..c0dfc2c982 100644 --- a/wpiutil/src/main/native/include/wpi/WorkerThread.h +++ b/wpiutil/src/main/native/include/wpi/WorkerThread.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -14,7 +14,6 @@ #include #include -#include "wpi/STLExtras.h" #include "wpi/SafeThread.h" #include "wpi/future.h" #include "wpi/uv/Async.h" @@ -107,7 +106,7 @@ class WorkerThreadThread : public SafeThread { template void RunWorkerThreadRequest(WorkerThreadThread& thr, WorkerThreadRequest& req) { - R result = apply_tuple(req.work, std::move(req.params)); + R result = std::apply(req.work, std::move(req.params)); if (req.afterWork) { if (auto async = thr.m_async.m_async.lock()) async->Send(std::move(req.afterWork), std::move(result)); @@ -119,7 +118,7 @@ void RunWorkerThreadRequest(WorkerThreadThread& thr, template void RunWorkerThreadRequest(WorkerThreadThread& thr, WorkerThreadRequest& req) { - apply_tuple(req.work, req.params); + std::apply(req.work, req.params); if (req.afterWork) { if (auto async = thr.m_async.m_async.lock()) async->Send(std::move(req.afterWork)); diff --git a/wpiutil/src/main/native/include/wpi/deprecated.h b/wpiutil/src/main/native/include/wpi/deprecated.h index 51f2163c53..6d77dde994 100644 --- a/wpiutil/src/main/native/include/wpi/deprecated.h +++ b/wpiutil/src/main/native/include/wpi/deprecated.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -8,26 +8,8 @@ #ifndef WPIUTIL_WPI_DEPRECATED_H_ #define WPIUTIL_WPI_DEPRECATED_H_ -// [[deprecated(msg)]] is a C++14 feature not supported by MSVC or GCC < 4.9. -// We provide an equivalent warning implementation for those compilers here. #ifndef WPI_DEPRECATED -#if defined(_MSC_VER) -#define WPI_DEPRECATED(msg) __declspec(deprecated(msg)) -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) -#if __cplusplus > 201103L #define WPI_DEPRECATED(msg) [[deprecated(msg)]] -#else -#define WPI_DEPRECATED(msg) [[gnu::deprecated(msg)]] -#endif -#else -#define WPI_DEPRECATED(msg) __attribute__((deprecated(msg))) -#endif -#elif __cplusplus > 201103L -#define WPI_DEPRECATED(msg) [[deprecated(msg)]] -#else -#define WPI_DEPRECATED(msg) /*nothing*/ -#endif #endif #endif // WPIUTIL_WPI_DEPRECATED_H_ diff --git a/wpiutil/src/main/native/include/wpi/json.h b/wpiutil/src/main/native/include/wpi/json.h index a27f84342d..a6368b7c05 100644 --- a/wpiutil/src/main/native/include/wpi/json.h +++ b/wpiutil/src/main/native/include/wpi/json.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Modifications Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Modifications Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -163,14 +163,6 @@ class json; #define JSON_UNLIKELY(x) x #endif -// C++ language standard detection -#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 - #define JSON_HAS_CPP_17 - #define JSON_HAS_CPP_14 -#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) - #define JSON_HAS_CPP_14 -#endif - /*! @brief Helper to determine whether there's a key_type for T. @@ -219,57 +211,6 @@ using enable_if_t = typename std::enable_if::type; template using uncvref_t = typename std::remove_cv::type>::type; -// implementation of C++14 index_sequence and affiliates -// source: https://stackoverflow.com/a/32223343 -template -struct index_sequence -{ - using type = index_sequence; - using value_type = std::size_t; - static constexpr std::size_t size() noexcept - { - return sizeof...(Ints); - } -}; - -template -struct merge_and_renumber; - -template -struct merge_and_renumber, index_sequence> - : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; - -template -struct make_index_sequence - : merge_and_renumber < typename make_index_sequence < N / 2 >::type, - typename make_index_sequence < N - N / 2 >::type > {}; - -template<> struct make_index_sequence<0> : index_sequence<> {}; -template<> struct make_index_sequence<1> : index_sequence<0> {}; - -template -using index_sequence_for = make_index_sequence; - -/* -Implementation of two C++17 constructs: conjunction, negation. This is needed -to avoid evaluating all the traits in a condition - -For example: not std::is_same::value and has_value_type::value -will not compile when T = void (on MSVC at least). Whereas -conjunction>, has_value_type>::value will -stop evaluating if negation<...>::value == false - -Please note that those constructs must be used with caution, since symbols can -become very long quickly (which can slow down compilation and cause MSVC -internal compiler errors). Only use it when you have to (see example ahead). -*/ -template struct conjunction : std::true_type {}; -template struct conjunction : B1 {}; -template -struct conjunction : std::conditional, B1>::type {}; - -template struct negation : std::integral_constant {}; - // dispatch utility (taken from ranges-v3) template struct priority_tag : priority_tag < N - 1 > {}; template<> struct priority_tag<0> {}; @@ -306,7 +247,7 @@ template struct is_compatible_object_type { static auto constexpr value = is_compatible_object_type_impl < - conjunction>, + std::conjunction>, has_mapped_type, has_key_type>::value, typename BasicJsonType::object_t, CompatibleObjectType >::value; @@ -325,12 +266,12 @@ template struct is_compatible_array_type { static auto constexpr value = - conjunction>, - negation>, + std::negation>, - negation>, - negation>, + std::negation>, has_value_type, has_iterator>::value; }; @@ -422,7 +363,7 @@ struct is_compatible_complete_type template struct is_compatible_type - : conjunction, + : std::conjunction, is_compatible_complete_type> { }; @@ -1035,7 +976,7 @@ void from_json(const BasicJsonType& j, std::pair& p) } template -void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence) +void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, std::index_sequence) { t = std::make_tuple(j.at(Idx).template get::type>()...); } @@ -1043,7 +984,7 @@ void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence void from_json(const BasicJsonType& j, std::tuple& t) { - from_json_tuple_impl(j, t, index_sequence_for {}); + from_json_tuple_impl(j, t, std::index_sequence_for {}); } struct from_json_fn @@ -1355,7 +1296,7 @@ void to_json(BasicJsonType& j, const std::pair& p) } template -void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence) +void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, std::index_sequence) { j = {std::get(t)...}; } @@ -1363,7 +1304,7 @@ void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence template void to_json(BasicJsonType& j, const std::tuple& t) { - to_json_tuple_impl(j, t, index_sequence_for {}); + to_json_tuple_impl(j, t, std::index_sequence_for {}); } struct to_json_fn @@ -2860,13 +2801,9 @@ class json /// the template arguments passed to class @ref json. /// @{ -#if defined(JSON_HAS_CPP_14) // Use transparent comparator if possible, combined with perfect forwarding // on find() and count() calls prevents unnecessary string construction. using object_comparator_t = std::less<>; -#else - using object_comparator_t = std::less; -#endif /*! @brief a type for an object @@ -4674,9 +4611,7 @@ class json #ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015 and not std::is_same>::value #endif -#if defined(JSON_HAS_CPP_17) and not std::is_same::value -#endif , int >::type = 0 > operator ValueType() const { @@ -8176,8 +8111,6 @@ inline wpi::json::json_pointer operator "" _json_pointer(const char* s, std::siz #undef JSON_TRY #undef JSON_LIKELY #undef JSON_UNLIKELY -#undef JSON_HAS_CPP_14 -#undef JSON_HAS_CPP_17 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION #undef NLOHMANN_BASIC_JSON_TPL #undef NLOHMANN_JSON_HAS_HELPER diff --git a/wpiutil/src/main/native/include/wpi/uv/Async.h b/wpiutil/src/main/native/include/wpi/uv/Async.h index 3ea3e5d1c9..4258257a0f 100644 --- a/wpiutil/src/main/native/include/wpi/uv/Async.h +++ b/wpiutil/src/main/native/include/wpi/uv/Async.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -16,7 +16,6 @@ #include #include -#include "wpi/STLExtras.h" #include "wpi/Signal.h" #include "wpi/mutex.h" #include "wpi/uv/Handle.h" @@ -70,7 +69,7 @@ class Async final : public HandleImpl, uv_async_t> { uv_async_init(loop->GetRaw(), h->GetRaw(), [](uv_async_t* handle) { auto& h = *static_cast(handle->data); std::lock_guard lock(h.m_mutex); - for (auto&& v : h.m_data) apply_tuple(h.wakeup, v); + for (auto&& v : h.m_data) std::apply(h.wakeup, v); h.m_data.clear(); }); if (err < 0) { diff --git a/wpiutil/src/main/native/include/wpi/uv/AsyncFunction.h b/wpiutil/src/main/native/include/wpi/uv/AsyncFunction.h index 64308564d3..1f4442af22 100644 --- a/wpiutil/src/main/native/include/wpi/uv/AsyncFunction.h +++ b/wpiutil/src/main/native/include/wpi/uv/AsyncFunction.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -18,7 +18,6 @@ #include #include -#include "wpi/STLExtras.h" #include "wpi/future.h" #include "wpi/mutex.h" #include "wpi/uv/Handle.h" @@ -91,9 +90,9 @@ class AsyncFunction final for (auto&& v : h.m_params) { auto p = h.m_promises.CreatePromise(v.first); if (h.wakeup) - apply_tuple(h.wakeup, - std::tuple_cat(std::make_tuple(std::move(p)), - std::move(v.second))); + std::apply(h.wakeup, + std::tuple_cat(std::make_tuple(std::move(p)), + std::move(v.second))); } h.m_params.clear(); // wake up any threads that might be waiting for the result