Commit a7a8dc50 authored by Dominik Charousset's avatar Dominik Charousset

Merge branch 'topic/forward-compatibility'

parents a7752756 f9f35653
......@@ -390,6 +390,46 @@ while [ $# -ne 0 ]; do
append_cache_entry CAF_ENABLE_ADDRESS_SANITIZER BOOL yes
append_cache_entry CAF_ENABLE_TYPE_ID_CHECKS BOOL yes
;;
# "overloads" for forward compatibility with new 0.18 disable-* syntax
--disable-memory-management)
append_cache_entry CAF_NO_MEM_MANAGEMENT BOOL yes
;;
--disable-compiler-check)
append_cache_entry CAF_NO_COMPILER_CHECK BOOL yes
;;
--disable-auto-libc++)
append_cache_entry CAF_NO_AUTO_LIBCPP BOOL yes
;;
--disable-exceptions)
append_cache_entry CAF_NO_EXCEPTIONS BOOL yes
;;
--disable-examples)
append_cache_entry CAF_NO_EXAMPLES BOOL yes
;;
--disable-curl-examples)
append_cache_entry CAF_NO_CURL_EXAMPLES BOOL yes
;;
--disable-testing)
append_cache_entry CAF_NO_UNIT_TESTS BOOL yes
;;
--disable-opencl)
append_cache_entry CAF_NO_OPENCL BOOL yes
;;
--disable-openssl)
append_cache_entry CAF_NO_OPENSSL BOOL yes
;;
--disable-tools)
append_cache_entry CAF_NO_TOOLS BOOL yes
;;
--disable-io)
append_cache_entry CAF_NO_IO BOOL yes
;;
--disable-python)
append_cache_entry CAF_NO_PYTHON BOOL yes
;;
--disable-summary)
append_cache_entry CAF_NO_SUMMARY BOOL yes
;;
*)
echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1
......
......@@ -21,6 +21,7 @@
#include <tuple>
#include "caf/broadcast_downstream_manager.hpp"
#include "caf/check_typed_input.hpp"
#include "caf/default_downstream_manager.hpp"
#include "caf/detail/stream_source_driver_impl.hpp"
#include "caf/detail/stream_source_impl.hpp"
......
......@@ -24,6 +24,7 @@
#include <stdexcept>
#include "caf/error.hpp"
#include "caf/timespan.hpp"
namespace caf {
......@@ -75,15 +76,6 @@ constexpr time_unit get_time_unit_from_period() {
return ratio_to_time_unit_helper<Period::num, Period::den>::value;
}
/// Represents an infinite amount of timeout for specifying "invalid" timeouts.
struct infinite_t {
constexpr infinite_t() {
// nop
}
};
static constexpr infinite_t infinite = infinite_t{};
/// Time duration consisting of a `time_unit` and a 64 bit unsigned integer.
class duration {
public:
......@@ -145,6 +137,12 @@ inline bool operator!=(const duration& lhs, const duration& rhs) {
return !(lhs == rhs);
}
/// @relates duration
template <class T>
inline bool is_infinite(duration x) {
return !x.valid();
}
/// @relates duration
template <class Clock, class Duration>
std::chrono::time_point<Clock, Duration>&
......
......@@ -23,7 +23,9 @@
#include <utility>
#include "caf/atom.hpp"
#include "caf/config.hpp"
#include "caf/detail/comparable.hpp"
#include "caf/detail/pp.hpp"
#include "caf/fwd.hpp"
#include "caf/meta/omittable_if_empty.hpp"
#include "caf/meta/type_name.hpp"
......@@ -71,6 +73,11 @@ template <class T, class U = void>
using enable_if_has_error_factory_t =
typename std::enable_if<detail::error_factory<T>::specialized, U>::type;
/// @private
template <class T, class U = void>
using enable_if_can_construct_error_t = typename std::enable_if<
detail::error_factory<T>::specialized || has_make_error<T>::value, U>::type;
/// A serializable type for storing error codes with category and optional,
/// human-readable context information. Unlike error handling classes from
/// the C++ standard library, this type is serializable. It consists of an
......@@ -105,9 +112,9 @@ class error : detail::comparable<error> {
public:
// -- member types -----------------------------------------------------------
using inspect_fun = std::function<
error(meta::type_name_t, uint8_t&, atom_value&, meta::omittable_if_empty_t,
message&)>;
using inspect_fun
= std::function<error(meta::type_name_t, uint8_t&, atom_value&,
meta::omittable_if_empty_t, message&)>;
// -- constructors, destructors, and assignment operators --------------------
......@@ -276,15 +283,21 @@ bool operator!=(E x, const error& y) {
return !(x == y);
}
/// @relates error
template <class Code, class... Ts>
enable_if_has_error_factory_t<Code, error> make_error(Code code, Ts&&... xs) {
return error{code, std::forward<Ts>(xs)...};
}
} // namespace caf
#define CAF_ERROR_CODE_ENUM(enum_name) \
#define CAF_ERROR_CODE_ENUM_2(enum_type, category_name) \
namespace caf { \
namespace detail { \
template <> \
struct error_factory<enum_name> { \
struct error_factory<enum_type> { \
static constexpr bool specialized = true; \
static constexpr atom_value category = atom(#enum_name); \
static constexpr atom_value category = atom(category_name); \
template <class... Ts> \
static message context(Ts&&... xs) { \
return make_message(std::forward<Ts>(xs)...); \
......@@ -292,3 +305,16 @@ bool operator!=(E x, const error& y) {
}; \
} \
}
#define CAF_ERROR_CODE_ENUM_1(type_name) \
CAF_ERROR_CODE_ENUM_2(type_name, #type_name)
#ifdef CAF_MSVC
# define CAF_ERROR_CODE_ENUM(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_ERROR_CODE_ENUM_, \
__VA_ARGS__)(__VA_ARGS__), \
CAF_PP_EMPTY())
#else
# define CAF_ERROR_CODE_ENUM(...) \
CAF_PP_OVERLOAD(CAF_ERROR_CODE_ENUM_, __VA_ARGS__)(__VA_ARGS__)
#endif
......@@ -91,9 +91,9 @@ public:
construct(other);
}
template <class Code, class E = enable_if_has_make_error_t<Code>>
template <class Code, class = enable_if_can_construct_error_t<Code>>
expected(Code code) : engaged_(false) {
new (std::addressof(error_)) caf::error(make_error(code));
new (std::addressof(error_)) caf::error(code);
}
expected(expected&& other) noexcept(nothrow_move) {
......@@ -139,7 +139,6 @@ public:
return *this;
}
expected& operator=(T&& x) noexcept(nothrow_move) {
if (engaged_) {
value_ = std::move(x);
......@@ -169,8 +168,8 @@ public:
}
template <class Code>
enable_if_has_make_error_t<Code, expected&> operator=(Code code) {
return *this = make_error(code);
enable_if_can_construct_error_t<Code, expected&> operator=(Code code) {
return *this = caf::error{code};
}
// -- modifiers --------------------------------------------------------------
......@@ -390,8 +389,8 @@ public:
// nop
}
template <class Code, class E = enable_if_has_make_error_t<Code>>
expected(Code code) : error_(make_error(code)) {
template <class Code, class = enable_if_can_construct_error_t<Code>>
expected(Code code) : error_(code) {
// nop
}
......@@ -402,6 +401,11 @@ public:
return *this;
}
template <class Code>
enable_if_can_construct_error_t<Code, expected&> operator=(Code code) {
error_ = caf::error{code};
}
explicit operator bool() const {
return !error_;
}
......@@ -458,4 +462,3 @@ auto operator<<(ostream& oss, const caf::expected<T>& x)
}
} // namespace std
// This header only exists to make transition to CAF 0.18 easier by not having
// to use #ifdef blocks for includes.
......@@ -61,14 +61,6 @@ struct is_serializable_or_whitelisted {
|| allowed_unsafe_message_type<T>::value;
};
/// @private
template <class T>
struct has_type_id {
static constexpr bool value = detail::is_complete<type_id<T>>::value
|| is_atom_constant<T>::value
|| allowed_unsafe_message_type<T>::value;
};
/// Returns a new `message` containing the values `(x, xs...)`.
/// @relates message
template <class T, class... Ts>
......
......@@ -26,5 +26,25 @@ namespace caf {
/// A portable timespan type with nanosecond resolution.
using timespan = std::chrono::duration<int64_t, std::nano>;
} // namespace caf
/// Represents an infinite amount of timeout for specifying "invalid" timeouts.
struct infinite_t {
constexpr infinite_t() {
// nop
}
};
/// Constant for passing "no timeout" to functions such as `request`.
static constexpr infinite_t infinite = infinite_t{};
// -- forward compatibility with CAF 0.18 --------------------------------------
constexpr bool is_infinite(infinite_t) {
return true;
}
template <class Rep, class Period>
constexpr bool is_infinite(std::chrono::duration<Rep, Period>) {
return false;
}
} // namespace caf
......@@ -23,7 +23,9 @@
#include <string>
#include <utility>
#include "caf/allowed_unsafe_message_type.hpp"
#include "caf/atom.hpp"
#include "caf/detail/is_complete.hpp"
#include "caf/detail/pp.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp"
......@@ -63,6 +65,17 @@ struct type_name_by_id;
/// The first type ID not reserved by CAF and its modules.
constexpr type_id_t first_custom_type_id = 200;
/// Evaluates to `true` if any of these statements holds true:
/// - `type_id<T>` is specialized
/// - `T` is an atom constant
/// - `allowed_unsafe_message_type<T>` is specialized
template <class T>
struct has_type_id {
static constexpr bool value = detail::is_complete<type_id<T>>::value
|| is_atom_constant<T>::value
|| allowed_unsafe_message_type<T>::value;
};
} // namespace caf
/// Starts a code block for registering custom types to CAF. Stores the first ID
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment