mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-02-04 21:33:56 +00:00
sprout/utility/pack.hpp 追加
This commit is contained in:
parent
9dbdf452d9
commit
a110b0ad0f
4 changed files with 116 additions and 2 deletions
|
@ -28,7 +28,7 @@ namespace sprout {
|
||||||
std::ptrdiff_t First,
|
std::ptrdiff_t First,
|
||||||
std::ptrdiff_t Last,
|
std::ptrdiff_t Last,
|
||||||
std::ptrdiff_t Step,
|
std::ptrdiff_t Step,
|
||||||
std::ptrdiff_t ...Indexes
|
std::ptrdiff_t... Indexes
|
||||||
>
|
>
|
||||||
struct index_range<First, Last, Step, sprout::index_tuple<Indexes...>, false>
|
struct index_range<First, Last, Step, sprout::index_tuple<Indexes...>, false>
|
||||||
: public sprout::index_range<First + Step, Last, Step, sprout::index_tuple<Indexes..., First> >
|
: public sprout::index_range<First + Step, Last, Step, sprout::index_tuple<Indexes..., First> >
|
||||||
|
@ -49,7 +49,7 @@ namespace sprout {
|
||||||
template<
|
template<
|
||||||
std::ptrdiff_t I,
|
std::ptrdiff_t I,
|
||||||
std::ptrdiff_t N,
|
std::ptrdiff_t N,
|
||||||
std::ptrdiff_t ...Indexes
|
std::ptrdiff_t... Indexes
|
||||||
>
|
>
|
||||||
struct index_n<I, N, sprout::index_tuple<Indexes...>, false>
|
struct index_n<I, N, sprout::index_tuple<Indexes...>, false>
|
||||||
: public sprout::index_n<I, N - 1, sprout::index_tuple<Indexes..., I> >
|
: public sprout::index_n<I, N - 1, sprout::index_tuple<Indexes..., I> >
|
||||||
|
|
10
sprout/utility/enabler.hpp
Normal file
10
sprout/utility/enabler.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef SPROUT_UTILITY_ENABLER_HPP
|
||||||
|
#define SPROUT_UTILITY_ENABLER_HPP
|
||||||
|
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
extern void* enabler;
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_UTILITY_ENABLER_HPP
|
65
sprout/utility/pack.hpp
Normal file
65
sprout/utility/pack.hpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#ifndef SPROUT_UTILITY_PACK_HPP
|
||||||
|
#define SPROUT_UTILITY_PACK_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/utility/forward.hpp>
|
||||||
|
#include <sprout/utility/enabler.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// tppack_at
|
||||||
|
//
|
||||||
|
namespace detail {
|
||||||
|
template<std::size_t N, typename Head, typename... Tail>
|
||||||
|
struct tppack_at_impl {
|
||||||
|
public:
|
||||||
|
typedef typename sprout::detail::tppack_at_impl<N - 1, Tail...>::type type;
|
||||||
|
};
|
||||||
|
template<typename Head, typename... Tail>
|
||||||
|
struct tppack_at_impl<0, Head, Tail...> {
|
||||||
|
public:
|
||||||
|
typedef Head type;
|
||||||
|
};
|
||||||
|
} // namespace detail
|
||||||
|
template<std::size_t N, typename... Args>
|
||||||
|
struct tppack_at
|
||||||
|
: public sprout::detail::tppack_at_impl<N, Args...>
|
||||||
|
{};
|
||||||
|
|
||||||
|
//
|
||||||
|
// fppack_at
|
||||||
|
//
|
||||||
|
namespace detail {
|
||||||
|
template<
|
||||||
|
std::size_t N,
|
||||||
|
typename R,
|
||||||
|
typename Head,
|
||||||
|
typename... Tail,
|
||||||
|
typename std::enable_if<N == 0>::type*& = sprout::enabler
|
||||||
|
>
|
||||||
|
SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) {
|
||||||
|
return sprout::forward<Head>(head);
|
||||||
|
}
|
||||||
|
template<
|
||||||
|
std::size_t N,
|
||||||
|
typename R,
|
||||||
|
typename Head,
|
||||||
|
typename... Tail,
|
||||||
|
typename std::enable_if<N != 0>::type*& = sprout::enabler
|
||||||
|
>
|
||||||
|
SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) {
|
||||||
|
return sprout::detail::fppack_at_impl<N - 1, R>(sprout::forward<Tail>(tail)...);
|
||||||
|
}
|
||||||
|
} // namespace detail
|
||||||
|
template<std::size_t N, typename... Args>
|
||||||
|
SPROUT_CONSTEXPR typename sprout::tppack_at<N, Args&&...>::type fppack_at(Args&&... args) {
|
||||||
|
return sprout::detail::fppack_at_impl<
|
||||||
|
N,
|
||||||
|
typename sprout::tppack_at<N, Args&&...>::type
|
||||||
|
>(sprout::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_UTILITY_PACK_HPP
|
39
testspr/typeinfo.hpp
Normal file
39
testspr/typeinfo.hpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#ifndef TESTSPR_TYPEINFO_HPP
|
||||||
|
#define TESTSPR_TYPEINFO_HPP
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
# include <cstdlib>
|
||||||
|
#endif
|
||||||
|
#include <string>
|
||||||
|
#include <typeinfo>
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
# include <cxxabi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace testspr {
|
||||||
|
//
|
||||||
|
// typename_of
|
||||||
|
//
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
namespace detail {
|
||||||
|
std::string gcc_demangle(char const* mangled) {
|
||||||
|
int status;
|
||||||
|
char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
|
||||||
|
std::string result(demangled);
|
||||||
|
std::free(demangled);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace detail
|
||||||
|
template<typename T>
|
||||||
|
std::string typename_of() {
|
||||||
|
return testspr::detail::gcc_demangle(typeid(T).name());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
template<typename T>
|
||||||
|
std::string typename_of() {
|
||||||
|
return std::string(typeid(T).name());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} // namespace testspr
|
||||||
|
|
||||||
|
#endif // #ifndef TESTSPR_TYPEINFO_HPP
|
Loading…
Add table
Reference in a new issue