From d99a7d14365c2bbe25198f1f8f22d294463e4b89 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 14 Jan 2013 01:13:48 +0900 Subject: [PATCH] fix: copy - support STL container --- sprout/adapt/sscrisk/cel/array.hpp | 55 +---------------- sprout/adapt/sscrisk/cel/utility.hpp | 9 +++ sprout/algorithm/fixed/copy.hpp | 28 ++++++++- .../container/container_construct_traits.hpp | 60 ++++++++++++------- sprout/container/container_traits.hpp | 36 +++++++++++ sprout/container/sscrisk/cel/array.hpp | 59 ++++++++++++++++++ sprout/pit/pit.hpp | 32 +++++----- 7 files changed, 189 insertions(+), 90 deletions(-) create mode 100644 sprout/adapt/sscrisk/cel/utility.hpp create mode 100644 sprout/container/sscrisk/cel/array.hpp diff --git a/sprout/adapt/sscrisk/cel/array.hpp b/sprout/adapt/sscrisk/cel/array.hpp index 97b95fdd..2a7058f4 100644 --- a/sprout/adapt/sscrisk/cel/array.hpp +++ b/sprout/adapt/sscrisk/cel/array.hpp @@ -3,57 +3,8 @@ #include #include -#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION -# include -# include -# include -# include -#endif - -#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION -namespace sprout { - // - // container_traits - // - template - struct container_traits > - : public sprout::detail::container_traits_default > - { - public: - typedef sprout::index_iterator&> iterator; - typedef sprout::index_iterator const&> const_iterator; - }; -} // namespace sprout - -namespace sprout { - // - // range_begin - // - template - inline typename sprout::container_traits >::iterator - range_begin(sscrisk::cel::array& cont) { - return typename sprout::container_traits >::iterator(cont, 0); - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator - range_begin(sscrisk::cel::array const& cont) { - return typename sprout::container_traits >::const_iterator(cont, 0); - } - - // - // range_end - // - template - inline typename sprout::container_traits >::iterator - range_end(sscrisk::cel::array& cont) { - return typename sprout::container_traits >::iterator(cont, cont.size()); - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator - range_end(sscrisk::cel::array const& cont) { - return typename sprout::container_traits >::const_iterator(cont, cont.size()); - } -} // namespace sprout -#endif +#include +#include +#include #endif // #ifndef SPROUT_ADAPT_SSCRISK_CEL_ARRAY_HPP diff --git a/sprout/adapt/sscrisk/cel/utility.hpp b/sprout/adapt/sscrisk/cel/utility.hpp new file mode 100644 index 00000000..946c3dd0 --- /dev/null +++ b/sprout/adapt/sscrisk/cel/utility.hpp @@ -0,0 +1,9 @@ +#ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP +#define SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP diff --git a/sprout/algorithm/fixed/copy.hpp b/sprout/algorithm/fixed/copy.hpp index e325a9c7..eb94722f 100644 --- a/sprout/algorithm/fixed/copy.hpp +++ b/sprout/algorithm/fixed/copy.hpp @@ -49,6 +49,7 @@ namespace sprout { sprout::distance(first, last) ); } + template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args), @@ -87,6 +88,30 @@ namespace sprout { { return sprout::fixed::detail::copy_impl(first, last, result, sprout::size(result)); } + + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::is_fixed_container::value, + typename sprout::fixed::result_of::algorithm::type + >::type + copy(InputIterator first, InputIterator last, Result const& result) + { + typedef typename std::iterator_traits::iterator_category* category; + return sprout::fixed::detail::copy(first, last, result, category()); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !sprout::is_fixed_container::value, + typename sprout::fixed::result_of::algorithm::type + >::type + copy(InputIterator first, InputIterator last, Result const& result) + { + return sprout::remake( + result, + sprout::size(result), + first, last + ); + } } // namespace detail // // copy @@ -94,8 +119,7 @@ namespace sprout { template inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type copy(InputIterator first, InputIterator last, Result const& result) { - typedef typename std::iterator_traits::iterator_category* category; - return sprout::fixed::detail::copy(first, last, result, category()); + return sprout::fixed::detail::copy(first, last, result); } } // namespace fixed diff --git a/sprout/container/container_construct_traits.hpp b/sprout/container/container_construct_traits.hpp index 6e5b3a33..350f66dc 100644 --- a/sprout/container/container_construct_traits.hpp +++ b/sprout/container/container_construct_traits.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP #define SPROUT_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP +#include #include #include #include @@ -14,34 +15,51 @@ namespace sprout { namespace detail { template - inline SPROUT_CONSTEXPR typename sprout::container_construct_traits::copied_type + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::is_fixed_container::value, + typename sprout::container_construct_traits::copied_type + >::type default_make_container(Args&&... args) { typedef typename sprout::container_construct_traits::copied_type copied_type; return copied_type{{sprout::forward(args)...}}; } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !sprout::is_fixed_container::value, + typename sprout::container_construct_traits::copied_type + >::type + default_make_container(Args&&... args) { + typedef typename sprout::container_construct_traits::copied_type copied_type; + return copied_type{sprout::forward(args)...}; + } + + template + struct container_construct_traits_impl { + public: + typedef Container copied_type; + public: + template + static SPROUT_CONSTEXPR copied_type + deep_copy(Cont&& cont) { + return sprout::forward(cont); + } + template + static SPROUT_CONSTEXPR copied_type + make(Args&&... args) { + return sprout::detail::default_make_container(sprout::forward(args)...); + } + template + static SPROUT_CONSTEXPR copied_type + remake(Cont&& cont, typename sprout::container_traits::difference_type size, Args&&... args) { + return make(sprout::forward(args)...); + } + }; } // namespace detail template - struct container_construct_traits { - public: - typedef Container copied_type; - public: - template - static SPROUT_CONSTEXPR copied_type - deep_copy(Cont&& cont) { - return sprout::forward(cont); - } - template - static SPROUT_CONSTEXPR copied_type - make(Args&&... args) { - return sprout::detail::default_make_container(sprout::forward(args)...); - } - template - static SPROUT_CONSTEXPR copied_type - remake(Cont&& cont, typename sprout::container_traits::difference_type size, Args&&... args) { - return make(sprout::forward(args)...); - } - }; + struct container_construct_traits + : public sprout::detail::container_construct_traits_impl + {}; template struct container_construct_traits : public sprout::container_construct_traits diff --git a/sprout/container/container_traits.hpp b/sprout/container/container_traits.hpp index 3afb36f1..d3854d24 100644 --- a/sprout/container/container_traits.hpp +++ b/sprout/container/container_traits.hpp @@ -513,6 +513,42 @@ namespace sprout { , public sprout::detail::inherit_if_static_size > , public sprout::detail::container_nosy_fixed_size > {}; + + // + // is_fixed_container + // + template + struct is_fixed_container + : public sprout::detail::has_static_size > + {}; + + namespace detail { + // + // static_size_or_zero + // + template + struct static_size_or_zero; + template + struct static_size_or_zero< + Container, + typename std::enable_if >::value>::type + > + : public std::integral_constant< + typename sprout::container_traits::size_type, + sprout::container_traits::static_size + > + {}; + template + struct static_size_or_zero< + Container, + typename std::enable_if >::value>::type + > + : public std::integral_constant< + typename sprout::container_traits::size_type, + 0 + > + {}; + } // namespace sprout } // namespace sprout #endif // #ifndef SPROUT_CONTAINER_CONTAINER_TRAITS_HPP diff --git a/sprout/container/sscrisk/cel/array.hpp b/sprout/container/sscrisk/cel/array.hpp new file mode 100644 index 00000000..0d0e297b --- /dev/null +++ b/sprout/container/sscrisk/cel/array.hpp @@ -0,0 +1,59 @@ +#ifndef SPROUT_CONTAINER_SSCRISK_CEL_ARRAY_HPP +#define SPROUT_CONTAINER_SSCRISK_CEL_ARRAY_HPP + +#include +#include +#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION +# include +# include +# include +# include +#endif + +#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION +namespace sprout { + // + // container_traits + // + template + struct container_traits > + : public sprout::detail::container_traits_default > + { + public: + typedef sprout::index_iterator&> iterator; + typedef sprout::index_iterator const&> const_iterator; + }; +} // namespace sprout + +namespace sprout { + // + // range_begin + // + template + inline typename sprout::container_traits >::iterator + range_begin(sscrisk::cel::array& cont) { + return typename sprout::container_traits >::iterator(cont, 0); + } + template + inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator + range_begin(sscrisk::cel::array const& cont) { + return typename sprout::container_traits >::const_iterator(cont, 0); + } + + // + // range_end + // + template + inline typename sprout::container_traits >::iterator + range_end(sscrisk::cel::array& cont) { + return typename sprout::container_traits >::iterator(cont, cont.size()); + } + template + inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator + range_end(sscrisk::cel::array const& cont) { + return typename sprout::container_traits >::const_iterator(cont, cont.size()); + } +} // namespace sprout +#endif + +#endif // #ifndef SPROUT_CONTAINER_SSCRISK_CEL_ARRAY_HPP diff --git a/sprout/pit/pit.hpp b/sprout/pit/pit.hpp index b7cdef0f..f3ade3a3 100644 --- a/sprout/pit/pit.hpp +++ b/sprout/pit/pit.hpp @@ -16,22 +16,24 @@ namespace sprout { // pit // template - class pit { + class pit + : public sprout::container_traits_facade + { public: typedef Container container_type; - typedef typename sprout::container_traits::value_type value_type; - typedef typename sprout::container_traits::reference reference; - typedef typename sprout::container_traits::const_reference const_reference; + typedef typename sprout::container_traits_facade::value_type value_type; + typedef typename sprout::container_traits_facade::reference reference; + typedef typename sprout::container_traits_facade::const_reference const_reference; typedef typename sprout::value_iterator iterator; typedef typename sprout::value_iterator const_iterator; - typedef typename sprout::container_traits::size_type size_type; - typedef typename sprout::container_traits::difference_type difference_type; - typedef typename sprout::container_traits::pointer pointer; - typedef typename sprout::container_traits::const_pointer const_pointer; + typedef typename sprout::container_traits_facade::size_type size_type; + typedef typename sprout::container_traits_facade::difference_type difference_type; + typedef typename sprout::container_traits_facade::pointer pointer; + typedef typename sprout::container_traits_facade::const_pointer const_pointer; typedef typename sprout::reverse_iterator reverse_iterator; typedef typename sprout::reverse_iterator const_reverse_iterator; public: - SPROUT_STATIC_CONSTEXPR size_type static_size = sprout::container_traits::static_size; + SPROUT_STATIC_CONSTEXPR size_type enumerable_size = sprout::detail::static_size_or_zero >::value; public: value_type elem; public: @@ -43,10 +45,10 @@ namespace sprout { } // iterators: iterator begin() { - return iterator(elem, static_size); + return iterator(elem, enumerable_size); } SPROUT_CONSTEXPR const_iterator begin() const { - return const_iterator(elem, static_size); + return const_iterator(elem, enumerable_size); } iterator end() SPROUT_NOEXCEPT { return iterator(elem, 0); @@ -67,7 +69,7 @@ namespace sprout { return const_reverse_iterator(begin()); } SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT { - return const_iterator(elem, static_size); + return const_iterator(elem, enumerable_size); } SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT { return const_iterator(elem, 0); @@ -80,13 +82,13 @@ namespace sprout { } // capacity: SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT { - return static_size; + return enumerable_size; } SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT { return size(); } SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT { - return static_size == 0; + return enumerable_size == 0; } // element access: reference operator[](size_type i) { @@ -127,7 +129,7 @@ namespace sprout { } }; template - SPROUT_CONSTEXPR_OR_CONST typename sprout::pit::size_type sprout::pit::static_size; + SPROUT_CONSTEXPR_OR_CONST typename sprout::pit::size_type sprout::pit::enumerable_size; // // swap