Skip to content

Commit

Permalink
A fix for issue #64.
Browse files Browse the repository at this point in the history
  • Loading branch information
eao197 committed Nov 29, 2019
1 parent d080dab commit 4e1ab4e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dev/restinio/cmake/target.cmake
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set(RESTINIO_VERSION "0.6.1")
set(RESTINIO_VERSION "0.6.1.1")
66 changes: 66 additions & 0 deletions dev/restinio/compiler_features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,69 @@
#define RESTINIO_STATIC_ASSERT_NOT_NOEXCEPT(expr) \
static_assert(!noexcept(expr), #expr " is not expected to be noexcept" )

namespace restinio
{

namespace static_if_details
{

template< bool Condition >
struct static_if_impl;

template<>
struct static_if_impl<true>
{
template<typename If_Part, typename Else_Part>
static decltype(auto)
call( If_Part && if_part, Else_Part && )
{
return if_part();
}
};

template<>
struct static_if_impl<false>
{
template<typename If_Part, typename Else_Part>
static decltype(auto)
call( If_Part &&, Else_Part && else_part )
{
return else_part();
}
};

} /* namespace static_if_details */

//
// static_if_else
//
/*!
* @brief An emulation of if constexpr for C++14.
*
* Usage example:
* @code
* static_if_else< noexcept(some-expression) >(
* []() noexcept {
* ... // Some action that doesn't throw.
* },
* [] {
* try {
* ... // Some action that throws.
* }
* catch(...) {}
* });
* @endcode
*
* @since v.0.6.1.1
*/
template< bool Condition, typename If_Part, typename Else_Part >
decltype(auto)
static_if_else( If_Part && if_part, Else_Part && else_part )
{
return static_if_details::static_if_impl<Condition>::call(
std::forward<If_Part>(if_part),
std::forward<Else_Part>(else_part) );
}

} /* namespace restinio */

22 changes: 14 additions & 8 deletions dev/restinio/impl/response_coordinator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ class response_context_t

write_group_t result{ std::move( m_write_groups.front() ) };

// We expect that m_write_groups.erase() isn't noexpect
// and because of that this call should be done via
// suppress_exceptions_quietly.
RESTINIO_STATIC_ASSERT_NOT_NOEXCEPT(
m_write_groups.erase(m_write_groups.begin()) );
restinio::utils::suppress_exceptions_quietly( [this] {
m_write_groups.erase( begin( m_write_groups ) );
} );
// Some STL implementation can have std::vector::erase that
// doesn't throw. So we use a kind of static if to select
// an appropriate behaviour.
static_if_else< noexcept(m_write_groups.erase(m_write_groups.begin())) >(
// This is for the case when std::vector::erase doesn't throw.
[this]() noexcept {
m_write_groups.erase( m_write_groups.begin() );
},
// This is for the case when std::vector::erase does throw.
[this]() {
restinio::utils::suppress_exceptions_quietly( [this] {
m_write_groups.erase( m_write_groups.begin() );
} );
} );

return result;
}
Expand Down

0 comments on commit 4e1ab4e

Please sign in to comment.