diff --git a/Release/include/cpprest/details/basic_types.h b/Release/include/cpprest/details/basic_types.h index d2ceb87189..83dbb21a50 100644 --- a/Release/include/cpprest/details/basic_types.h +++ b/Release/include/cpprest/details/basic_types.h @@ -129,3 +129,18 @@ typedef std::basic_istringstream utf16istringstream; #endif #endif #endif + +// This is not really a basic type, but define this macro in this header +// because it's included by all the other ones and this macro needs to be +// available in several places. +#if defined(_MSVC_LANG) +#define CPPREST_CHECK_CXX_STD(ver) (_MSVC_LANG >= (ver)) +#else +#define CPPREST_CHECK_CXX_STD(ver) (__cplusplus >= (ver)) +#endif + +#if CPPREST_CHECK_CXX_STD(202002L) +#define CPPREST_CAPTURE_THIS ,this +#else +#define CPPREST_CAPTURE_THIS +#endif diff --git a/Release/include/cpprest/filestream.h b/Release/include/cpprest/filestream.h index 1e4a0f278e..f7a103a9ba 100644 --- a/Release/include/cpprest/filestream.h +++ b/Release/include/cpprest/filestream.h @@ -239,7 +239,7 @@ class basic_file_buffer : public details::streambuf_state_manager<_CharType> // Neither heads are open. Close the underlying device // We need to flush all writes if the file was opened for writing. - return flush_internal().then([=](pplx::task flushTask) -> pplx::task { + return flush_internal().then([= CPPREST_CAPTURE_THIS](pplx::task flushTask) -> pplx::task { // swallow exception from flush try { @@ -527,7 +527,7 @@ class basic_file_buffer : public details::streambuf_state_manager<_CharType> /// reached, EOF if there is some error. virtual pplx::task _getn(_Out_writes_(count) _CharType* ptr, _In_ size_t count) { - return m_readOps.enqueue_operation([=]() -> pplx::task { + return m_readOps.enqueue_operation([= CPPREST_CAPTURE_THIS]() -> pplx::task { if (m_info->m_atend || count == 0) return pplx::task_from_result(0); if (_in_avail_unprot() >= count) diff --git a/Release/include/pplx/pplxtasks.h b/Release/include/pplx/pplxtasks.h index 6868fc1619..b903302793 100644 --- a/Release/include/pplx/pplxtasks.h +++ b/Release/include/pplx/pplxtasks.h @@ -2514,7 +2514,7 @@ struct _Task_impl : public _Task_impl_base if (_M_Continuations) { // Scheduling cancellation with automatic inlining. - _ScheduleFuncWithAutoInline([=]() { _RunTaskContinuations(); }, details::_DefaultAutoInline); + _ScheduleFuncWithAutoInline([= CPPREST_CAPTURE_THIS]() { _RunTaskContinuations(); }, details::_DefaultAutoInline); } } return true; diff --git a/Release/src/http/listener/http_server_asio.cpp b/Release/src/http/listener/http_server_asio.cpp index e83b9ff525..052189441e 100644 --- a/Release/src/http/listener/http_server_asio.cpp +++ b/Release/src/http/listener/http_server_asio.cpp @@ -420,7 +420,7 @@ class asio_server_connection will_erase_from_parent_t do_response() { auto unique_reference = this->get_reference(); - get_request().get_response().then([=](pplx::task r_task) { + get_request().get_response().then([= CPPREST_CAPTURE_THIS](pplx::task r_task) { http_response response; try { @@ -434,7 +434,7 @@ class asio_server_connection serialize_headers(response); // before sending response, the full incoming message need to be processed. - return get_request().content_ready().then([=](pplx::task) { + return get_request().content_ready().then([= CPPREST_CAPTURE_THIS](pplx::task) { (will_deref_and_erase_t) this->async_write(&asio_server_connection::handle_headers_written, response); }); }); @@ -444,7 +444,7 @@ class asio_server_connection will_erase_from_parent_t do_bad_response() { auto unique_reference = this->get_reference(); - get_request().get_response().then([=](pplx::task r_task) { + get_request().get_response().then([= CPPREST_CAPTURE_THIS](pplx::task r_task) { http_response response; try { @@ -882,7 +882,7 @@ will_deref_t asio_server_connection::handle_chunked_body(const boost::system::er { auto writebuf = requestImpl->outstream().streambuf(); writebuf.putn_nocopy(buffer_cast(m_request_buf.data()), toWrite) - .then([=](pplx::task writeChunkTask) -> will_deref_t { + .then([= CPPREST_CAPTURE_THIS](pplx::task writeChunkTask) -> will_deref_t { try { writeChunkTask.get(); @@ -947,13 +947,13 @@ will_deref_and_erase_t asio_server_connection::async_write(WriteFunc response_fu { if (m_ssl_stream) { - boost::asio::async_write(*m_ssl_stream, m_response_buf, [=](const boost::system::error_code& ec, std::size_t) { + boost::asio::async_write(*m_ssl_stream, m_response_buf, [= CPPREST_CAPTURE_THIS](const boost::system::error_code& ec, std::size_t) { (this->*response_func_ptr)(response, ec); }); } else { - boost::asio::async_write(*m_socket, m_response_buf, [=](const boost::system::error_code& ec, std::size_t) { + boost::asio::async_write(*m_socket, m_response_buf, [= CPPREST_CAPTURE_THIS](const boost::system::error_code& ec, std::size_t) { (this->*response_func_ptr)(response, ec); }); } @@ -1135,7 +1135,7 @@ will_deref_and_erase_t asio_server_connection::handle_write_chunked_response(con auto membuf = m_response_buf.prepare(ChunkSize + chunked_encoding::additional_encoding_space); readbuf.getn(buffer_cast(membuf) + chunked_encoding::data_offset, ChunkSize) - .then([=](pplx::task actualSizeTask) -> will_deref_and_erase_t { + .then([= CPPREST_CAPTURE_THIS](pplx::task actualSizeTask) -> will_deref_and_erase_t { size_t actualSize = 0; try { @@ -1168,7 +1168,7 @@ will_deref_and_erase_t asio_server_connection::handle_write_large_response(const response, std::make_exception_ptr(http_exception("Response stream close early!"))); size_t readBytes = (std::min)(ChunkSize, m_write_size - m_write); readbuf.getn(buffer_cast(m_response_buf.prepare(readBytes)), readBytes) - .then([=](pplx::task actualSizeTask) -> will_deref_and_erase_t { + .then([= CPPREST_CAPTURE_THIS](pplx::task actualSizeTask) -> will_deref_and_erase_t { size_t actualSize = 0; try {