From bf05aa54cac60f205e49d45f4e2f609ae4db21a8 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 13 May 2019 01:06:33 +0700 Subject: [PATCH] move to C++17 --- .appveyor.yml | 1 - CMakeLists.txt | 4 +- README.md | 10 +- headers/kari_hpp/kari.hpp | 272 ++------------------------------------ 4 files changed, 19 insertions(+), 268 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 27089cb..4f3132d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,6 @@ version: "{build}" shallow_clone: true image: - - Visual Studio 2015 - Visual Studio 2017 - Visual Studio 2019 Preview platform: diff --git a/CMakeLists.txt b/CMakeLists.txt index 9328443..70b37ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# 3.8 version is required for `cxx_std_14` +# 3.8 version is required for `cxx_std_17` cmake_minimum_required(VERSION 3.8 FATAL_ERROR) if(NOT DEFINED PROJECT_NAME) @@ -9,7 +9,7 @@ project(kari.hpp) add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE headers) -target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14) +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) if(BUILD_AS_STANDALONE) option(BUILD_WITH_UNTESTS "Build with unit tests" ON) diff --git a/README.md b/README.md index e2e32a2..750e7e2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# kari.hpp [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Experimental%20library%20for%20currying%20in%20C%2B%2B14&url=https://github.com/BlackMATov/kari.hpp&via=BMEngine&hashtags=cpp,currying,cpp14,cpp17,functionalprogramming) +# kari.hpp [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Experimental%20library%20for%20currying%20in%20C%2B%2B17&url=https://github.com/BlackMATov/kari.hpp&via=BMEngine&hashtags=cpp,currying,cpp14,cpp17,functionalprogramming) -> Experimental library for currying in C++14 +> Experimental library for currying in C++17 [![travis][badge.travis]][travis] [![appveyor][badge.appveyor]][appveyor] @@ -12,14 +12,14 @@ [badge.travis]: https://img.shields.io/travis/BlackMATov/kari.hpp/master.svg?logo=travis [badge.appveyor]: https://img.shields.io/appveyor/ci/BlackMATov/kari-hpp/master.svg?logo=appveyor [badge.codecov]: https://img.shields.io/codecov/c/github/BlackMATov/kari.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%2B17-yellow.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/kari.hpp [appveyor]: https://ci.appveyor.com/project/BlackMATov/kari-hpp [codecov]: https://codecov.io/gh/BlackMATov/kari.hpp -[language]: https://en.wikipedia.org/wiki/C%2B%2B14 +[language]: https://en.wikipedia.org/wiki/C%2B%2B17 [license]: https://github.com/BlackMATov/kari.hpp/blob/master/LICENSE.md [paypal]: https://www.paypal.me/matov @@ -131,7 +131,7 @@ namespace kari { struct is_curried; template < typename F > - constexpr bool is_curried_v = is_curried::value; + inline constexpr bool is_curried_v = is_curried::value; template < std::size_t N, typename F, typename... Args > struct curry_t { diff --git a/headers/kari_hpp/kari.hpp b/headers/kari_hpp/kari.hpp index 220b7c7..b9e8b06 100644 --- a/headers/kari_hpp/kari.hpp +++ b/headers/kari_hpp/kari.hpp @@ -12,254 +12,6 @@ #include #include -// ----------------------------------------------------------------------------- -// -// https://github.com/BlackMATov/invoke.hpp -// -// ----------------------------------------------------------------------------- - -#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__; } - -// -// void_t -// - -namespace invoke_hpp -{ - namespace impl - { - template < typename... Args > - struct make_void { - using type = void; - }; - } - - template < typename... Args > - using void_t = typename impl::make_void::type; -} - -// -// is_reference_wrapper -// - -namespace invoke_hpp -{ - namespace impl - { - template < typename T > - struct is_reference_wrapper_impl - : std::false_type {}; - - template < typename U > - struct is_reference_wrapper_impl> - : std::true_type {}; - } - - template < typename T > - struct is_reference_wrapper - : impl::is_reference_wrapper_impl> {}; -} - -// -// invoke -// - -namespace invoke_hpp -{ - namespace impl - { - // - // invoke_member_object_impl - // - - template - < - typename Base, typename F, typename Derived, - typename std::enable_if_t>::value, int> = 0 - > - constexpr auto invoke_member_object_impl(F Base::* f, Derived&& ref) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - std::forward(ref).*f) - - template - < - typename Base, typename F, typename RefWrap, - typename std::enable_if_t>::value, int> = 0 - > - constexpr auto invoke_member_object_impl(F Base::* f, RefWrap&& ref) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - ref.get().*f) - - template - < - typename Base, typename F, typename Pointer, - typename std::enable_if_t< - !std::is_base_of>::value && - !is_reference_wrapper>::value - , int> = 0 - > - constexpr auto invoke_member_object_impl(F Base::* f, Pointer&& ptr) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - (*std::forward(ptr)).*f) - - // - // invoke_member_function_impl - // - - template - < - typename Base, typename F, typename Derived, typename... Args, - typename std::enable_if_t>::value, int> = 0 - > - constexpr auto invoke_member_function_impl(F Base::* f, Derived&& ref, Args&&... args) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - (std::forward(ref).*f)(std::forward(args)...)) - - template - < - typename Base, typename F, typename RefWrap, typename... Args, - typename std::enable_if_t>::value, int> = 0 - > - constexpr auto invoke_member_function_impl(F Base::* f, RefWrap&& ref, Args&&... args) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - (ref.get().*f)(std::forward(args)...)) - - template - < - typename Base, typename F, typename Pointer, typename... Args, - typename std::enable_if_t< - !std::is_base_of>::value && - !is_reference_wrapper>::value - , int> = 0 - > - constexpr auto invoke_member_function_impl(F Base::* f, Pointer&& ptr, Args&&... args) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - ((*std::forward(ptr)).*f)(std::forward(args)...)) - } - - template - < - typename F, typename... Args, - typename std::enable_if_t>::value, int> = 0 - > - constexpr auto invoke(F&& f, Args&&... args) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - std::forward(f)(std::forward(args)...)) - - template - < - typename F, typename T, - typename std::enable_if_t>::value, int> = 0 - > - constexpr auto invoke(F&& f, T&& t) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - impl::invoke_member_object_impl(std::forward(f), std::forward(t))) - - template - < - typename F, typename... Args, - typename std::enable_if_t>::value, int> = 0 - > - constexpr auto invoke(F&& f, Args&&... args) - INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( - impl::invoke_member_function_impl(std::forward(f), std::forward(args)...)) -} - -// -// invoke_result -// - -namespace invoke_hpp -{ - namespace impl - { - struct invoke_result_impl_tag {}; - - template < typename Void, typename F, typename... Args > - struct invoke_result_impl {}; - - template < typename F, typename... Args > - struct invoke_result_impl(), std::declval()...))>, F, Args...> { - using type = decltype(invoke_hpp::invoke(std::declval(), std::declval()...)); - }; - } - - template < typename F, typename... Args > - struct invoke_result - : impl::invoke_result_impl {}; - - template < typename F, typename... Args > - using invoke_result_t = typename invoke_result::type; -} - -// -// is_invocable -// - -namespace invoke_hpp -{ - namespace impl - { - struct is_invocable_r_impl_tag {}; - - template < typename Void, typename R, typename F, typename... Args > - struct is_invocable_r_impl - : std::false_type {}; - - template < typename R, typename F, typename... Args > - struct is_invocable_r_impl>, R, F, Args...> - : std::conditional_t< - std::is_void::value, - std::true_type, - std::is_convertible, R>> {}; - } - - template < typename R, typename F, typename... Args > - struct is_invocable_r - : impl::is_invocable_r_impl {}; - - template < typename F, typename... Args > - using is_invocable = is_invocable_r; -} - -// -// apply -// - -namespace invoke_hpp -{ - namespace impl - { - template < typename F, typename Tuple, std::size_t... I > - constexpr decltype(auto) apply_impl(F&& f, Tuple&& args, std::index_sequence) - INVOKE_HPP_NOEXCEPT_RETURN( - invoke_hpp::invoke( - std::forward(f), - std::get(std::forward(args))...)) - } - - template < typename F, typename Tuple > - constexpr decltype(auto) apply(F&& f, Tuple&& args) - INVOKE_HPP_NOEXCEPT_RETURN( - impl::apply_impl( - std::forward(f), - std::forward(args), - std::make_index_sequence>::value>())) -} - -#undef INVOKE_HPP_NOEXCEPT_RETURN -#undef INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN - -// ----------------------------------------------------------------------------- -// -// https://github.com/BlackMATov/kari.hpp -// -// ----------------------------------------------------------------------------- - #define KARI_HPP_NOEXCEPT_RETURN(...) \ noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } @@ -278,19 +30,19 @@ namespace kari std::size_t N, typename F, typename... Args, typename std::enable_if_t< (N == 0) && - invoke_hpp::is_invocable, Args...>::value + std::is_invocable_v, Args...> , int> = 0 > constexpr auto make_curry(F&& f, std::tuple&& args) KARI_HPP_NOEXCEPT_RETURN( - invoke_hpp::apply(std::forward(f), std::move(args))) + std::apply(std::forward(f), std::move(args))) template < std::size_t N, typename F, typename... Args, typename std::enable_if_t< (N > 0) || - !invoke_hpp::is_invocable, Args...>::value + !std::is_invocable_v, Args...> , int> = 0 > constexpr auto make_curry(F&& f, std::tuple&& args) @@ -408,7 +160,7 @@ namespace kari : detail::is_curried_impl> {}; template < typename F > - constexpr bool is_curried_v = is_curried::value; + inline constexpr bool is_curried_v = is_curried::value; // // curry @@ -512,7 +264,7 @@ namespace kari KARI_HPP_NOEXCEPT_DECLTYPE_RETURN( std::forward(a)) }; - constexpr auto fid = curry(fid_t{}); + inline constexpr auto fid = curry(fid_t{}); // // fconst @@ -524,7 +276,7 @@ namespace kari KARI_HPP_NOEXCEPT_DECLTYPE_RETURN( std::forward(a)) }; - constexpr auto fconst = curry(fconst_t{}); + inline constexpr auto fconst = curry(fconst_t{}); // // fflip @@ -539,7 +291,7 @@ namespace kari std::forward(b), std::forward(a))) }; - constexpr auto fflip = curry(fflip_t{}); + inline constexpr auto fflip = curry(fflip_t{}); // // fpipe @@ -555,7 +307,7 @@ namespace kari std::forward(g), std::forward(a)))) }; - constexpr auto fpipe = curry(fpipe_t{}); + inline constexpr auto fpipe = curry(fpipe_t{}); // // fcompose @@ -571,7 +323,7 @@ namespace kari std::forward(f), std::forward(a)))) }; - constexpr auto fcompose = curry(fcompose_t{}); + inline constexpr auto fcompose = curry(fcompose_t{}); // // fpipe operators @@ -651,7 +403,7 @@ namespace kari namespace underscore { struct us_t {}; - constexpr us_t _{}; + inline constexpr us_t _{}; // // is_underscore, is_underscore_v @@ -659,10 +411,10 @@ namespace kari template < typename T > struct is_underscore - : std::integral_constant>::value> {}; + : std::bool_constant>> {}; template < typename T > - constexpr bool is_underscore_v = is_underscore::value; + inline constexpr bool is_underscore_v = is_underscore::value; // // unary operators