uvw is now a C++17 only library (close #155)
This commit is contained in:
parent
6ce60d4088
commit
749581309e
24
.travis.yml
24
.travis.yml
@ -9,23 +9,21 @@ matrix:
|
||||
include:
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
language: cpp
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-6']
|
||||
env: COMPILER=g++-6
|
||||
packages: ['g++-7']
|
||||
env: COMPILER=g++-7
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
|
||||
packages: ['clang-4.0', 'libstdc++-4.9-dev']
|
||||
env: COMPILER=clang++-4.0
|
||||
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
|
||||
packages: ['clang-6.0', 'g++-7']
|
||||
env: COMPILER=clang++-6.0
|
||||
- os: osx
|
||||
osx_image: xcode8.3
|
||||
osx_image: xcode10
|
||||
compiler: clang
|
||||
language: cpp
|
||||
env: COMPILER=clang++
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
@ -33,15 +31,15 @@ matrix:
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-6']
|
||||
packages: ['g++-7']
|
||||
env:
|
||||
- C_COMPILER=gcc-6
|
||||
- COMPILER=g++-6
|
||||
- C_COMPILER=gcc-7
|
||||
- COMPILER=g++-7
|
||||
- CXXFLAGS="-O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
|
||||
before_script:
|
||||
- pip install --user cpp-coveralls
|
||||
after_success:
|
||||
- coveralls --gcov gcov-6 --gcov-options '\-lp' --root ${TRAVIS_BUILD_DIR} --build-root ${TRAVIS_BUILD_DIR}/build --extension cpp --extension hpp --exclude deps --include src
|
||||
- coveralls --gcov gcov-7 --gcov-options '\-lp' --root ${TRAVIS_BUILD_DIR} --build-root ${TRAVIS_BUILD_DIR}/build --extension cpp --extension hpp --exclude deps --include src
|
||||
- os: linux
|
||||
dist: xenial
|
||||
sudo: true
|
||||
@ -75,5 +73,5 @@ install:
|
||||
|
||||
script:
|
||||
- mkdir -p build && cd build
|
||||
- cmake .. -DBUILD_TESTING=ON && make -j4
|
||||
- cmake .. -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF && make -j4
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j4 -R uvw
|
||||
|
||||
5
AUTHORS
5
AUTHORS
@ -1,10 +1,10 @@
|
||||
# Author
|
||||
|
||||
Michele Caini aka skypjack
|
||||
skypjack
|
||||
|
||||
# Collaborators
|
||||
|
||||
Paolo Monteverde aka morbo84
|
||||
morbo84
|
||||
|
||||
# Contributors
|
||||
|
||||
@ -21,3 +21,4 @@ Miigon
|
||||
slyshykO
|
||||
bmagistro
|
||||
richardbmx
|
||||
wnsgml972
|
||||
|
||||
@ -16,7 +16,7 @@ endif()
|
||||
# Project configuration
|
||||
#
|
||||
|
||||
project(uvw VERSION 1.18.0)
|
||||
project(uvw VERSION 2.0.0)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
@ -30,7 +30,7 @@ message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
|
||||
message("* Copyright (c) 2016-2019 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
|
||||
message("*")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(NOT MSVC)
|
||||
|
||||
@ -10,11 +10,11 @@ platform:
|
||||
- Win32
|
||||
|
||||
configuration:
|
||||
- Release
|
||||
- Debug
|
||||
|
||||
before_build:
|
||||
- cd %BUILD_DIR%
|
||||
- cmake .. -DBUILD_TESTING=ON -G"Visual Studio 15 2017"
|
||||
- cmake .. -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF -G"Visual Studio 15 2017"
|
||||
|
||||
build:
|
||||
parallel: true
|
||||
|
||||
@ -17,7 +17,7 @@ ExternalProject_Add(
|
||||
ExternalProject_Add(
|
||||
libuv
|
||||
GIT_REPOSITORY https://github.com/libuv/libuv.git
|
||||
GIT_TAG v1.30.0
|
||||
GIT_TAG v1.30.1
|
||||
SOURCE_DIR @LIBUV_DEPS_DIR@
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
|
||||
@ -21,7 +21,7 @@ namespace uvw {
|
||||
* Custom wrapper around error constants of `libuv`.
|
||||
*/
|
||||
struct ErrorEvent {
|
||||
template<typename U, typename = std::enable_if_t<std::is_integral<U>::value>>
|
||||
template<typename U, typename = std::enable_if_t<std::is_integral_v<U>>>
|
||||
explicit ErrorEvent(U val) noexcept
|
||||
: ec{static_cast<int>(val)}
|
||||
{}
|
||||
@ -218,7 +218,7 @@ public:
|
||||
};
|
||||
|
||||
virtual ~Emitter() noexcept {
|
||||
static_assert(std::is_base_of<Emitter<T>, T>::value, "!");
|
||||
static_assert(std::is_base_of_v<Emitter<T>, T>);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -48,7 +48,7 @@ public:
|
||||
*/
|
||||
template<typename F>
|
||||
F * sym(std::string name) {
|
||||
static_assert(std::is_function<F>::value, "!");
|
||||
static_assert(std::is_function_v<F>);
|
||||
F *func;
|
||||
auto err = uv_dlsym(get(), name.data(), reinterpret_cast<void**>(&func));
|
||||
if(err) { func = nullptr; }
|
||||
|
||||
@ -236,7 +236,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates resources of handles' types.
|
||||
* @brief Creates resources of any type.
|
||||
*
|
||||
* This should be used as a default method to create resources.<br/>
|
||||
* The arguments are the ones required for the specific resource.
|
||||
@ -246,27 +246,14 @@ public:
|
||||
* @return A pointer to the newly created resource.
|
||||
*/
|
||||
template<typename R, typename... Args>
|
||||
std::enable_if_t<std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>
|
||||
resource(Args&&... args) {
|
||||
auto ptr = R::create(shared_from_this(), std::forward<Args>(args)...);
|
||||
ptr = ptr->init() ? ptr : nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates resources of types other than handles' ones.
|
||||
*
|
||||
* This should be used as a default method to create resources.<br/>
|
||||
* The arguments are the ones required for the specific resource.
|
||||
*
|
||||
* Use it as `loop->resource<uvw::WorkReq>()`.
|
||||
*
|
||||
* @return A pointer to the newly created resource.
|
||||
*/
|
||||
template<typename R, typename... Args>
|
||||
std::enable_if_t<not std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>
|
||||
resource(Args&&... args) {
|
||||
return R::create(shared_from_this(), std::forward<Args>(args)...);
|
||||
std::shared_ptr<R> resource(Args&&... args) {
|
||||
if constexpr(std::is_base_of_v<BaseHandle, R>) {
|
||||
auto ptr = R::create(shared_from_this(), std::forward<Args>(args)...);
|
||||
ptr = ptr->init() ? ptr : nullptr;
|
||||
return ptr;
|
||||
} else {
|
||||
return R::create(shared_from_this(), std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -28,18 +28,15 @@ protected:
|
||||
}
|
||||
|
||||
template<typename F, typename... Args>
|
||||
auto invoke(F &&f, Args&&... args)
|
||||
-> std::enable_if_t<not std::is_void<std::result_of_t<F(Args...)>>::value> {
|
||||
auto err = std::forward<F>(f)(std::forward<Args>(args)...);
|
||||
if(err) { Emitter<T>::publish(ErrorEvent{err}); }
|
||||
else { this->leak(); }
|
||||
}
|
||||
|
||||
template<typename F, typename... Args>
|
||||
auto invoke(F &&f, Args&&... args)
|
||||
-> std::enable_if_t<std::is_void<std::result_of_t<F(Args...)>>::value> {
|
||||
std::forward<F>(f)(std::forward<Args>(args)...);
|
||||
this->leak();
|
||||
auto invoke(F &&f, Args&&... args) {
|
||||
if constexpr(std::is_void_v<std::invoke_result_t<F, Args...>>) {
|
||||
std::forward<F>(f)(std::forward<Args>(args)...);
|
||||
this->leak();
|
||||
} else {
|
||||
auto err = std::forward<F>(f)(std::forward<Args>(args)...);
|
||||
if(err) { Emitter<T>::publish(ErrorEvent{err}); }
|
||||
else { this->leak(); }
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@ -192,7 +192,7 @@ public:
|
||||
template<typename F>
|
||||
static void once(F &&f) noexcept {
|
||||
using CallbackType = void(*)(void);
|
||||
static_assert(std::is_convertible<F, CallbackType>::value, "!");
|
||||
static_assert(std::is_convertible_v<F, CallbackType>);
|
||||
CallbackType cb = f;
|
||||
uv_once(guard(), cb);
|
||||
}
|
||||
|
||||
@ -23,36 +23,21 @@ class UnderlyingType {
|
||||
protected:
|
||||
struct ConstructorAccess { explicit ConstructorAccess(int) {} };
|
||||
|
||||
template<typename R = U>
|
||||
auto get() noexcept {
|
||||
return &resource;
|
||||
}
|
||||
|
||||
auto get() const noexcept {
|
||||
return &resource;
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
auto get() noexcept {
|
||||
static_assert(not std::is_same<R, U>::value, "!");
|
||||
return reinterpret_cast<R *>(&resource);
|
||||
}
|
||||
|
||||
template<typename R = U>
|
||||
auto get() const noexcept {
|
||||
return reinterpret_cast<const R *>(&resource);
|
||||
}
|
||||
|
||||
template<typename R, typename... P>
|
||||
auto get(UnderlyingType<P...> &other) noexcept {
|
||||
return reinterpret_cast<R *>(&other.resource);
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
auto get() const noexcept {
|
||||
static_assert(not std::is_same<R, U>::value, "!");
|
||||
return reinterpret_cast<const R *>(&resource);
|
||||
}
|
||||
|
||||
template<typename R, typename... P>
|
||||
auto get(const UnderlyingType<P...> &other) const noexcept {
|
||||
return reinterpret_cast<const R *>(&other.resource);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit UnderlyingType(ConstructorAccess, std::shared_ptr<Loop> ref) noexcept
|
||||
: pLoop{std::move(ref)}, resource{}
|
||||
@ -62,7 +47,7 @@ public:
|
||||
UnderlyingType(UnderlyingType &&) = delete;
|
||||
|
||||
virtual ~UnderlyingType() {
|
||||
static_assert(std::is_base_of<UnderlyingType<T, U>, T>::value, "!");
|
||||
static_assert(std::is_base_of_v<UnderlyingType<T, U>, T>);
|
||||
}
|
||||
|
||||
UnderlyingType & operator=(const UnderlyingType &) = delete;
|
||||
|
||||
@ -13,14 +13,6 @@
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
// MSVC doesn't have C++14 relaxed constexpr support yet. Hence the jugglery.
|
||||
#define CONSTEXPR_SPECIFIER
|
||||
#else
|
||||
#define CONSTEXPR_SPECIFIER constexpr
|
||||
#endif
|
||||
|
||||
|
||||
namespace uvw {
|
||||
|
||||
|
||||
@ -100,10 +92,8 @@ public:
|
||||
* @return A valid instance of Flags instantiated from values `V`.
|
||||
*/
|
||||
template<E... V>
|
||||
static CONSTEXPR_SPECIFIER Flags<E> from() {
|
||||
auto flags = Flags<E>{};
|
||||
int _[] = { 0, (flags = flags | V, 0)... };
|
||||
return void(_), flags;
|
||||
static constexpr Flags<E> from() {
|
||||
return (Flags<E>{} | ... | V);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,14 +117,14 @@ public:
|
||||
constexpr Flags(const Flags &f) noexcept: flags{f.flags} { }
|
||||
constexpr Flags(Flags &&f) noexcept: flags{std::move(f.flags)} { }
|
||||
|
||||
~Flags() noexcept { static_assert(std::is_enum<E>::value, "!"); }
|
||||
~Flags() noexcept { static_assert(std::is_enum_v<E>); }
|
||||
|
||||
CONSTEXPR_SPECIFIER Flags & operator=(const Flags &f) noexcept {
|
||||
constexpr Flags & operator=(const Flags &f) noexcept {
|
||||
flags = f.flags;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CONSTEXPR_SPECIFIER Flags & operator=(Flags &&f) noexcept {
|
||||
constexpr Flags & operator=(Flags &&f) noexcept {
|
||||
flags = std::move(f.flags);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -83,14 +83,12 @@ TEST(TCP, SockPeer) {
|
||||
uvw::Addr addr = handle.sock();
|
||||
|
||||
ASSERT_EQ(addr.ip, address);
|
||||
ASSERT_EQ(addr.port, decltype(addr.port){port});
|
||||
});
|
||||
|
||||
client->once<uvw::ConnectEvent>([&address](const uvw::ConnectEvent &, uvw::TCPHandle &handle) {
|
||||
uvw::Addr addr = handle.peer();
|
||||
|
||||
ASSERT_EQ(addr.ip, address);
|
||||
ASSERT_NE(addr.port, decltype(addr.port){0});
|
||||
|
||||
handle.close();
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user