Skip to content

Commit 70ecea5

Browse files
committed
fix compile for c++17
1 parent 7748d7a commit 70ecea5

9 files changed

Lines changed: 46 additions & 10 deletions

File tree

.github/workflows/ci.macos.arm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Build
2828
run: |
2929
cmake -B ${{github.workspace}}/build -D PHOTON_BUILD_TESTING=ON -D CMAKE_BUILD_TYPE=Release \
30-
-D PHOTON_ENABLE_SASL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3
30+
-D PHOTON_ENABLE_SASL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 -D PHOTON_CXX_STANDARD=17
3131
cmake --build ${{github.workspace}}/build -j $(nproc)
3232
3333
- name: Test

.github/workflows/ci.macos.x86.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Build
2828
run: |
2929
cmake -B ${{github.workspace}}/build -D PHOTON_BUILD_TESTING=ON -D CMAKE_BUILD_TYPE=Release \
30-
-D PHOTON_ENABLE_SASL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3
30+
-D PHOTON_ENABLE_SASL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 -D PHOTON_CXX_STANDARD=17
3131
cmake --build ${{github.workspace}}/build -j $(nproc)
3232
3333
- name: Test

common/enumerable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ struct Enumerable
4141
if (obj && !obj->valid())
4242
this->obj = nullptr;
4343
}
44+
#if __cplusplus < 201703L
4445
using R = typename std::result_of<decltype(&T::get)(T)>::type;
46+
#else
47+
using R = typename std::invoke_result<decltype(&T::get), T>::type;
48+
#endif
4549
R operator*() { return obj ? obj->get() : R{}; }
4650
bool operator==(const iterator& rhs) const { return obj == rhs.obj; }
4751
bool operator!=(const iterator& rhs) const { return !(*this == rhs); }

common/executor/executor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ class Executor {
3333

3434
template <
3535
typename Context = AutoContext, typename Func,
36+
#if __cplusplus < 201703L
3637
typename R = typename std::result_of<Func()>::type,
38+
#else
39+
typename R = typename std::invoke_result<Func>::type,
40+
#endif
3741
typename _ = typename std::enable_if<!std::is_void<R>::value, R>::type>
3842
R perform(Func &&act) {
3943
R result;
@@ -52,7 +56,11 @@ class Executor {
5256

5357
template <
5458
typename Context = AutoContext, typename Func,
59+
#if __cplusplus < 201703L
5560
typename R = typename std::result_of<Func()>::type,
61+
#else
62+
typename R = typename std::invoke_result<Func>::type,
63+
#endif
5664
typename _ = typename std::enable_if<std::is_void<R>::value, R>::type>
5765
void perform(Func &&act) {
5866
Awaiter<Context> aop;

common/ring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ssize_t RingBuffer::do_read(void *buf, size_t count)
6060
ssize_t RingBuffer::readv(const struct iovec *iov, int iovcnt)
6161
{
6262
ssize_t size = 0;
63-
scoped_lock lock(m_read_lock);
63+
photon::scoped_lock lock(m_read_lock);
6464
for (auto& x: ptr_array(iov, iovcnt))
6565
{
6666
auto ret = do_read(x.iov_base, x.iov_len);
@@ -110,7 +110,7 @@ ssize_t RingBuffer::do_write(const void* buf, size_t count)
110110
ssize_t RingBuffer::writev(const struct iovec *iov, int iovcnt)
111111
{
112112
ssize_t size = 0;
113-
scoped_lock lock(m_write_lock);
113+
photon::scoped_lock lock(m_write_lock);
114114
for (auto& x: ptr_array(iov, iovcnt))
115115
{
116116
auto ret = do_write(x.iov_base, x.iov_len);

fs/async_filesystem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ namespace fs
8585
{
8686
public:
8787
template<typename IF, typename Func, typename...ARGS,
88+
#if __cplusplus < 201703L
8889
typename R = typename std::result_of<Func(IF*, ARGS...)>::type >
90+
#else
91+
typename R = typename std::invoke_result<Func, IF*, ARGS...>::type>
92+
#endif
8993
R perform(IF* _if, Func func, ARGS...args)
9094
{
9195
return th_performer<R>().call(_if, func, args...);

rpc/test/test-ooo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020
#include <thread>
2121
#include <algorithm>
2222

23-
#include <gtest/gtest.h>
23+
#include "../../test/gtest.h"
2424
#include <gflags/gflags.h>
2525
#include <photon/common/alog.h>
2626

@@ -58,7 +58,7 @@ int do_issue(void*, OutOfOrderContext* args)
5858
auto tag = args->tag;
5959
LOG_DEBUG(VALUE(tag));
6060
aop.push_back(args->tag);
61-
random_shuffle(aop.begin(), aop.end());
61+
shuffle(aop.begin(), aop.end());
6262
return 0;
6363
}
6464

@@ -121,7 +121,7 @@ int heavy_complete(void*, OutOfOrderContext* args) {
121121
int process_thread() {
122122
while (issue_list.size()) {
123123
thread_yield();
124-
random_shuffle(issue_list.begin(), issue_list.end());
124+
shuffle(issue_list.begin(), issue_list.end());
125125
processing_queue.push(issue_list.back());
126126
issue_list.pop_back();
127127
}
@@ -207,7 +207,7 @@ inline int error_complete(void*, OutOfOrderContext* args) {
207207
inline int error_process() {
208208
while (issue_list.size()) {
209209
thread_yield_to(nullptr);
210-
random_shuffle(issue_list.begin(), issue_list.end());
210+
shuffle(issue_list.begin(), issue_list.end());
211211
auto val = issue_list.back();
212212
if (rand()%2)
213213
val = UINT64_MAX;

test/gtest.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
#include <random>
3+
#include <algorithm>
4+
5+
// #pragma GCC diagnostic push
6+
// #ifdef __clang__
7+
#pragma GCC diagnostic ignored "-Wsign-compare"
8+
#pragma GCC diagnostic ignored "-Wunused-result"
9+
10+
// #endif
11+
#include <gtest/gtest.h>
12+
#include <gtest/gtest-spi.h>
13+
// #pragma GCC diagnostic pop
14+
15+
template< class RandomIt> inline
16+
void shuffle( RandomIt first, RandomIt last) {
17+
std::random_device rd;
18+
std::mt19937 g(rd());
19+
return std::shuffle(first, last, g);
20+
}

thread/test/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License.
2323
#include <algorithm>
2424
#include <sys/time.h>
2525
#include <gflags/gflags.h>
26-
#include <gtest/gtest.h>
26+
#include "../../test/gtest.h"
2727
#include <photon/common/alog-audit.h>
2828

2929
#define private public
@@ -140,7 +140,7 @@ void sleepq_perf(SleepQueue& sleepq, const vector<photon::thread*>& items)
140140
check(sleepq);
141141

142142
auto pops = items;
143-
random_shuffle(pops.begin(), pops.end());
143+
shuffle(pops.begin(), pops.end());
144144
pops.resize(pops.size()/2);
145145
{
146146
update_now();

0 commit comments

Comments
 (0)