Skip to content

Commit

Permalink
Merge pull request #969 from bugdea1er/configuration
Browse files Browse the repository at this point in the history
Remove `CROW_CAN_USE_CPP14` and `CROW_CAN_USE_CPP17` macros
  • Loading branch information
gittiver authored Jan 6, 2025
2 parents 849eb87 + eb644ed commit c148be0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 138 deletions.
8 changes: 0 additions & 8 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,8 @@ namespace crow

/// \brief Create a route using a rule (**Use CROW_ROUTE instead**)
template<uint64_t Tag>
#ifdef CROW_GCC83_WORKAROUND
auto& route(const std::string& rule)
#else
auto route(const std::string& rule)
#endif
#if defined CROW_CAN_USE_CPP17 && !defined CROW_GCC83_WORKAROUND
-> typename std::invoke_result<decltype(&Router::new_rule_tagged<Tag>), Router, const std::string&>::type
#elif !defined CROW_GCC83_WORKAROUND
-> typename std::result_of<decltype (&Router::new_rule_tagged<Tag>)(Router, const std::string&)>::type
#endif
{
return router_.new_rule_tagged<Tag>(rule);
}
Expand Down
40 changes: 0 additions & 40 deletions include/crow/middlewares/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include <functional>
#include <chrono>

#ifdef CROW_CAN_USE_CPP17
#include <variant>
#endif

namespace
{
Expand Down Expand Up @@ -53,7 +51,6 @@ namespace crow
namespace session
{

#ifdef CROW_CAN_USE_CPP17
using multi_value_types = black_magic::S<bool, int64_t, double, std::string>;

/// A multi_value is a safe variant wrapper with json conversion support
Expand Down Expand Up @@ -118,38 +115,6 @@ namespace crow
default: return multi_value{false};
}
}
#else
// Fallback for C++11/14 that uses a raw json::wvalue internally.
// This implementation consumes significantly more memory
// than the variant-based version
struct multi_value
{
json::wvalue json() const { return v_; }

static multi_value from_json(const json::rvalue&);

std::string string() const { return v_.dump(); }

template<typename T, typename RT = wrap_mv_t<T>>
RT get(const T& fallback)
{
return json::wvalue_reader{v_}.get((const RT&)(fallback));
}

template<typename T, typename RT = wrap_mv_t<T>>
void set(T val)
{
v_ = RT(std::move(val));
}

json::wvalue v_;
};

inline multi_value multi_value::from_json(const json::rvalue& rv)
{
return {rv};
}
#endif

/// Expiration tracker keeps track of soonest-to-expire keys
struct ExpirationTracker
Expand Down Expand Up @@ -226,13 +191,8 @@ namespace crow
template<typename Store>
struct SessionMiddleware
{
#ifdef CROW_CAN_USE_CPP17
using lock = std::scoped_lock<std::mutex>;
using rc_lock = std::scoped_lock<std::recursive_mutex>;
#else
using lock = std::lock_guard<std::mutex>;
using rc_lock = std::lock_guard<std::recursive_mutex>;
#endif

struct context
{
Expand Down
66 changes: 18 additions & 48 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,10 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename... Args>
void set_(Func f, typename std::enable_if<!std::is_same<typename std::tuple_element<0, std::tuple<Args..., void>>::type, const request&>::value, int>::type = 0)
{
handler_ = (
#ifdef CROW_CAN_USE_CPP14
[f = std::move(f)]
#else
[f]
#endif
(const request&, response& res, Args... args) {
res = response(f(args...));
res.end();
});
handler_ = ([f = std::move(f)](const request&, response& res, Args... args) {
res = response(f(args...));
res.end();
});
}

template<typename Req, typename... Args>
Expand Down Expand Up @@ -354,16 +348,10 @@ namespace crow // NOTE: Already documented in "crow/app.h"
static_assert(!std::is_same<void, decltype(f())>::value,
"Handler function cannot have void return type; valid return types: string, int, crow::response, crow::returnable");

handler_ = (
#ifdef CROW_CAN_USE_CPP14
[f = std::move(f)]
#else
[f]
#endif
(const request&, response& res) {
res = response(f());
res.end();
});
handler_ = ([f = std::move(f)](const request&, response& res) {
res = response(f());
res.end();
});
}

template<typename Func>
Expand All @@ -376,16 +364,10 @@ namespace crow // NOTE: Already documented in "crow/app.h"
static_assert(!std::is_same<void, decltype(f(std::declval<crow::request>()))>::value,
"Handler function cannot have void return type; valid return types: string, int, crow::response, crow::returnable");

handler_ = (
#ifdef CROW_CAN_USE_CPP14
[f = std::move(f)]
#else
[f]
#endif
(const crow::request& req, crow::response& res) {
res = response(f(req));
res.end();
});
handler_ = ([f = std::move(f)](const request& req, response& res) {
res = response(f(req));
res.end();
});
}

template<typename Func>
Expand All @@ -398,15 +380,9 @@ namespace crow // NOTE: Already documented in "crow/app.h"
{
static_assert(std::is_same<void, decltype(f(std::declval<crow::response&>()))>::value,
"Handler function with response argument should have void return type");
handler_ = (
#ifdef CROW_CAN_USE_CPP14
[f = std::move(f)]
#else
[f]
#endif
(const crow::request&, crow::response& res) {
f(res);
});
handler_ = ([f = std::move(f)](const request&, response& res) {
f(res);
});
}

template<typename Func>
Expand Down Expand Up @@ -681,15 +657,9 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename Func>
void operator()(Func&& f)
{
handler_ = (
#ifdef CROW_CAN_USE_CPP14
[f = std::move(f)]
#else
[f]
#endif
(crow::request& req, crow::response& res, Args... args) {
detail::wrapped_handler_call(req, res, f, std::forward<Args>(args)...);
});
handler_ = ([f = std::move(f)](request& req, response& res, Args... args) {
detail::wrapped_handler_call(req, res, f, std::forward<Args>(args)...);
});
}

template<typename Func>
Expand Down
24 changes: 0 additions & 24 deletions include/crow/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@
#endif

// compiler flags
#if defined(_MSVC_LANG) && _MSVC_LANG >= 201402L
#define CROW_CAN_USE_CPP14
#endif
#if __cplusplus >= 201402L
#define CROW_CAN_USE_CPP14
#endif

#if defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
#define CROW_CAN_USE_CPP17
#endif
#if __cplusplus >= 201703L
#define CROW_CAN_USE_CPP17
#if defined(__GNUC__) && __GNUC__ < 8
#define CROW_FILESYSTEM_IS_EXPERIMENTAL
#endif
#endif

#if defined(_MSC_VER)
#if _MSC_VER < 1900
Expand All @@ -57,11 +41,3 @@
#define noexcept throw()
#endif
#endif

#if defined(__GNUC__) && __GNUC__ == 8 && __GNUC_MINOR__ < 4
#if __cplusplus > 201103L
#define CROW_GCC83_WORKAROUND
#else
#error "GCC 8.1 - 8.3 has a bug that prevents Crow from compiling with C++11. Please update GCC to > 8.3 or use C++ > 11."
#endif
#endif
18 changes: 0 additions & 18 deletions include/crow/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

#include "crow/settings.h"

#if defined(CROW_CAN_USE_CPP17) && !defined(CROW_FILESYSTEM_IS_EXPERIMENTAL)
#include <filesystem>
#endif

// TODO(EDev): Adding C++20's [[likely]] and [[unlikely]] attributes might be useful
#if defined(__GNUG__) || defined(__clang__)
Expand Down Expand Up @@ -291,21 +289,12 @@ namespace crow
};

// Extract element from forward tuple or get default
#ifdef CROW_CAN_USE_CPP14
template<typename T, typename Tup>
typename std::enable_if<has_type<T&, Tup>::value, typename std::decay<T>::type&&>::type
tuple_extract(Tup& tup)
{
return std::move(std::get<T&>(tup));
}
#else
template<typename T, typename Tup>
typename std::enable_if<has_type<T&, Tup>::value, T&&>::type
tuple_extract(Tup& tup)
{
return std::move(std::get<tuple_index<T&, Tup>::value>(tup));
}
#endif

template<typename T, typename Tup>
typename std::enable_if<!has_type<T&, Tup>::value, T>::type
Expand Down Expand Up @@ -812,14 +801,7 @@ namespace crow

inline static std::string join_path(std::string path, const std::string& fname)
{
#if defined(CROW_CAN_USE_CPP17) && !defined(CROW_FILESYSTEM_IS_EXPERIMENTAL)
return (std::filesystem::path(path) / fname).string();
#else
if (!(path.back() == '/' || path.back() == '\\'))
path += '/';
path += fname;
return path;
#endif
}

/**
Expand Down

0 comments on commit c148be0

Please sign in to comment.