diff --git a/sprout/algorithm/fit/partition_copy.hpp b/sprout/algorithm/fit/partition_copy.hpp index 8d868df0..2af9364b 100644 --- a/sprout/algorithm/fit/partition_copy.hpp +++ b/sprout/algorithm/fit/partition_copy.hpp @@ -8,6 +8,7 @@ #ifndef SPROUT_ALGORITHM_FIT_PARTITION_COPY_HPP #define SPROUT_ALGORITHM_FIT_PARTITION_COPY_HPP +#include #include #include #include @@ -30,11 +31,12 @@ namespace sprout { typename sprout::container_traits::difference_type offset ) { + typedef typename std::iterator_traits::difference_type diff_type; return sprout::sub_copy( sprout::get_internal(sprout::fixed::partition_copy(first, last, result, pred)), offset, offset + sprout::fit_size( - result, sprout::detail::count_n_if(first, NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first, last), sprout::size(result)), pred) + result, sprout::detail::count_n_if(first, NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first, last), sprout::size(result)), pred) ) ); } diff --git a/sprout/container/begin.hpp b/sprout/container/begin.hpp index 62e70593..c43f6143 100644 --- a/sprout/container/begin.hpp +++ b/sprout/container/begin.hpp @@ -10,8 +10,8 @@ #include #include +#include #include -#include #include namespace sprout_adl { @@ -81,4 +81,6 @@ namespace sprout { } } // namespace sprout +#include + #endif // #ifndef SPROUT_CONTAINER_BEGIN_HPP diff --git a/sprout/container/construct_functions.hpp b/sprout/container/construct_functions.hpp new file mode 100644 index 00000000..d7fa750b --- /dev/null +++ b/sprout/container/construct_functions.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_CONTAINER_CONSTRUCT_FUNCTIONS_HPP +#define SPROUT_CONTAINER_CONSTRUCT_FUNCTIONS_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_CONTAINER_CONSTRUCT_FUNCTIONS_HPP diff --git a/sprout/container/container_construct_traits.hpp b/sprout/container/container_construct_traits.hpp index ddd931b0..160af30a 100644 --- a/sprout/container/container_construct_traits.hpp +++ b/sprout/container/container_construct_traits.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -26,9 +27,6 @@ namespace sprout { // // container_construct_traits // - template - struct container_construct_traits; - namespace detail { template inline SPROUT_CONSTEXPR typename std::enable_if< diff --git a/sprout/container/container_fitness_traits.hpp b/sprout/container/container_fitness_traits.hpp index 1054fbb7..dfaca490 100644 --- a/sprout/container/container_fitness_traits.hpp +++ b/sprout/container/container_fitness_traits.hpp @@ -9,6 +9,7 @@ #define SPROUT_CONTAINER_CONTAINER_FITNESS_TRAITS_HPP #include +#include #include #include #include @@ -23,7 +24,7 @@ namespace sprout { public: template static SPROUT_CONSTEXPR typename sprout::container_traits::difference_type - fit_size(Cont&& cont, typename sprout::container_traits::difference_type size) { + fit_size(Cont&& cont, typename sprout::container_traits::size_type size) { return NS_SSCRISK_CEL_OR_SPROUT::min(size, sprout::size(SPROUT_FORWARD(Cont, cont))); } }; diff --git a/sprout/container/container_range_traits.hpp b/sprout/container/container_range_traits.hpp index bc3fb647..8d4ab805 100644 --- a/sprout/container/container_range_traits.hpp +++ b/sprout/container/container_range_traits.hpp @@ -8,17 +8,126 @@ #ifndef SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP #define SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP -#include +#include +#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include namespace sprout { // // container_range_traits // + namespace detail { + template + struct has_mem_size_test { + public: + template< + typename U = T, + typename = typename sprout::identity().size())>::type + > + static sprout::true_type test(int); + static sprout::false_type test(...); + }; +#if defined(_MSC_VER) + template::test(0))>::type> + struct has_mem_size + : public Base_ + {}; +#else + template + struct has_mem_size + : public sprout::identity::test(0))>::type + {}; +#endif + + template + struct container_range_traits_range_size_impl; + template + struct container_range_traits_range_size_impl< + Container, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type + range_size(Container const& cont) { + return cont.size(); + } + }; + template + struct container_range_traits_range_size_impl< + Container, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type + range_size(Container const& cont) { + return sprout::distance(sprout::begin(cont), sprout::end(cont)); + } + }; + + template + struct has_mem_empty_test { + public: + template< + typename U = T, + typename = typename sprout::identity().empty())>::type + > + static sprout::true_type test(int); + static sprout::false_type test(...); + }; +#if defined(_MSC_VER) + template::test(0))>::type> + struct has_mem_empty + : public Base_ + {}; +#else + template + struct has_mem_empty + : public sprout::identity::test(0))>::type + {}; +#endif + + template + struct container_range_traits_range_empty_impl; + template + struct container_range_traits_range_empty_impl< + Container, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR bool + range_empty(Container const& cont) { + return cont.empty(); + } + }; + template + struct container_range_traits_range_empty_impl< + Container, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR bool + range_empty(Container const& cont) { + return sprout::size(cont) == 0; + } + }; + } // namespace detail + template - struct container_range_traits { + struct container_range_traits + : public sprout::detail::container_range_traits_range_size_impl + , public sprout::detail::container_range_traits_range_empty_impl + { public: + // iterators: static SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(Container& cont) { return cont.begin(); @@ -27,7 +136,6 @@ namespace sprout { range_begin(Container const& cont) { return cont.begin(); } - static SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_end(Container& cont) { return cont.end(); @@ -40,20 +148,30 @@ namespace sprout { template struct container_range_traits { public: + // iterators: static SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(Container const& cont) { return sprout::container_range_traits::range_begin(cont); } - static SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_end(Container const& cont) { return sprout::container_range_traits::range_end(cont); } + // capacity: + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type + range_size(Container const& cont) { + return sprout::container_range_traits::range_size(cont); + } + static SPROUT_CONSTEXPR bool + range_empty(Container const& cont) { + return sprout::container_range_traits::range_empty(cont); + } }; template struct container_range_traits { public: + // iterators: static SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(T (& arr)[N]) { typedef typename sprout::container_traits::iterator type; @@ -64,7 +182,6 @@ namespace sprout { typedef typename sprout::container_traits::iterator type; return type(arr); } - static SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_end(T (& arr)[N]) { typedef typename sprout::container_traits::iterator type; @@ -75,19 +192,37 @@ namespace sprout { typedef typename sprout::container_traits::iterator type; return type(arr) + N; } + // capacity: + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type + range_size(T const (&)[N]) { + return N; + } + static SPROUT_CONSTEXPR bool + range_empty(T const (&)[N]) { + return false; + } }; template struct container_range_traits { public: + // iterators: static SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(T const (& arr)[N]) { return sprout::container_range_traits::range_begin(arr); } - static SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator range_end(T const (& arr)[N]) { return sprout::container_range_traits::range_end(arr); } + // capacity: + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type + range_size(T const (& arr)[N]) { + return sprout::container_range_traits::range_size(arr); + } + static SPROUT_CONSTEXPR bool + range_empty(T const (& arr)[N]) { + return sprout::container_range_traits::range_empty(arr); + } }; } // namespace sprout diff --git a/sprout/container/container_traits.hpp b/sprout/container/container_traits.hpp index 9af71d80..2d2a5b5f 100644 --- a/sprout/container/container_traits.hpp +++ b/sprout/container/container_traits.hpp @@ -17,15 +17,13 @@ #include #include #include +#include #if SPROUT_USE_PTR_INDEX_ITERATOR_IMPLEMENTATION # include #endif #include namespace sprout { - template - struct container_traits; - namespace detail { // // has_value_type @@ -574,7 +572,7 @@ namespace sprout { 0 > {}; - } // namespace sprout + } // namespace detail } // namespace sprout #endif // #ifndef SPROUT_CONTAINER_CONTAINER_TRAITS_HPP diff --git a/sprout/container/container_transform_traits.hpp b/sprout/container/container_transform_traits.hpp index 52f3d4ba..49dc3895 100644 --- a/sprout/container/container_transform_traits.hpp +++ b/sprout/container/container_transform_traits.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -18,9 +19,6 @@ namespace sprout { // // container_transform_traits // - template - struct container_transform_traits; - namespace detail { template::size_type Size> struct default_array_rebind_size; diff --git a/sprout/container/empty.hpp b/sprout/container/empty.hpp index 52b93e2f..66ab173a 100644 --- a/sprout/container/empty.hpp +++ b/sprout/container/empty.hpp @@ -9,18 +9,48 @@ #define SPROUT_CONTAINER_EMPTY_HPP #include -#include -#include +#include +#include +#include +#include + +namespace sprout_adl { + sprout::not_found_via_adl range_empty(...); +} // namespace sprout_adl namespace sprout { + namespace container_detail { + template + inline SPROUT_CONSTEXPR bool + range_empty(Container const& cont) { + return sprout::container_range_traits::range_empty(cont); + } + } // namespace container_detail + // // empty // + // effect: + // ADL callable range_empty(cont) -> range_empty(cont) + // otherwise -> sprout::container_range_traits::range_empty(cont) + // [default] + // callable cont.empty() -> cont.empty() + // otherwise -> size(cont) == 0 + // template inline SPROUT_CONSTEXPR bool empty(Container const& cont) { - return sprout::begin(cont) == sprout::end(cont); + using sprout::container_detail::range_empty; + using sprout_adl::range_empty; + return range_empty(cont); + } + template + inline SPROUT_CONSTEXPR bool + empty(T const (& arr)[N]) { + return sprout::container_detail::range_empty(arr); } } // namespace sprout +#include + #endif // #ifndef SPROUT_CONTAINER_EMPTY_HPP diff --git a/sprout/container/end.hpp b/sprout/container/end.hpp index 26703c69..d368f90c 100644 --- a/sprout/container/end.hpp +++ b/sprout/container/end.hpp @@ -10,8 +10,8 @@ #include #include +#include #include -#include #include namespace sprout_adl { @@ -81,4 +81,6 @@ namespace sprout { } } // namespace sprout +#include + #endif // #ifndef SPROUT_CONTAINER_END_HPP diff --git a/sprout/container/fitness_functions.hpp b/sprout/container/fitness_functions.hpp new file mode 100644 index 00000000..962554ca --- /dev/null +++ b/sprout/container/fitness_functions.hpp @@ -0,0 +1,14 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_CONTAINER_FITNESS_FUNCTIONS_HPP +#define SPROUT_CONTAINER_FITNESS_FUNCTIONS_HPP + +#include +#include + +#endif // #ifndef SPROUT_CONTAINER_FITNESS_FUNCTIONS_HPP diff --git a/sprout/container/functions.hpp b/sprout/container/functions.hpp index 0aabc0df..5c7fc4cf 100644 --- a/sprout/container/functions.hpp +++ b/sprout/container/functions.hpp @@ -9,24 +9,10 @@ #define SPROUT_CONTAINER_FUNCTIONS_HPP #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_CONTAINER_FUNCTIONS_HPP diff --git a/sprout/container/range_functions.hpp b/sprout/container/range_functions.hpp new file mode 100644 index 00000000..d0c3900d --- /dev/null +++ b/sprout/container/range_functions.hpp @@ -0,0 +1,18 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_CONTAINER_RANGE_FUNCTIONS_HPP +#define SPROUT_CONTAINER_RANGE_FUNCTIONS_HPP + +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_CONTAINER_RANGE_FUNCTIONS_HPP diff --git a/sprout/container/range_functions_fwd.hpp b/sprout/container/range_functions_fwd.hpp new file mode 100644 index 00000000..c8f61a63 --- /dev/null +++ b/sprout/container/range_functions_fwd.hpp @@ -0,0 +1,66 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_CONTAINER_RANGE_FUNCTIONS_FWD_HPP +#define SPROUT_CONTAINER_RANGE_FUNCTIONS_FWD_HPP + +#include +#include + +namespace sprout { + // + // begin + // + template + SPROUT_CONSTEXPR typename sprout::container_traits::iterator + begin(Container& cont); + template + SPROUT_CONSTEXPR typename sprout::container_traits::iterator + begin(Container const& cont); + // + // cbegin + // + template + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator + cbegin(Container const& cont); + + // + // end + // + template + SPROUT_CONSTEXPR typename sprout::container_traits::iterator + end(Container& cont); + template + SPROUT_CONSTEXPR typename sprout::container_traits::iterator + end(Container const& cont); + // + // cend + // + template + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator + cend(Container const& cont); + + // + // size + // + template + SPROUT_CONSTEXPR typename sprout::container_traits::size_type + size(Container const& cont); + + // + // empty + // + template + SPROUT_CONSTEXPR bool + empty(Container const& cont); +} // namespace sprout + + +#include +#include + +#endif // #ifndef SPROUT_CONTAINER_RANGE_FUNCTIONS_FWD_HPP diff --git a/sprout/container/size.hpp b/sprout/container/size.hpp index fca44065..4aa5c81b 100644 --- a/sprout/container/size.hpp +++ b/sprout/container/size.hpp @@ -9,20 +9,48 @@ #define SPROUT_CONTAINER_SIZE_HPP #include +#include +#include #include -#include -#include -#include +#include + +namespace sprout_adl { + sprout::not_found_via_adl range_size(...); +} // namespace sprout_adl namespace sprout { + namespace container_detail { + template + inline SPROUT_CONSTEXPR typename sprout::container_traits::size_type + range_size(Container const& cont) { + return sprout::container_range_traits::range_size(cont); + } + } // namespace container_detail + // // size // + // effect: + // ADL callable range_size(cont) -> range_size(cont) + // otherwise -> sprout::container_range_traits::range_size(cont) + // [default] + // callable cont.size() -> cont.size() + // otherwise -> distance(begin(cont), end(cont)) + // template - inline SPROUT_CONSTEXPR typename sprout::container_traits::difference_type + inline SPROUT_CONSTEXPR typename sprout::container_traits::size_type size(Container const& cont) { - return sprout::distance(sprout::begin(cont), sprout::end(cont)); + using sprout::container_detail::range_size; + using sprout_adl::range_size; + return range_size(cont); + } + template + inline SPROUT_CONSTEXPR typename sprout::container_traits::size_type + size(T const (& arr)[N]) { + return sprout::container_detail::range_size(arr); } } // namespace sprout +#include + #endif // #ifndef SPROUT_CONTAINER_SIZE_HPP diff --git a/sprout/container/sub_container_traits.hpp b/sprout/container/sub_container_traits.hpp index 8dff8671..e70a3477 100644 --- a/sprout/container/sub_container_traits.hpp +++ b/sprout/container/sub_container_traits.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace sprout { // diff --git a/sprout/container/sub_functions.hpp b/sprout/container/sub_functions.hpp new file mode 100644 index 00000000..987511ad --- /dev/null +++ b/sprout/container/sub_functions.hpp @@ -0,0 +1,23 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_CONTAINER_SUB_FUNCTIONS_HPP +#define SPROUT_CONTAINER_SUB_FUNCTIONS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_CONTAINER_SUB_FUNCTIONS_HPP diff --git a/sprout/container/traits.hpp b/sprout/container/traits.hpp index 94dc995f..96db1ffa 100644 --- a/sprout/container/traits.hpp +++ b/sprout/container/traits.hpp @@ -9,6 +9,7 @@ #define SPROUT_CONTAINER_TRAITS_HPP #include +#include #include #include #include diff --git a/sprout/container/traits_functions.hpp b/sprout/container/traits_functions.hpp new file mode 100644 index 00000000..0de041f8 --- /dev/null +++ b/sprout/container/traits_functions.hpp @@ -0,0 +1,14 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_CONTAINER_TRAITS_FUNCTIONS_HPP +#define SPROUT_CONTAINER_TRAITS_FUNCTIONS_HPP + +#include +#include + +#endif // #ifndef SPROUT_CONTAINER_TRAITS_FUNCTIONS_HPP diff --git a/sprout/container/traits_fwd.hpp b/sprout/container/traits_fwd.hpp new file mode 100644 index 00000000..da97452b --- /dev/null +++ b/sprout/container/traits_fwd.hpp @@ -0,0 +1,51 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_CONTAINER_TRAITS_FWD_HPP +#define SPROUT_CONTAINER_TRAITS_FWD_HPP + +#include + +namespace sprout { + // + // container_traits + // + template + struct container_traits; + + // + // container_range_traits + // + template + struct container_range_traits; + + // + // container_construct_traits + // + template + struct container_construct_traits; + + // + // container_transform_traits + // + template + struct container_transform_traits; + + // + // container_fitness_traits + // + template + struct container_fitness_traits; + + // + // sub_container_traits + // + template + struct sub_container_traits; +} // namespace sprout + +#endif // #ifndef SPROUT_CONTAINER_TRAITS_FWD_HPP