From a110b0ad0fc89643233762036e8b83c61d60738b Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 9 Jan 2012 21:32:51 +0900 Subject: [PATCH] =?UTF-8?q?sprout/utility/pack.hpp=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/index_tuple.hpp | 4 +-- sprout/utility/enabler.hpp | 10 ++++++ sprout/utility/pack.hpp | 65 ++++++++++++++++++++++++++++++++++++++ testspr/typeinfo.hpp | 39 +++++++++++++++++++++++ 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 sprout/utility/enabler.hpp create mode 100644 sprout/utility/pack.hpp create mode 100644 testspr/typeinfo.hpp diff --git a/sprout/index_tuple.hpp b/sprout/index_tuple.hpp index 4bab21dc..e9550df2 100644 --- a/sprout/index_tuple.hpp +++ b/sprout/index_tuple.hpp @@ -28,7 +28,7 @@ namespace sprout { std::ptrdiff_t First, std::ptrdiff_t Last, std::ptrdiff_t Step, - std::ptrdiff_t ...Indexes + std::ptrdiff_t... Indexes > struct index_range, false> : public sprout::index_range > @@ -49,7 +49,7 @@ namespace sprout { template< std::ptrdiff_t I, std::ptrdiff_t N, - std::ptrdiff_t ...Indexes + std::ptrdiff_t... Indexes > struct index_n, false> : public sprout::index_n > diff --git a/sprout/utility/enabler.hpp b/sprout/utility/enabler.hpp new file mode 100644 index 00000000..d2123e45 --- /dev/null +++ b/sprout/utility/enabler.hpp @@ -0,0 +1,10 @@ +#ifndef SPROUT_UTILITY_ENABLER_HPP +#define SPROUT_UTILITY_ENABLER_HPP + +#include + +namespace sprout { + extern void* enabler; +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_ENABLER_HPP diff --git a/sprout/utility/pack.hpp b/sprout/utility/pack.hpp new file mode 100644 index 00000000..4c8e71c4 --- /dev/null +++ b/sprout/utility/pack.hpp @@ -0,0 +1,65 @@ +#ifndef SPROUT_UTILITY_PACK_HPP +#define SPROUT_UTILITY_PACK_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // tppack_at + // + namespace detail { + template + struct tppack_at_impl { + public: + typedef typename sprout::detail::tppack_at_impl::type type; + }; + template + struct tppack_at_impl<0, Head, Tail...> { + public: + typedef Head type; + }; + } // namespace detail + template + struct tppack_at + : public sprout::detail::tppack_at_impl + {}; + + // + // fppack_at + // + namespace detail { + template< + std::size_t N, + typename R, + typename Head, + typename... Tail, + typename std::enable_if::type*& = sprout::enabler + > + SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) { + return sprout::forward(head); + } + template< + std::size_t N, + typename R, + typename Head, + typename... Tail, + typename std::enable_if::type*& = sprout::enabler + > + SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) { + return sprout::detail::fppack_at_impl(sprout::forward(tail)...); + } + } // namespace detail + template + SPROUT_CONSTEXPR typename sprout::tppack_at::type fppack_at(Args&&... args) { + return sprout::detail::fppack_at_impl< + N, + typename sprout::tppack_at::type + >(sprout::forward(args)...); + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_PACK_HPP diff --git a/testspr/typeinfo.hpp b/testspr/typeinfo.hpp new file mode 100644 index 00000000..91e0446d --- /dev/null +++ b/testspr/typeinfo.hpp @@ -0,0 +1,39 @@ +#ifndef TESTSPR_TYPEINFO_HPP +#define TESTSPR_TYPEINFO_HPP + +#if defined(__GNUC__) +# include +#endif +#include +#include +#if defined(__GNUC__) +# include +#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 + std::string typename_of() { + return testspr::detail::gcc_demangle(typeid(T).name()); + } +#else + template + std::string typename_of() { + return std::string(typeid(T).name()); + } +#endif +} // namespace testspr + +#endif // #ifndef TESTSPR_TYPEINFO_HPP