From aec77334ef77b18f2cf77adb36edc2a901c2d4d2 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 11 Aug 2012 21:53:12 +0900 Subject: [PATCH] add sprout::cbind --- sprout/breed/breed_fwd.hpp | 2 +- sprout/endian_traits.hpp | 34 +++++++++++++++++++++++++++++++-- sprout/functional/bind/bind.hpp | 20 +++++++++++++++++++ sprout/tuple/tuple/tuple.hpp | 2 +- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/sprout/breed/breed_fwd.hpp b/sprout/breed/breed_fwd.hpp index 14bf8ec5..b41e09ef 100644 --- a/sprout/breed/breed_fwd.hpp +++ b/sprout/breed/breed_fwd.hpp @@ -24,7 +24,7 @@ namespace sprout { struct private_type_ { public: - SPROUT_CONSTEXPR private_type_ operator,(int) const; //??? + SPROUT_CONSTEXPR private_type_ operator,(int) const; // ??? }; template diff --git a/sprout/endian_traits.hpp b/sprout/endian_traits.hpp index 2610b0c8..08e9b6d1 100644 --- a/sprout/endian_traits.hpp +++ b/sprout/endian_traits.hpp @@ -13,7 +13,22 @@ namespace sprout { template class default_big_endian_traits< T, - typename std::enable_if::value>::type + typename std::enable_if::value && sizeof(T) == 1>::type + > { + public: + typedef T type; + public: + static SPROUT_CONSTEXPR std::size_t size() { + return sizeof(type); + } + static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t i) { + return static_cast(t); + } + }; + template + class default_big_endian_traits< + T, + typename std::enable_if::value && !(sizeof(T) == 1)>::type > { public: typedef T type; @@ -34,7 +49,22 @@ namespace sprout { template class default_little_endian_traits< T, - typename std::enable_if::value>::type + typename std::enable_if::value && sizeof(T) == 1>::type + > { + public: + typedef T type; + public: + static SPROUT_CONSTEXPR std::size_t size() { + return sizeof(type); + } + static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t i) { + return static_cast(t); + } + }; + template + class default_little_endian_traits< + T, + typename std::enable_if::value && !(sizeof(T) == 1)>::type > { public: typedef T type; diff --git a/sprout/functional/bind/bind.hpp b/sprout/functional/bind/bind.hpp index 8e9efeae..89436c26 100644 --- a/sprout/functional/bind/bind.hpp +++ b/sprout/functional/bind/bind.hpp @@ -554,6 +554,26 @@ namespace sprout { typedef typename helper_type::type result_type; return result_type(maybe_type::do_wrap(sprout::forward(f)), sprout::forward(args)...); } + + // + // cbind + // + template + inline SPROUT_CONSTEXPR typename sprout::detail::bind_helper::type const + cbind(F&& f, BoundArgs&&... args) { + typedef sprout::detail::bind_helper helper_type; + typedef typename helper_type::maybe_type maybe_type; + typedef typename helper_type::type result_type; + return result_type(maybe_type::do_wrap(sprout::forward(f)), sprout::forward(args)...); + } + template + inline SPROUT_CONSTEXPR typename sprout::detail::bindres_helper::type const + cbind(F&& f, BoundArgs&&... args) { + typedef sprout::detail::bindres_helper helper_type; + typedef typename helper_type::maybe_type maybe_type; + typedef typename helper_type::type result_type; + return result_type(maybe_type::do_wrap(sprout::forward(f)), sprout::forward(args)...); + } } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_BIND_BIND_HPP diff --git a/sprout/tuple/tuple/tuple.hpp b/sprout/tuple/tuple/tuple.hpp index 1eca081d..b6e38ff4 100644 --- a/sprout/tuple/tuple/tuple.hpp +++ b/sprout/tuple/tuple/tuple.hpp @@ -15,7 +15,7 @@ namespace sprout { namespace detail { template class head_base; - //??? + // ??? // EBO disabled // template // class head_base