From 12944502a1dbcecdd2024d7bed0d2d36d83d388c Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 6 Jun 2021 19:40:54 +0800 Subject: [PATCH] Revert "update IPC_CONCEPT_" This reverts commit 1e5547e6dfd0605fa62be67899c6c893aa61f9fc. --- src/libipc/memory/alloc.h | 11 +++--- src/libipc/memory/wrapper.h | 17 ++++----- src/libipc/platform/tls_pointer_win.cpp | 1 + src/libipc/platform/to_tchar.h | 15 +++++--- src/libipc/utility/concept.h | 47 +++++++++---------------- src/libipc/utility/pimpl.h | 17 ++++----- 6 files changed, 46 insertions(+), 62 deletions(-) diff --git a/src/libipc/memory/alloc.h b/src/libipc/memory/alloc.h index 820361a..16bebc9 100755 --- a/src/libipc/memory/alloc.h +++ b/src/libipc/memory/alloc.h @@ -44,8 +44,7 @@ constexpr std::size_t aligned(std::size_t size, size_t alignment) noexcept { return ( (size - 1) & ~(alignment - 1) ) + alignment; } -template -IPC_CONCEPT_(has_take, require([](auto && t)->decltype(t.take(std::move(t))) {})); +IPC_CONCEPT_(has_take, take(std::move(std::declval()))); class scope_alloc_base { protected: @@ -117,13 +116,13 @@ public: } template - auto take(scope_alloc && rhs) -> std::enable_if_t::value> { + auto take(scope_alloc && rhs) -> ipc::require::value> { base_t::take(std::move(rhs)); alloc_.take(std::move(rhs.alloc_)); } template - auto take(scope_alloc && rhs) -> std::enable_if_t::value> { + auto take(scope_alloc && rhs) -> ipc::require::value> { base_t::take(std::move(rhs)); } @@ -256,7 +255,7 @@ public: } template - auto take(fixed_alloc && rhs) -> std::enable_if_t::value> { + auto take(fixed_alloc && rhs) -> ipc::require::value> { base_t::take(std::move(rhs)); alloc_.take(std::move(rhs.alloc_)); } @@ -395,7 +394,7 @@ public: } template - auto take(variable_alloc && rhs) -> std::enable_if_t::value> { + auto take(variable_alloc && rhs) -> ipc::require::value> { base_t::take(std::move(rhs)); alloc_.take(std::move(rhs.alloc_)); } diff --git a/src/libipc/memory/wrapper.h b/src/libipc/memory/wrapper.h index 7f84838..5e76f88 100755 --- a/src/libipc/memory/wrapper.h +++ b/src/libipc/memory/wrapper.h @@ -27,8 +27,7 @@ namespace mem { namespace detail { -template -IPC_CONCEPT_(is_comparable, require([](auto && t)->decltype(t < t) {})); +IPC_CONCEPT_(is_comparable, operator<(std::declval())); } // namespace detail @@ -72,10 +71,8 @@ public: template class default_recycler : public limited_recycler { - template - IPC_CONCEPT_(has_remain, require([](auto && t)->decltype(t.remain()) {})); - template - IPC_CONCEPT_(has_empty, require([](auto && t)->decltype(t.empty()) {})); + IPC_CONCEPT_(has_remain, remain()); + IPC_CONCEPT_(has_empty , empty()); template void try_fill(A & alc) { @@ -89,28 +86,28 @@ public: template auto try_replenish(alloc_policy & alc, std::size_t size) - -> std::enable_if_t::value && has_remain::value> { + -> ipc::require::value && has_remain::value> { if (alc.remain() >= size) return; this->try_fill(alc); } template auto try_replenish(alloc_policy & alc, std::size_t /*size*/) - -> std::enable_if_t::value && !has_remain::value && has_empty::value> { + -> ipc::require::value && !has_remain::value && has_empty::value> { if (!alc.empty()) return; this->try_fill(alc); } template auto try_replenish(alloc_policy & alc, std::size_t /*size*/) - -> std::enable_if_t::value && has_empty::value> { + -> ipc::require::value && has_empty::value> { if (!alc.empty()) return; this->try_recover(alc); } template IPC_CONSTEXPR_ auto try_replenish(alloc_policy & /*alc*/, std::size_t /*size*/) noexcept - -> std::enable_if_t<(!detail::has_take::value || !has_remain::value) && !has_empty::value> { + -> ipc::require<(!detail::has_take::value || !has_remain::value) && !has_empty::value> { // Do Nothing. } }; diff --git a/src/libipc/platform/tls_pointer_win.cpp b/src/libipc/platform/tls_pointer_win.cpp index 3d56909..cdbe208 100755 --- a/src/libipc/platform/tls_pointer_win.cpp +++ b/src/libipc/platform/tls_pointer_win.cpp @@ -7,6 +7,7 @@ * @remarks * Windows doesn't support a per-thread destructor with its TLS primitives. * So, here will build it manually by inserting a function to be called on each thread's exit. + * * @see * - https://www.codeproject.com/Articles/8113/Thread-Local-Storage-The-C-Way * - https://src.chromium.org/viewvc/chrome/trunk/src/base/threading/thread_local_storage_win.cc diff --git a/src/libipc/platform/to_tchar.h b/src/libipc/platform/to_tchar.h index 2598b83..df67b2d 100755 --- a/src/libipc/platform/to_tchar.h +++ b/src/libipc/platform/to_tchar.h @@ -15,14 +15,19 @@ namespace ipc { namespace detail { +struct has_value_type_ { + template static std::true_type check(typename T::value_type *); + template static std::false_type check(...); +}; + +template (nullptr))> +struct is_same_char : std::is_same {}; + template -IPC_CONCEPT_(has_same_char, - require([]()->std::enable_if_t::value> {}) || - require([]()->std::enable_if_t::value> {}) -); +struct is_same_char : std::is_same {}; template -using IsSameChar = std::enable_if_t::value, R>; +using IsSameChar = ipc::require::value, R>; //////////////////////////////////////////////////////////////// /// to_tchar implementation diff --git a/src/libipc/utility/concept.h b/src/libipc/utility/concept.h index 5192c07..9325ddc 100755 --- a/src/libipc/utility/concept.h +++ b/src/libipc/utility/concept.h @@ -1,42 +1,29 @@ #pragma once -#include // std::declval +#include // std::enable_if namespace ipc { -/** - * @remarks - * <> Concepts TS Improve on C++17 - * @see - * - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0726r0.html - * - https://www.youtube.com/watch?v=TorW5ekkL_w -*/ -namespace detail { +// concept helpers -template ()(std::declval()...))> -constexpr bool require_impl(int) { return true; } - -template -constexpr bool require_impl(...) { return false; } - -} // namespace detail - -template -constexpr bool require(F&&) { - return detail::require_impl(int{}); -} - -} // namespace ipc - -/// concept helpers +template +using require = typename std::enable_if::type; #ifdef IPC_CONCEPT_ # error "IPC_CONCEPT_ has been defined." #endif -#define IPC_CONCEPT_($$name, $$what) \ -class $$name { \ -public: \ - constexpr static bool value = $$what; \ +#define IPC_CONCEPT_(NAME, WHAT) \ +template \ +class NAME { \ +private: \ + template \ + static std::true_type check(decltype(std::declval().WHAT)*); \ + template \ + static std::false_type check(...); \ +public: \ + using type = decltype(check(nullptr)); \ + constexpr static auto value = type::value; \ } + +} // namespace ipc diff --git a/src/libipc/utility/pimpl.h b/src/libipc/utility/pimpl.h index fbb5ea2..25074e7 100755 --- a/src/libipc/utility/pimpl.h +++ b/src/libipc/utility/pimpl.h @@ -8,19 +8,14 @@ namespace ipc { -template -IPC_CONCEPT_(is_impl_comfortable, - require([](auto && t)->std::enable_if_t<(sizeof(t) <= sizeof(T*))> {}) -); - -template -using IsImplComfortable = std::enable_if_t::value, R>; - -template -using IsImplUncomfortable = std::enable_if_t::value, R>; - // pimpl small object optimization helpers +template +using IsImplComfortable = ipc::require<(sizeof(T) <= sizeof(T*)), R>; + +template +using IsImplUncomfortable = ipc::require<(sizeof(T) > sizeof(T*)), R>; + template constexpr auto make_impl(P&&... params) -> IsImplComfortable { T* buf {};