Skip to content

Commit 9e3b7b5

Browse files
committed
relax requirements: use c++11 instead c++14
1 parent 9efae77 commit 9e3b7b5

15 files changed

+153
-119
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
cmake_minimum_required(VERSION 3.0)
22
project (bredis)
33

4-
set(CMAKE_CXX_STANDARD 14)
4+
set(CMAKE_CXX_STANDARD 11)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

77
include (CTest)
88
enable_testing()
99

1010

11-
1211
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
1312
add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
1413
#add_definitions(-DBREDIS_DEBUG)

examples/multi-threads-1.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@
3535
namespace r = bredis;
3636
namespace asio = boost::asio;
3737
namespace po = boost::program_options;
38+
namespace sys = boost::system;
3839

3940
using socket_t = asio::ip::tcp::socket;
4041
using next_layer_t = socket_t;
4142
//using next_layer_t = r::test::SocketWithLogging<asio::ip::tcp::socket>;
4243
using Buffer = boost::asio::streambuf;
4344
using Iterator = typename r::to_iterator<Buffer>::iterator_t;
45+
using Policy = r::parsing_policy::keep_result;
46+
using result_t = r::positive_parse_result_t<Iterator, Policy>;
4447
using Connection = r::Connection<next_layer_t>;
4548

4649
struct redis_accessor_t {
@@ -64,8 +67,9 @@ struct producer_t {
6467
redis.conn.async_write(
6568
redis.tx_buff,
6669
cmd_ping,
67-
asio::bind_executor(redis.strand, [self = this](const auto &error_code, size_t bytes_transferred){
68-
if (!error_code){
70+
asio::bind_executor(redis.strand, [this](const sys::error_code &ec, std::size_t bytes_transferred){
71+
if (!ec){
72+
auto self = this;
6973
self->redis.ping_count++;
7074
self->redis.tx_buff.consume(bytes_transferred);
7175
self->produce();
@@ -83,8 +87,9 @@ struct consumer_t {
8387
void consume(){
8488
redis.conn.async_read(
8589
redis.rx_buff,
86-
asio::bind_executor(redis.strand, [self = this](const auto &error_code, auto &&r){
87-
if(!error_code){
90+
asio::bind_executor(redis.strand, [this](const sys::error_code &ec, result_t &&r){
91+
if(!ec){
92+
auto self = this;
8893
self->redis.pong_count++;
8994
self->redis.rx_buff.consume(r.consumed);
9095
self->consume();
@@ -103,8 +108,9 @@ struct watcher_t {
103108
void watch() {
104109
timer.expires_after(asio::chrono::seconds(1));
105110
timer.async_wait(
106-
asio::bind_executor(redis.strand, [self = this](const auto &error_code){
107-
if (!error_code) {
111+
asio::bind_executor(redis.strand, [this](const sys::error_code &ec){
112+
if (!ec) {
113+
auto self = this;
108114
std::cout << "pings: " << self->redis.ping_count << ", pongs: " << self->redis.pong_count << "\n";
109115
self->watch();
110116
}

include/bredis/Command.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//
77
#pragma once
88

9+
#include <boost/core/enable_if.hpp>
910
#include <boost/utility/string_ref.hpp>
1011
#include <boost/variant.hpp>
11-
#include <type_traits>
1212
#include <vector>
1313

1414
#include "Result.hpp"
@@ -31,14 +31,14 @@ struct single_command_t {
3131
args_container_t arguments;
3232

3333
template <typename... Args,
34-
typename = std::enable_if_t<detail::are_all_constructible<
34+
typename = boost::enable_if_t<detail::are_all_constructible<
3535
boost::string_ref, Args...>::value>>
3636
single_command_t(Args &&... args) : arguments{std::forward<Args>(args)...} {
3737
static_assert(sizeof...(Args) >= 1, "Empty command is not allowed");
3838
}
3939

4040
template <typename InputIterator,
41-
typename = std::enable_if_t<std::is_constructible<
41+
typename = boost::enable_if_t<std::is_constructible<
4242
boost::string_ref, typename std::iterator_traits<
4343
InputIterator>::value_type>::value>>
4444
single_command_t(InputIterator first, InputIterator last)

include/bredis/MarkerHelpers.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include <algorithm>
11+
#include <boost/algorithm/cxx14/equal.hpp>
1112
#include <boost/convert.hpp>
1213
#include <boost/convert/lexical_cast.hpp>
1314
#include <cctype>
@@ -81,21 +82,22 @@ class equality : public boost::static_visitor<bool> {
8182
}
8283

8384
bool operator()(const markers::string_t<Iterator> &value) const {
84-
auto helper = stringizer<Iterator>();
85-
auto str = helper(value);
86-
return std::equal(begin_, end_, value.from, value.to);
85+
return boost::algorithm::equal(begin_, end_, value.from, value.to);
8786
}
8887

8988
bool operator()(const markers::int_t<Iterator> &value) const {
90-
return std::equal(begin_, end_, value.string.from, value.string.to);
89+
return boost::algorithm::equal(begin_, end_, value.string.from,
90+
value.string.to);
9191
}
9292

9393
bool operator()(const markers::error_t<Iterator> &value) const {
94-
return std::equal(begin_, end_, value.string.from, value.string.to);
94+
return boost::algorithm::equal(begin_, end_, value.string.from,
95+
value.string.to);
9596
}
9697

9798
bool operator()(const markers::nil_t<Iterator> &value) const {
98-
return std::equal(begin_, end_, value.string.from, value.string.to);
99+
return boost::algorithm::equal(begin_, end_, value.string.from,
100+
value.string.to);
99101
}
100102
};
101103

@@ -172,8 +174,8 @@ class check_subscription : public boost::static_visitor<bool> {
172174
}
173175

174176
const auto &channel_ = cmd_.arguments[idx];
175-
return std::equal(channel_.cbegin(), channel_.cend(), channel->from,
176-
channel->to);
177+
return boost::algorithm::equal(channel_.cbegin(), channel_.cend(),
178+
channel->from, channel->to);
177179
}
178180
return false;
179181
}

include/bredis/impl/connection.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#include "common.ipp"
1111
#include <algorithm>
12+
#include <boost/type_traits/decay.hpp>
1213
#include <cassert>
1314
#include <ostream>
14-
#include <type_traits>
1515

1616
#include "async_op.ipp"
1717

@@ -29,7 +29,7 @@ Connection<NextLayer>::async_write(DynamicBuffer &tx_buff,
2929

3030
using boost::asio::async_write;
3131
using Signature = void(boost::system::error_code, std::size_t);
32-
using Callback = std::decay_t<WriteCallback>;
32+
using Callback = boost::decay_t<WriteCallback>;
3333
using AsyncResult = asio::async_result<Callback, Signature>;
3434
using CompletionHandler = typename AsyncResult::completion_handler_type;
3535
using serializer_t = command_serializer_visitor<DynamicBuffer>;
@@ -58,7 +58,7 @@ Connection<NextLayer>::async_read(DynamicBuffer &rx_buff,
5858
using Iterator = typename to_iterator<DynamicBuffer>::iterator_t;
5959
using ParseResult = BREDIS_PARSE_RESULT(DynamicBuffer, Policy);
6060
using Signature = void(boost::system::error_code, ParseResult);
61-
using Callback = std::decay_t<ReadCallback>;
61+
using Callback = boost::decay_t<ReadCallback>;
6262
using AsyncResult = asio::async_result<Callback, Signature>;
6363
using CompletionHandler = typename AsyncResult::completion_handler_type;
6464
using ReadOp =

t/10-ping.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace r = bredis;
1414
namespace asio = boost::asio;
1515
namespace ep = empty_port;
1616
namespace ts = test_server;
17+
namespace sys = boost::system;
1718

1819
TEST_CASE("ping", "[connection]") {
1920
using socket_t = asio::ip::tcp::socket;
@@ -48,10 +49,11 @@ TEST_CASE("ping", "[connection]") {
4849
Buffer tx_buff, rx_buff;
4950

5051
c.async_write(
51-
tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) {
52+
tx_buff, "ping",
53+
[&](const sys::error_code &error_code, std::size_t bytes_transferred) {
5254
REQUIRE(!error_code);
5355
tx_buff.consume(bytes_transferred);
54-
c.async_read(rx_buff, [&](const auto&, auto &&r) {
56+
c.async_read(rx_buff, [&](const sys::error_code &, result_t &&r) {
5557
completion_promise.set_value(r);
5658
rx_buff.consume(r.consumed);
5759
});

t/11-multi-ping.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <boost/asio.hpp>
22
#include <future>
3-
#include <vector>
43
#include <string>
4+
#include <vector>
55

66
#include "EmptyPort.hpp"
77
#include "SocketWithLogging.hpp"
@@ -14,6 +14,7 @@ namespace r = bredis;
1414
namespace asio = boost::asio;
1515
namespace ep = empty_port;
1616
namespace ts = test_server;
17+
namespace sys = boost::system;
1718

1819
TEST_CASE("ping", "[connection]") {
1920
using socket_t = asio::ip::tcp::socket;
@@ -59,23 +60,23 @@ TEST_CASE("ping", "[connection]") {
5960
std::future<result_t> completion_future = completion_promise.get_future();
6061

6162
Buffer tx_buff, rx_buff;
62-
read_callback_t read_callback =
63-
[&](const boost::system::error_code &error_code, ParseResult &&r) {
64-
if (error_code) {
65-
BREDIS_LOG_DEBUG("error: " << error_code.message());
66-
REQUIRE(!error_code);
67-
}
63+
read_callback_t read_callback = [&](const sys::error_code &error_code,
64+
ParseResult &&r) {
65+
if (error_code) {
66+
BREDIS_LOG_DEBUG("error: " << error_code.message());
6867
REQUIRE(!error_code);
69-
auto &replies =
70-
boost::get<r::markers::array_holder_t<Iterator>>(r.result);
71-
BREDIS_LOG_DEBUG("callback, size: " << replies.elements.size());
72-
REQUIRE(replies.elements.size() == count);
73-
completion_promise.set_value();
74-
rx_buff.consume(r.consumed);
75-
};
68+
}
69+
REQUIRE(!error_code);
70+
auto &replies =
71+
boost::get<r::markers::array_holder_t<Iterator>>(r.result);
72+
BREDIS_LOG_DEBUG("callback, size: " << replies.elements.size());
73+
REQUIRE(replies.elements.size() == count);
74+
completion_promise.set_value();
75+
rx_buff.consume(r.consumed);
76+
};
7677

77-
write_callback_t write_callback = [&](
78-
const boost::system::error_code &error_code, auto bytes_transferred) {
78+
write_callback_t write_callback = [&](const sys::error_code &error_code,
79+
std::size_t bytes_transferred) {
7980
(void)bytes_transferred;
8081
BREDIS_LOG_DEBUG("write_callback");
8182
if (error_code) {

t/12-basic-types.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace r = bredis;
1515
namespace asio = boost::asio;
1616
namespace ep = empty_port;
1717
namespace ts = test_server;
18+
namespace sys = boost::system;
1819

1920
TEST_CASE("ping", "[connection]") {
2021
using socket_t = asio::ip::tcp::socket;
@@ -64,7 +65,7 @@ TEST_CASE("ping", "[connection]") {
6465
r::single_command_t("time"),
6566
};
6667
std::vector<read_callback_t> callbacks{
67-
[&](const boost::system::error_code&error_code, ParseResult &&r) {
68+
[&](const boost::system::error_code &error_code, ParseResult &&r) {
6869
auto extract = boost::apply_visitor(Extractor(), r.result);
6970
REQUIRE(boost::get<r::extracts::int_t>(extract) == 0);
7071
REQUIRE(order == 0);
@@ -120,12 +121,13 @@ TEST_CASE("ping", "[connection]") {
120121
c.async_read(rx_buff, generic_callback);
121122
};
122123

123-
c.async_write(tx_buff, r::command_wrapper_t(cmds_container),
124-
[&](const auto &error_code, auto bytes_transferred) {
125-
REQUIRE(!error_code);
126-
tx_buff.consume(bytes_transferred);
127-
c.async_read(rx_buff, generic_callback);
128-
});
124+
c.async_write(
125+
tx_buff, r::command_wrapper_t(cmds_container),
126+
[&](const sys::error_code &ec, std::size_t bytes_transferred) {
127+
REQUIRE(!ec);
128+
tx_buff.consume(bytes_transferred);
129+
c.async_read(rx_buff, generic_callback);
130+
});
129131

130132
while (completion_future.wait_for(sleep_delay) !=
131133
std::future_status::ready) {

t/13-protol-error.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace r = bredis;
1313
namespace asio = boost::asio;
1414
namespace sys = boost::system;
1515
namespace ep = empty_port;
16+
namespace sys = boost::system;
1617

1718
TEST_CASE("protocol-error", "[connection]") {
1819
using socket_t = asio::ip::tcp::socket;
@@ -53,17 +54,18 @@ TEST_CASE("protocol-error", "[connection]") {
5354
async_read_until(
5455
peer_socket, remote_rx_buff, end_marker,
5556
[&](const sys::error_code &ec, std::size_t sz) {
56-
(void)ec;(void)sz;
57+
(void)ec;
58+
(void)sz;
5759
BREDIS_LOG_DEBUG("async_read: " << sz << ", " << ec.message());
5860

5961
async_write(peer_socket, output_buf,
6062
[&](const sys::error_code &ec, std::size_t sz) {
61-
(void)ec;(void)sz;
63+
(void)ec;
64+
(void)sz;
6265
BREDIS_LOG_DEBUG("async_write: "
6366
<< sz << ", " << ec.message());
6467
});
6568
});
66-
6769
});
6870

6971
socket_t socket(io_service, end_point.protocol());
@@ -75,14 +77,16 @@ TEST_CASE("protocol-error", "[connection]") {
7577

7678
Buffer rx_buff, tx_buff;
7779
c.async_write(
78-
tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) {
79-
REQUIRE(!error_code);
80+
tx_buff, "ping",
81+
[&](const sys::error_code &ec, std::size_t bytes_transferred) {
82+
REQUIRE(!ec);
8083
tx_buff.consume(bytes_transferred);
81-
c.async_read(rx_buff, [&](const auto &error_code, ParseResult &&) {
82-
REQUIRE(error_code);
83-
REQUIRE(error_code.message() == "Wrong introduction");
84-
completion_promise.set_value();
85-
});
84+
c.async_read(rx_buff,
85+
[&](const sys::error_code &ec, ParseResult &&) {
86+
REQUIRE(ec);
87+
REQUIRE(ec.message() == "Wrong introduction");
88+
completion_promise.set_value();
89+
});
8690
});
8791
while (completion_future.wait_for(sleep_delay) !=
8892
std::future_status::ready) {

t/14-uds.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace r = bredis;
1818
namespace asio = boost::asio;
1919
namespace ts = test_server;
2020
namespace ep = empty_port;
21+
namespace sys = boost::system;
2122

2223
struct tmpfile_holder_t {
2324
char *filename_;
@@ -75,9 +76,9 @@ TEST_CASE("ping", "[connection]") {
7576
std::future<result_t> completion_future = completion_promise.get_future();
7677
Buffer rx_buff, tx_buff;
7778

78-
read_callback_t read_callback = [&](const auto &error_code,
79+
read_callback_t read_callback = [&](const sys::error_code &ec,
7980
ParseResult &&r) {
80-
REQUIRE(!error_code);
81+
REQUIRE(!ec);
8182
rx_buff.consume(r.consumed);
8283

8384
auto str = boost::apply_visitor(
@@ -96,12 +97,13 @@ TEST_CASE("ping", "[connection]") {
9697
completion_promise.set_value();
9798
};
9899

99-
c.async_write(tx_buff, cmd,
100-
[&](const auto &error_code, auto bytes_transferred) {
101-
REQUIRE(!error_code);
102-
tx_buff.consume(bytes_transferred);
103-
c.async_read(rx_buff, read_callback, count);
104-
});
100+
c.async_write(
101+
tx_buff, cmd,
102+
[&](const sys::error_code &ec, std::size_t bytes_transferred) {
103+
REQUIRE(!ec);
104+
tx_buff.consume(bytes_transferred);
105+
c.async_read(rx_buff, read_callback, count);
106+
});
105107

106108
while (completion_future.wait_for(sleep_delay) !=
107109
std::future_status::ready) {

0 commit comments

Comments
 (0)