mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-25 21:35:41 +00:00
add C++17 make_from_tuple
This commit is contained in:
parent
eec9c86920
commit
23408e46c4
4 changed files with 50 additions and 6 deletions
|
@ -24,7 +24,7 @@ namespace sprout {
|
|||
template<typename F, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename sprout::invoke_result<F, Args...>::type
|
||||
invoke(F&& f, Args&&... args) SPROUT_NOEXCEPT_IF((sprout::is_nothrow_invocable<F, Args...>::value)) {
|
||||
return sprout::detail::invoke(sprout::forward<F>(f), sprout::forward<Args>(args)...);
|
||||
return sprout::detail::invoke(SPROUT_FORWARD(F, f), SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <sprout/tuple/metafunctions.hpp>
|
||||
#include <sprout/tuple/functions.hpp>
|
||||
#include <sprout/tuple/apply.hpp>
|
||||
#include <sprout/tuple/make_from_tuple.hpp>
|
||||
#include <sprout/tuple/fused.hpp>
|
||||
#include <sprout/tuple/flex.hpp>
|
||||
|
||||
|
|
43
sprout/tuple/make_from_tuple.hpp
Normal file
43
sprout/tuple/make_from_tuple.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2017 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_TUPLE_MAKE_FROM_TUPLE_HPP
|
||||
#define SPROUT_TUPLE_MAKE_FROM_TUPLE_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/tuple/get.hpp>
|
||||
#include <sprout/tuple/indexes.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// make_from_tuple
|
||||
//
|
||||
namespace detail {
|
||||
template<typename T, typename Tuple, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
make_from_tuple_impl(Tuple&& t, sprout::index_tuple<Indexes...>) {
|
||||
return T(sprout::get<Indexes>(SPROUT_FORWARD(Tuple, t))...);
|
||||
}
|
||||
} // namespace detail
|
||||
template<typename T, typename Tuple>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
make_from_tuple(Tuple&& t) {
|
||||
return sprout::tuples::detail::make_from_tuple_impl<T>(
|
||||
SPROUT_FORWARD(Tuple, t),
|
||||
sprout::tuple_indexes<typename std::remove_reference<Tuple>::type>::make()
|
||||
);
|
||||
}
|
||||
} // namespace tuples
|
||||
|
||||
using sprout::tuples::make_from_tuple;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_MAKE_FROM_TUPLE_HPP
|
|
@ -20,31 +20,31 @@ namespace sprout {
|
|||
template<typename F, typename... Args>
|
||||
inline SPROUT_CONSTEXPR decltype(std::declval<F>()(std::declval<Args>()...))
|
||||
invoke(F&& f, Args&&... args) SPROUT_NOEXCEPT_IF_EXPR(std::declval<F>()(std::declval<Args>()...)) {
|
||||
return sprout::forward<F>(f)(sprout::forward<Args>(args)...);
|
||||
return SPROUT_FORWARD(F, f)(SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
|
||||
template<typename Base, typename T, typename Derived>
|
||||
inline SPROUT_CONSTEXPR decltype(std::declval<Derived>().*(std::declval<T Base::*>()))
|
||||
invoke(T Base::* pm, Derived&& d) SPROUT_NOEXCEPT_IF_EXPR(std::declval<Derived>().*(std::declval<T Base::*>())) {
|
||||
return sprout::forward<Derived>(d).*(pm);
|
||||
return SPROUT_FORWARD(Derived, d).*(pm);
|
||||
}
|
||||
|
||||
template<typename PMD, typename Pointer>
|
||||
inline SPROUT_CONSTEXPR decltype((*std::declval<Pointer>()).*(std::declval<PMD>()))
|
||||
invoke(PMD&& pmd, Pointer&& ptr) SPROUT_NOEXCEPT_IF_EXPR((*std::declval<Pointer>()).*(std::declval<PMD>())) {
|
||||
return sprout::forward<Pointer>(ptr).*(sprout::forward<PMD>(pmd));
|
||||
return SPROUT_FORWARD(Pointer, ptr).*(SPROUT_FORWARD(PMD, pmd));
|
||||
}
|
||||
|
||||
template<typename Base, typename T, typename Derived, typename... Args>
|
||||
inline SPROUT_CONSTEXPR decltype((std::declval<Derived>().*(std::declval<T Base::*>()))(std::declval<Args>()...))
|
||||
invoke(T Base::* pm, Derived&& d, Args&&... args) SPROUT_NOEXCEPT_IF_EXPR((std::declval<Derived>().*(std::declval<T Base::*>()))(std::declval<Args>()...)) {
|
||||
return (sprout::forward<Derived>(d).*(pm))(sprout::forward<Args>(args)...);
|
||||
return (SPROUT_FORWARD(Derived, d).*(pm))(SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
|
||||
template<typename PMF, typename Pointer, typename... Args>
|
||||
inline SPROUT_CONSTEXPR decltype(((*std::declval<Pointer>()).*(std::declval<PMF>()))(std::declval<Args>()...))
|
||||
invoke(PMF&& pmf, Pointer&& ptr, Args&&... args) SPROUT_NOEXCEPT_IF_EXPR(((*std::declval<Pointer>()).*(std::declval<PMF>()))(std::declval<Args>()...)) {
|
||||
return (sprout::forward<Pointer>(ptr).*(sprout::forward<PMF>(pmf)))(sprout::forward<Args>(args)...);
|
||||
return (SPROUT_FORWARD(Pointer, ptr).*(SPROUT_FORWARD(PMF, pmf)))(SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
|
||||
template<typename R, typename F, typename... Args>
|
||||
|
|
Loading…
Reference in a new issue