Skip to content

Commit ff488e0

Browse files
committed
Revert "update IPC_CONCEPT_"
This reverts commit 1e5547e.
1 parent 54bc338 commit ff488e0

File tree

6 files changed

+43
-59
lines changed

6 files changed

+43
-59
lines changed

src/libipc/memory/alloc.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ constexpr std::size_t aligned(std::size_t size, size_t alignment) noexcept {
4444
return ( (size - 1) & ~(alignment - 1) ) + alignment;
4545
}
4646

47-
template <typename T>
48-
IPC_CONCEPT_(has_take, require<T>([](auto && t)->decltype(t.take(std::move(t))) {}));
47+
IPC_CONCEPT_(has_take, take(std::move(std::declval<Type>())));
4948

5049
class scope_alloc_base {
5150
protected:
@@ -117,13 +116,13 @@ class scope_alloc : public detail::scope_alloc_base {
117116
}
118117

119118
template <typename A = AllocP>
120-
auto take(scope_alloc && rhs) -> std::enable_if_t<detail::has_take<A>::value> {
119+
auto take(scope_alloc && rhs) -> ipc::require<detail::has_take<A>::value> {
121120
base_t::take(std::move(rhs));
122121
alloc_.take(std::move(rhs.alloc_));
123122
}
124123

125124
template <typename A = AllocP>
126-
auto take(scope_alloc && rhs) -> std::enable_if_t<!detail::has_take<A>::value> {
125+
auto take(scope_alloc && rhs) -> ipc::require<!detail::has_take<A>::value> {
127126
base_t::take(std::move(rhs));
128127
}
129128

@@ -256,7 +255,7 @@ class fixed_alloc : public detail::fixed_alloc_base {
256255
}
257256

258257
template <typename A = AllocP>
259-
auto take(fixed_alloc && rhs) -> std::enable_if_t<detail::has_take<A>::value> {
258+
auto take(fixed_alloc && rhs) -> ipc::require<detail::has_take<A>::value> {
260259
base_t::take(std::move(rhs));
261260
alloc_.take(std::move(rhs.alloc_));
262261
}
@@ -395,7 +394,7 @@ class variable_alloc : public detail::variable_alloc_base {
395394
}
396395

397396
template <typename A = AllocP>
398-
auto take(variable_alloc && rhs) -> std::enable_if_t<detail::has_take<A>::value> {
397+
auto take(variable_alloc && rhs) -> ipc::require<detail::has_take<A>::value> {
399398
base_t::take(std::move(rhs));
400399
alloc_.take(std::move(rhs.alloc_));
401400
}

src/libipc/memory/wrapper.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ namespace mem {
2727

2828
namespace detail {
2929

30-
template <typename T>
31-
IPC_CONCEPT_(is_comparable, require<const T>([](auto && t)->decltype(t < t) {}));
30+
IPC_CONCEPT_(is_comparable, operator<(std::declval<Type>()));
3231

3332
} // namespace detail
3433

@@ -72,10 +71,8 @@ class limited_recycler<AllocP, true> {
7271
template <typename AllocP>
7372
class default_recycler : public limited_recycler<AllocP> {
7473

75-
template <typename T>
76-
IPC_CONCEPT_(has_remain, require<const T>([](auto && t)->decltype(t.remain()) {}));
77-
template <typename T>
78-
IPC_CONCEPT_(has_empty, require<const T>([](auto && t)->decltype(t.empty()) {}));
74+
IPC_CONCEPT_(has_remain, remain());
75+
IPC_CONCEPT_(has_empty , empty());
7976

8077
template <typename A>
8178
void try_fill(A & alc) {
@@ -89,28 +86,28 @@ class default_recycler : public limited_recycler<AllocP> {
8986

9087
template <typename A = AllocP>
9188
auto try_replenish(alloc_policy & alc, std::size_t size)
92-
-> std::enable_if_t<detail::has_take<A>::value && has_remain<A>::value> {
89+
-> ipc::require<detail::has_take<A>::value && has_remain<A>::value> {
9390
if (alc.remain() >= size) return;
9491
this->try_fill(alc);
9592
}
9693

9794
template <typename A = AllocP>
9895
auto try_replenish(alloc_policy & alc, std::size_t /*size*/)
99-
-> std::enable_if_t<detail::has_take<A>::value && !has_remain<A>::value && has_empty<A>::value> {
96+
-> ipc::require<detail::has_take<A>::value && !has_remain<A>::value && has_empty<A>::value> {
10097
if (!alc.empty()) return;
10198
this->try_fill(alc);
10299
}
103100

104101
template <typename A = AllocP>
105102
auto try_replenish(alloc_policy & alc, std::size_t /*size*/)
106-
-> std::enable_if_t<!detail::has_take<A>::value && has_empty<A>::value> {
103+
-> ipc::require<!detail::has_take<A>::value && has_empty<A>::value> {
107104
if (!alc.empty()) return;
108105
this->try_recover(alc);
109106
}
110107

111108
template <typename A = AllocP>
112109
IPC_CONSTEXPR_ auto try_replenish(alloc_policy & /*alc*/, std::size_t /*size*/) noexcept
113-
-> std::enable_if_t<(!detail::has_take<A>::value || !has_remain<A>::value) && !has_empty<A>::value> {
110+
-> ipc::require<(!detail::has_take<A>::value || !has_remain<A>::value) && !has_empty<A>::value> {
114111
// Do Nothing.
115112
}
116113
};

src/libipc/platform/tls_pointer_win.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @remarks
88
* Windows doesn't support a per-thread destructor with its TLS primitives.
99
* So, here will build it manually by inserting a function to be called on each thread's exit.
10+
*
1011
* @see
1112
* - https://www.codeproject.com/Articles/8113/Thread-Local-Storage-The-C-Way
1213
* - https://src.chromium.org/viewvc/chrome/trunk/src/base/threading/thread_local_storage_win.cc

src/libipc/platform/to_tchar.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@
1515
namespace ipc {
1616
namespace detail {
1717

18+
struct has_value_type_ {
19+
template <typename T> static std::true_type check(typename T::value_type *);
20+
template <typename T> static std::false_type check(...);
21+
};
22+
23+
template <typename T, typename U, typename = decltype(has_value_type_::check<U>(nullptr))>
24+
struct is_same_char : std::is_same<T, U> {};
25+
1826
template <typename T, typename U>
19-
IPC_CONCEPT_(has_same_char,
20-
require([]()->std::enable_if_t<std::is_same<T, typename U::value_type>::value> {}) ||
21-
require([]()->std::enable_if_t<std::is_same<T, U>::value> {})
22-
);
27+
struct is_same_char<T, U, std::true_type> : std::is_same<T, typename U::value_type> {};
2328

2429
template <typename T, typename S, typename R = S>
25-
using IsSameChar = std::enable_if_t<has_same_char<T, S>::value, R>;
30+
using IsSameChar = ipc::require<is_same_char<T, S>::value, R>;
2631

2732
////////////////////////////////////////////////////////////////
2833
/// to_tchar implementation

src/libipc/utility/concept.h

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
11
#pragma once
22

3-
#include <type_traits> // std::declval
3+
#include <type_traits> // std::enable_if
44

55
namespace ipc {
66

7-
/**
8-
* @remarks
9-
* <<Concepts emulation>> Concepts TS Improve on C++17
10-
* @see
11-
* - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0726r0.html
12-
* - https://www.youtube.com/watch?v=TorW5ekkL_w
13-
*/
14-
namespace detail {
7+
// concept helpers
158

16-
template <typename F, typename... Args,
17-
typename = decltype(std::declval<F&&>()(std::declval<Args&&>()...))>
18-
constexpr bool require_impl(int) { return true; }
19-
20-
template <typename F, typename... Args>
21-
constexpr bool require_impl(...) { return false; }
22-
23-
} // namespace detail
24-
25-
template <typename... Args, typename F>
26-
constexpr bool require(F&&) {
27-
return detail::require_impl<F&&, Args&&...>(int{});
28-
}
29-
30-
} // namespace ipc
31-
32-
/// concept helpers
9+
template <bool Cond, typename R = void>
10+
using require = typename std::enable_if<Cond, R>::type;
3311

3412
#ifdef IPC_CONCEPT_
3513
# error "IPC_CONCEPT_ has been defined."
3614
#endif
3715

38-
#define IPC_CONCEPT_($$name, $$what) \
39-
class $$name { \
40-
public: \
41-
constexpr static bool value = $$what; \
16+
#define IPC_CONCEPT_(NAME, WHAT) \
17+
template <typename T> \
18+
class NAME { \
19+
private: \
20+
template <typename Type> \
21+
static std::true_type check(decltype(std::declval<Type>().WHAT)*); \
22+
template <typename Type> \
23+
static std::false_type check(...); \
24+
public: \
25+
using type = decltype(check<T>(nullptr)); \
26+
constexpr static auto value = type::value; \
4227
}
28+
29+
} // namespace ipc

src/libipc/utility/pimpl.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@
88

99
namespace ipc {
1010

11-
template <typename T>
12-
IPC_CONCEPT_(is_impl_comfortable,
13-
require<T>([](auto && t)->std::enable_if_t<(sizeof(t) <= sizeof(T*))> {})
14-
);
11+
// pimpl small object optimization helpers
1512

1613
template <typename T, typename R = T*>
17-
using IsImplComfortable = std::enable_if_t<is_impl_comfortable<T>::value, R>;
14+
using IsImplComfortable = ipc::require<(sizeof(T) <= sizeof(T*)), R>;
1815

1916
template <typename T, typename R = T*>
20-
using IsImplUncomfortable = std::enable_if_t<!is_impl_comfortable<T>::value, R>;
21-
22-
// pimpl small object optimization helpers
17+
using IsImplUncomfortable = ipc::require<(sizeof(T) > sizeof(T*)), R>;
2318

2419
template <typename T, typename... P>
2520
constexpr auto make_impl(P&&... params) -> IsImplComfortable<T> {

0 commit comments

Comments
 (0)