Skip to content

Commit ca6c066

Browse files
committed
Autodetect C++11 features and adjust accordingly
Uses boost macros to figure out which features are present.
1 parent 43d9801 commit ca6c066

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/socket_io_client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ void socketio_client_handler::on_open(connection_ptr con)
4242
{
4343
m_con = con;
4444
// Create the heartbeat timer and use the same io_service as the main event loop.
45+
#ifndef BOOST_NO_CXX11_SMART_PTR
4546
m_heartbeatTimer = std::unique_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(con->get_io_service(), boost::posix_time::seconds(0)));
47+
#else
48+
m_heartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(con->get_io_service(), boost::posix_time::seconds(0)));
49+
#endif
4650
start_heartbeat();
4751
m_connected = true;
4852

src/socket_io_client.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ class socketio_client_handler : public client::handler {
7171
// Function pointer to a event handler.
7272
// Args is an array, managed by rapidjson, and could be null
7373
// Can change to whatever signature you want, just make sure to change the call in on_socketio_event too.
74+
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
75+
// If you're using C++11 and have the proper functional header in the standard lib, we'll use that
7476
typedef std::function<void (socketio_events&, const Value&)> eventFunc;
77+
#else
78+
// Otherwise we'll let boost fill in the gaps
79+
typedef boost::function<void (socketio_events&, const Value&)> eventFunc;
80+
#endif
7581

7682
// Performs a socket.IO handshake
7783
// https://github.com/LearnBoost/socket.io-spec
@@ -152,7 +158,14 @@ class socketio_client_handler : public client::handler {
152158
std::string m_transports;
153159

154160
// Heartbeat variabes.
161+
#ifndef BOOST_NO_CXX11_SMART_PTR
162+
// If you're using C++11 use the standar library smart pointer
155163
std::unique_ptr<boost::asio::deadline_timer> m_heartbeatTimer;
164+
#else
165+
// Otherwise let boost provideo the smart pointer
166+
boost::shared_ptr<boost::asio::deadline_timer> m_heartbeatTimer;
167+
#endif
168+
156169
bool m_heartbeatActive;
157170

158171
// Event bindings

0 commit comments

Comments
 (0)