mirror of
https://github.com/BlackMATov/invoke.hpp.git
synced 2025-12-12 21:46:18 +07:00
finalize C++11 impl
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# 3.8 version is required for `cxx_std_14`
|
||||
# 3.8 version is required for `cxx_std_11`
|
||||
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
|
||||
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
@@ -8,7 +8,7 @@ endif()
|
||||
project(invoke.hpp)
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14)
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE headers)
|
||||
|
||||
if(BUILD_AS_STANDALONE)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# invoke.hpp
|
||||
|
||||
> std::invoke/std::apply analogs for C++14
|
||||
> std::invoke/std::apply analogs for C++11/14
|
||||
|
||||
[![travis][badge.travis]][travis]
|
||||
[![appveyor][badge.appveyor]][appveyor]
|
||||
@@ -12,14 +12,14 @@
|
||||
[badge.travis]: https://img.shields.io/travis/BlackMATov/invoke.hpp/master.svg?logo=travis
|
||||
[badge.appveyor]: https://img.shields.io/appveyor/ci/BlackMATov/invoke-hpp/master.svg?logo=appveyor
|
||||
[badge.codecov]: https://img.shields.io/codecov/c/github/BlackMATov/invoke.hpp/master.svg?logo=codecov
|
||||
[badge.language]: https://img.shields.io/badge/language-C%2B%2B14-red.svg
|
||||
[badge.language]: https://img.shields.io/badge/language-C%2B%2B11-red.svg
|
||||
[badge.license]: https://img.shields.io/badge/license-MIT-blue.svg
|
||||
[badge.paypal]: https://img.shields.io/badge/donate-PayPal-orange.svg?logo=paypal&colorA=00457C
|
||||
|
||||
[travis]: https://travis-ci.org/BlackMATov/invoke.hpp
|
||||
[appveyor]: https://ci.appveyor.com/project/BlackMATov/invoke-hpp
|
||||
[codecov]: https://codecov.io/gh/BlackMATov/invoke.hpp
|
||||
[language]: https://en.wikipedia.org/wiki/C%2B%2B14
|
||||
[language]: https://en.wikipedia.org/wiki/C%2B%2B11
|
||||
[license]: https://en.wikipedia.org/wiki/MIT_License
|
||||
[paypal]: https://www.paypal.me/matov
|
||||
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#define INVOKE_HPP_NOEXCEPT_RETURN(...) \
|
||||
noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
|
||||
|
||||
#define INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN(...) \
|
||||
noexcept(noexcept(__VA_ARGS__)) -> decltype (__VA_ARGS__) { return __VA_ARGS__; }
|
||||
|
||||
@@ -35,6 +32,42 @@ namespace invoke_hpp
|
||||
using void_t = typename impl::make_void<Args...>::type;
|
||||
}
|
||||
|
||||
//
|
||||
// integer_sequence
|
||||
//
|
||||
|
||||
namespace invoke_hpp
|
||||
{
|
||||
template < typename T, T... Ints >
|
||||
struct integer_sequence {
|
||||
using value_type = T;
|
||||
static constexpr std::size_t size() noexcept { return sizeof...(Ints); }
|
||||
};
|
||||
|
||||
template < std::size_t... Ints >
|
||||
using index_sequence = integer_sequence<std::size_t, Ints...>;
|
||||
|
||||
namespace impl
|
||||
{
|
||||
template < typename T, std::size_t N, T... Ints >
|
||||
struct make_integer_sequence_impl
|
||||
: make_integer_sequence_impl<T, N - 1, N - 1, Ints...> {};
|
||||
|
||||
template < typename T, T... Ints >
|
||||
struct make_integer_sequence_impl<T, 0, Ints...>
|
||||
: integer_sequence<T, Ints...> {};
|
||||
}
|
||||
|
||||
template < typename T, std::size_t N >
|
||||
using make_integer_sequence = impl::make_integer_sequence_impl<T, N>;
|
||||
|
||||
template < std::size_t N >
|
||||
using make_index_sequence = make_integer_sequence<std::size_t, N>;
|
||||
|
||||
template < typename... Ts >
|
||||
using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
|
||||
}
|
||||
|
||||
//
|
||||
// is_reference_wrapper
|
||||
//
|
||||
@@ -223,40 +256,12 @@ namespace invoke_hpp
|
||||
// apply
|
||||
//
|
||||
|
||||
namespace invoke_hpp
|
||||
{
|
||||
namespace impl
|
||||
{
|
||||
template<typename T, T... Ints>
|
||||
struct integer_sequence
|
||||
{
|
||||
typedef T value_type;
|
||||
static constexpr std::size_t size() { return sizeof...(Ints); }
|
||||
};
|
||||
|
||||
template<std::size_t... Ints>
|
||||
using index_sequence = integer_sequence<std::size_t, Ints...>;
|
||||
|
||||
template<typename T, std::size_t N, T... Is>
|
||||
struct make_integer_sequence : make_integer_sequence<T, N-1, N-1, Is...> {};
|
||||
|
||||
template<typename T, T... Is>
|
||||
struct make_integer_sequence<T, 0, Is...> : integer_sequence<T, Is...> {};
|
||||
|
||||
template<std::size_t N>
|
||||
using make_index_sequence = make_integer_sequence<std::size_t, N>;
|
||||
|
||||
template<typename... T>
|
||||
using index_sequence_for = make_index_sequence<sizeof...(T)>;
|
||||
}
|
||||
}
|
||||
|
||||
namespace invoke_hpp
|
||||
{
|
||||
namespace impl
|
||||
{
|
||||
template < typename F, typename Tuple, std::size_t... I >
|
||||
constexpr auto apply_impl(F&& f, Tuple&& args, impl::index_sequence<I...>)
|
||||
constexpr auto apply_impl(F&& f, Tuple&& args, index_sequence<I...>)
|
||||
INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
invoke_hpp::invoke(
|
||||
std::forward<F>(f),
|
||||
@@ -269,9 +274,7 @@ namespace invoke_hpp
|
||||
impl::apply_impl(
|
||||
std::forward<F>(f),
|
||||
std::forward<Tuple>(args),
|
||||
impl::make_index_sequence<std::tuple_size<typename std::decay<Tuple>::type>::value>()))
|
||||
make_index_sequence<std::tuple_size<typename std::decay<Tuple>::type>::value>()))
|
||||
}
|
||||
|
||||
|
||||
#undef INVOKE_HPP_NOEXCEPT_RETURN
|
||||
#undef INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN
|
||||
|
||||
Reference in New Issue
Block a user