mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-02-13 10:13:56 +00:00
rewrite sprout::algorithm::join performance
This commit is contained in:
parent
0ceabb5b9b
commit
1ea9d30e2a
145 changed files with 1359 additions and 364 deletions
|
@ -135,4 +135,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_BOGO_SORT_CPP
|
||||
|
||||
|
|
|
@ -177,4 +177,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_BOGO_SORT_RESULT_CPP
|
||||
|
||||
|
|
|
@ -104,4 +104,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_CPP
|
||||
|
||||
|
|
|
@ -104,4 +104,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_BACKWARD_CPP
|
||||
|
||||
|
|
|
@ -110,4 +110,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_IF_CPP
|
||||
|
||||
|
|
|
@ -104,4 +104,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_N_CPP
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_FILL_CPP
|
||||
|
||||
|
|
|
@ -78,4 +78,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_FILL_N_CPP
|
||||
|
||||
|
|
|
@ -78,4 +78,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_GENERATE_CPP
|
||||
|
||||
|
|
|
@ -82,4 +82,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_GENERATE_N_CPP
|
||||
|
||||
|
|
|
@ -133,4 +133,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_INPLACE_MERGE_CPP
|
||||
|
||||
|
|
|
@ -125,4 +125,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_MAKE_HEAP_CPP
|
||||
|
||||
|
|
|
@ -133,4 +133,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_MAKE_PARTIAL_HEAP_CPP
|
||||
|
||||
|
|
|
@ -221,4 +221,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_MERGE_CPP
|
||||
|
||||
|
|
|
@ -133,4 +133,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_NTH_ELEMENT_CPP
|
||||
|
||||
|
|
|
@ -133,4 +133,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_PARTIAL_SORT_CPP
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_PARTITION_CPP
|
||||
|
||||
|
|
|
@ -110,4 +110,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_PARTITION_COPY_CPP
|
||||
|
||||
|
|
|
@ -70,4 +70,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_POP_HEAP_CPP
|
||||
|
||||
|
|
|
@ -125,4 +125,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_PUSH_HEAP_CPP
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REMOVE_CPP
|
||||
|
||||
|
|
|
@ -110,4 +110,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REMOVE_COPY_CPP
|
||||
|
||||
|
|
|
@ -110,4 +110,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REMOVE_COPY_IF_CPP
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REMOVE_IF_CPP
|
||||
|
||||
|
|
|
@ -78,4 +78,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REPLACE_CPP
|
||||
|
||||
|
|
|
@ -116,4 +116,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REPLACE_COPY_CPP
|
||||
|
||||
|
|
|
@ -116,4 +116,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REPLACE_COPY_IF_CPP
|
||||
|
||||
|
|
|
@ -78,4 +78,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REPLACE_IF_CPP
|
||||
|
||||
|
|
|
@ -70,4 +70,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REBERSE_CPP
|
||||
|
||||
|
|
|
@ -104,4 +104,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_REBERSE_COPY_CPP
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_ROTATE_CPP
|
||||
|
||||
|
|
|
@ -110,4 +110,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_ROTATE_COPY_CPP
|
||||
|
||||
|
|
|
@ -221,4 +221,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SET_DIFFERENCE_CPP
|
||||
|
||||
|
|
|
@ -221,4 +221,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SET_INTERSECTION_CPP
|
||||
|
||||
|
|
|
@ -221,4 +221,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SET_SYMMETRIC_DIFFERENCE_CPP
|
||||
|
||||
|
|
|
@ -221,4 +221,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SET_UNION_CPP
|
||||
|
||||
|
|
|
@ -76,4 +76,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SHUFFLE_CPP
|
||||
|
||||
|
|
|
@ -97,4 +97,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SHUFFLE_RESULT_CPP
|
||||
|
||||
|
|
|
@ -125,4 +125,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SORT_CPP
|
||||
|
||||
|
|
|
@ -125,4 +125,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SORT_HEAP_CPP
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_STABLE_PARTITION_CPP
|
||||
|
||||
|
|
|
@ -110,4 +110,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_STABLE_PARTITION_COPY_CPP
|
||||
|
||||
|
|
|
@ -125,4 +125,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_STABLE_SORT_CPP
|
||||
|
||||
|
|
|
@ -78,4 +78,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SWAP_ELEMENT_CPP
|
||||
|
||||
|
|
|
@ -116,4 +116,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_SWAP_ELEMENT_COPY_CPP
|
||||
|
||||
|
|
|
@ -208,4 +208,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_TRANSFORM_CPP
|
||||
|
||||
|
|
|
@ -125,4 +125,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_UNIQUE_CPP
|
||||
|
||||
|
|
|
@ -195,4 +195,3 @@ namespace testspr {
|
|||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_UNIQUE_COPY_CPP
|
||||
|
||||
|
|
|
@ -3,6 +3,5 @@
|
|||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/string/join.hpp>
|
||||
#include <sprout/algorithm/string/join2.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_STRING_HPP
|
||||
|
|
|
@ -1,22 +1,88 @@
|
|||
#ifndef SPROUT_ALGORITHM_STRING_JOIN_HPP
|
||||
#define SPROUT_ALGORITHM_STRING_JOIN_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/iterator/traits.hpp>
|
||||
#include <sprout/utility/enabler_if.hpp>
|
||||
#include <sprout/range/adaptor/size_enumed.hpp>
|
||||
#include <sprout/range/algorithm/lower_bound.hpp>
|
||||
#include <sprout/range/numeric/partial_sum.hpp>
|
||||
#include <sprout/weed/traits/type/is_c_str.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace algorithm {
|
||||
namespace detail {
|
||||
template<typename String, typename = void>
|
||||
struct string_size;
|
||||
template<typename String>
|
||||
struct string_size<
|
||||
String,
|
||||
typename std::enable_if<sprout::weed::traits::is_c_str<String>::value>::type
|
||||
>
|
||||
: public std::integral_constant<
|
||||
typename sprout::container_traits<String>::size_type,
|
||||
sprout::container_traits<String>::static_size - 1
|
||||
>
|
||||
{};
|
||||
template<typename String>
|
||||
struct string_size<
|
||||
String,
|
||||
typename std::enable_if<!sprout::weed::traits::is_c_str<String>::value>::type
|
||||
>
|
||||
: public std::integral_constant<
|
||||
typename sprout::container_traits<String>::size_type,
|
||||
sprout::container_traits<String>::static_size
|
||||
>
|
||||
{};
|
||||
|
||||
template<
|
||||
typename String,
|
||||
typename sprout::enabler_if<sprout::weed::traits::is_c_str<String>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<String>::difference_type
|
||||
str_size(String const& str) {
|
||||
return sprout::size(str) - 1;
|
||||
}
|
||||
template<
|
||||
typename String,
|
||||
typename sprout::enabler_if<!sprout::weed::traits::is_c_str<String>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<String>::difference_type
|
||||
str_size(String const& str) {
|
||||
return sprout::size(str);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
namespace result_of {
|
||||
//
|
||||
// join
|
||||
//
|
||||
template<typename ContainerContainer>
|
||||
template<typename ContainerContainer, typename Separator = void>
|
||||
struct join {
|
||||
public:
|
||||
typedef typename sprout::container_transform_traits<
|
||||
typename sprout::container_traits<ContainerContainer>::value_type
|
||||
>::template rebind_size<
|
||||
sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer>::value_type
|
||||
>::static_size
|
||||
? (sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer>::value_type
|
||||
>::static_size
|
||||
+ sprout::algorithm::detail::string_size<Separator>::value
|
||||
)
|
||||
* sprout::container_traits<ContainerContainer>::static_size
|
||||
- sprout::algorithm::detail::string_size<Separator>::value
|
||||
: 0
|
||||
>::type type;
|
||||
};
|
||||
template<typename ContainerContainer>
|
||||
struct join<ContainerContainer, void> {
|
||||
public:
|
||||
typedef typename sprout::container_transform_traits<
|
||||
typename sprout::container_traits<ContainerContainer>::value_type
|
||||
|
@ -30,31 +96,80 @@ namespace sprout {
|
|||
} // namespace result_of
|
||||
|
||||
namespace detail {
|
||||
template<typename Result, typename ContainerInputIterator, typename... Args>
|
||||
template<typename Result, typename ContIterator, typename SizeIterator, typename Sizes>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Result>::value_type
|
||||
join_impl_ra_2(
|
||||
ContIterator first_cont,
|
||||
SizeIterator found,
|
||||
Sizes const& sizes,
|
||||
sprout::index_t idx
|
||||
)
|
||||
{
|
||||
typedef typename sprout::container_traits<Result>::value_type value_type;
|
||||
return found == sizes.end() ? value_type()
|
||||
: sprout::begin(first_cont[found - sizes.begin()])[idx - (found != sizes.begin() ? found[-1] : 0)]
|
||||
;
|
||||
}
|
||||
template<typename Result, typename ContIterator, sprout::index_t... Indexes, typename Sizes>
|
||||
inline SPROUT_CONSTEXPR Result
|
||||
join_impl_ra_1(
|
||||
ContIterator first_cont,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
Sizes const& sizes
|
||||
)
|
||||
{
|
||||
return sprout::make<Result>(
|
||||
sprout::algorithm::detail::join_impl_ra_2<Result>(
|
||||
first_cont,
|
||||
sprout::range::lower_bound(sizes, Indexes + 1),
|
||||
sizes,
|
||||
Indexes
|
||||
)...
|
||||
);
|
||||
}
|
||||
template<typename Result, typename ContainerContainer>
|
||||
inline SPROUT_CONSTEXPR Result
|
||||
join_impl_ra(ContainerContainer const& cont_cont) {
|
||||
typedef typename sprout::container_traits<Result>::difference_type size_type;
|
||||
typedef sprout::array<
|
||||
size_type,
|
||||
sprout::container_traits<ContainerContainer>::static_size
|
||||
> sizes_type;
|
||||
return sprout::algorithm::detail::join_impl_ra_1<Result>(
|
||||
sprout::begin(cont_cont),
|
||||
sprout::index_range<0, sprout::container_traits<Result>::static_size>::make(),
|
||||
sprout::range::partial_sum(
|
||||
cont_cont | sprout::adaptors::size_enumed,
|
||||
sprout::pit<sizes_type>()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename Result, typename ContIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContainerInputIterator first_cont,
|
||||
ContainerInputIterator last_cont,
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
Args const&... args
|
||||
);
|
||||
template<typename Result, typename ContainerInputIterator, typename... Args>
|
||||
template<typename Result, typename ContIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContainerInputIterator first_cont,
|
||||
ContainerInputIterator last_cont,
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
Args const&... args
|
||||
);
|
||||
template<typename Result, typename ContainerInputIterator, typename InputIterator, typename... Args>
|
||||
template<typename Result, typename ContIterator, typename InputIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl_1(
|
||||
ContainerInputIterator first_cont,
|
||||
ContainerInputIterator last_cont,
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Args const&... args
|
||||
|
@ -62,64 +177,345 @@ namespace sprout {
|
|||
{
|
||||
return sprout::make<Result>(args...);
|
||||
}
|
||||
template<typename Result, typename ContainerInputIterator, typename InputIterator, typename... Args>
|
||||
template<typename Result, typename ContIterator, typename InputIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl_1(
|
||||
ContainerInputIterator first_cont,
|
||||
ContainerInputIterator last_cont,
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
return first != last
|
||||
? sprout::algorithm::detail::join_impl_1<Result>(first_cont, last_cont, sprout::next(first), last, args..., *first)
|
||||
? sprout::algorithm::detail::join_impl_1<Result>(
|
||||
first_cont, last_cont,
|
||||
sprout::next(first), last,
|
||||
args..., *first
|
||||
)
|
||||
: sprout::algorithm::detail::join_impl<Result>(sprout::next(first_cont), last_cont, args...)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename ContainerInputIterator, typename... Args>
|
||||
template<typename Result, typename ContIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContainerInputIterator first_cont,
|
||||
ContainerInputIterator last_cont,
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
return sprout::make<Result>(args...);
|
||||
}
|
||||
template<typename Result, typename ContainerInputIterator, typename... Args>
|
||||
template<typename Result, typename ContIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContainerInputIterator first_cont,
|
||||
ContainerInputIterator last_cont,
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
return first_cont != last_cont
|
||||
? sprout::algorithm::detail::join_impl_1<Result>(first_cont, last_cont, sprout::begin(*first_cont), sprout::end(*first_cont), args...)
|
||||
? sprout::algorithm::detail::join_impl_1<Result>(
|
||||
first_cont, last_cont,
|
||||
sprout::begin(*first_cont), sprout::end(*first_cont),
|
||||
args...
|
||||
)
|
||||
: sprout::make<Result>(args...)
|
||||
;
|
||||
}
|
||||
|
||||
template<
|
||||
typename ContainerContainer,
|
||||
typename sprout::enabler_if<
|
||||
sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<ContainerContainer const>::iterator
|
||||
>::value
|
||||
&& sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer const>::value_type
|
||||
>::iterator
|
||||
>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join<ContainerContainer>::type
|
||||
join(ContainerContainer const& cont_cont) {
|
||||
typedef typename sprout::algorithm::result_of::join<ContainerContainer>::type result_type;
|
||||
return sprout::algorithm::detail::join_impl_ra<result_type>(cont_cont);
|
||||
}
|
||||
template<
|
||||
typename ContainerContainer,
|
||||
typename sprout::enabler_if<!(
|
||||
sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<ContainerContainer const>::iterator
|
||||
>::value
|
||||
&& sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer const>::value_type
|
||||
>::iterator
|
||||
>::value
|
||||
)>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join<ContainerContainer>::type
|
||||
join(ContainerContainer const& cont_cont) {
|
||||
typedef typename sprout::algorithm::result_of::join<ContainerContainer>::type result_type;
|
||||
return sprout::algorithm::detail::join_impl<result_type>(
|
||||
sprout::begin(cont_cont),
|
||||
sprout::end(cont_cont)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// join
|
||||
//
|
||||
template<typename ContainerContainer>
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join<ContainerContainer>::type join(
|
||||
ContainerContainer const& cont_cont
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join<ContainerContainer>::type
|
||||
join(ContainerContainer const& cont_cont) {
|
||||
return sprout::algorithm::detail::join(cont_cont);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename Result, typename ContIterator, typename SepIterator, typename SizeIterator, typename Sizes>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Result>::value_type
|
||||
join_impl_ra_2(
|
||||
ContIterator first_cont,
|
||||
SepIterator first,
|
||||
SizeIterator found,
|
||||
Sizes const& sizes,
|
||||
sprout::index_t idx
|
||||
)
|
||||
{
|
||||
return sprout::algorithm::detail::join_impl<typename sprout::algorithm::result_of::join<ContainerContainer>::type>(
|
||||
sprout::begin(cont_cont),
|
||||
sprout::end(cont_cont)
|
||||
typedef typename sprout::container_traits<Result>::value_type value_type;
|
||||
return found == sizes.end() ? value_type()
|
||||
: (found - sizes.begin()) % 2 ? first[idx - found[-1]]
|
||||
: sprout::begin(first_cont[(found - sizes.begin()) / 2])[idx - (found != sizes.begin() ? found[-1] : 0)]
|
||||
;
|
||||
}
|
||||
template<typename Result, typename ContIterator, typename SepIterator, sprout::index_t... Indexes, typename Sizes>
|
||||
inline SPROUT_CONSTEXPR Result
|
||||
join_impl_ra_1(
|
||||
ContIterator first_cont,
|
||||
SepIterator first,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
Sizes const& sizes
|
||||
)
|
||||
{
|
||||
return sprout::make<Result>(
|
||||
sprout::algorithm::detail::join_impl_ra_2<Result>(
|
||||
first_cont,
|
||||
first,
|
||||
sprout::range::lower_bound(sizes, Indexes + 1),
|
||||
sizes,
|
||||
Indexes
|
||||
)...
|
||||
);
|
||||
}
|
||||
template<typename Result, typename ContainerContainer, typename Separator>
|
||||
inline SPROUT_CONSTEXPR Result
|
||||
join_impl_ra(ContainerContainer const& cont_cont, Separator const& separator) {
|
||||
typedef typename sprout::container_traits<Result>::difference_type size_type;
|
||||
typedef sprout::array<
|
||||
size_type,
|
||||
sprout::container_traits<ContainerContainer>::static_size
|
||||
? sprout::container_traits<ContainerContainer>::static_size * 2 - 1
|
||||
: 0
|
||||
> sizes_type;
|
||||
return sprout::algorithm::detail::join_impl_ra_1<Result>(
|
||||
sprout::begin(cont_cont),
|
||||
sprout::begin(separator),
|
||||
sprout::index_range<0, sprout::container_traits<Result>::static_size>::make(),
|
||||
sprout::range::partial_sum(
|
||||
cont_cont | sprout::adaptors::size_enumed(sprout::algorithm::detail::str_size(separator), true),
|
||||
sprout::pit<sizes_type>()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename Result, typename ContIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
Args const&... args
|
||||
);
|
||||
template<typename Result, typename ContIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
Args const&... args
|
||||
);
|
||||
template<typename Result, typename ContIterator, typename SepIterator, typename InputIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl_1(
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
SepIterator sep_first,
|
||||
SepIterator sep_last,
|
||||
bool sep,
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
return sprout::make<Result>(args...);
|
||||
}
|
||||
template<typename Result, typename ContIterator, typename SepIterator, typename InputIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl_1(
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
SepIterator sep_first,
|
||||
SepIterator sep_last,
|
||||
bool sep,
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
return first != last
|
||||
? sprout::algorithm::detail::join_impl_1<Result>(
|
||||
first_cont, last_cont,
|
||||
sep_first, sep_last,
|
||||
sep,
|
||||
sprout::next(first), last,
|
||||
args..., *first
|
||||
)
|
||||
: sep
|
||||
? sprout::algorithm::detail::join_impl<Result>(
|
||||
sprout::next(first_cont), last_cont,
|
||||
sep_first, sep_last,
|
||||
false,
|
||||
args...
|
||||
)
|
||||
: sprout::algorithm::detail::join_impl<Result>(
|
||||
first_cont, last_cont,
|
||||
sep_first, sep_last,
|
||||
true,
|
||||
args...
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename ContIterator, typename SepIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
SepIterator sep_first,
|
||||
SepIterator sep_last,
|
||||
bool sep,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
return sprout::make<Result>(args...);
|
||||
}
|
||||
template<typename Result, typename ContIterator, typename SepIterator, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
||||
Result
|
||||
>::type join_impl(
|
||||
ContIterator first_cont,
|
||||
ContIterator last_cont,
|
||||
SepIterator sep_first,
|
||||
SepIterator sep_last,
|
||||
bool sep,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
return first_cont != last_cont
|
||||
? sep
|
||||
? sprout::algorithm::detail::join_impl_1<Result>(
|
||||
first_cont, last_cont,
|
||||
sep_first, sep_last,
|
||||
sep,
|
||||
sep_first, sep_last,
|
||||
args...
|
||||
)
|
||||
: sprout::algorithm::detail::join_impl_1<Result>(
|
||||
first_cont, last_cont,
|
||||
sep_first, sep_last,
|
||||
sep,
|
||||
sprout::begin(*first_cont), sprout::end(*first_cont),
|
||||
args...
|
||||
)
|
||||
: sprout::make<Result>(args...)
|
||||
;
|
||||
}
|
||||
|
||||
template<
|
||||
typename ContainerContainer,
|
||||
typename Separator,
|
||||
typename sprout::enabler_if<
|
||||
sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<ContainerContainer const>::iterator
|
||||
>::value
|
||||
&& sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer const>::value_type
|
||||
>::iterator
|
||||
>::value
|
||||
&& sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<Separator const>::iterator
|
||||
>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join<ContainerContainer>::type
|
||||
join(ContainerContainer const& cont_cont, Separator const& separator) {
|
||||
typedef typename sprout::algorithm::result_of::join<ContainerContainer>::type result_type;
|
||||
return sprout::algorithm::detail::join_impl_ra<result_type>(cont_cont, separator);
|
||||
}
|
||||
template<
|
||||
typename ContainerContainer,
|
||||
typename Separator,
|
||||
typename sprout::enabler_if<!(
|
||||
sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<ContainerContainer const>::iterator
|
||||
>::value
|
||||
&& sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer const>::value_type
|
||||
>::iterator
|
||||
>::value
|
||||
&& sprout::is_random_access_iterator<
|
||||
typename sprout::container_traits<Separator const>::iterator
|
||||
>::value
|
||||
)>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join<ContainerContainer>::type
|
||||
join(ContainerContainer const& cont_cont, Separator const& separator) {
|
||||
typedef typename sprout::algorithm::result_of::join<ContainerContainer>::type result_type;
|
||||
return sprout::algorithm::detail::join_impl<result_type>(
|
||||
sprout::begin(cont_cont),
|
||||
sprout::end(cont_cont),
|
||||
sprout::begin(separator),
|
||||
sprout::end(separator),
|
||||
false
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// join
|
||||
//
|
||||
template<typename ContainerContainer, typename Separator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join<ContainerContainer, Separator>::type
|
||||
join(ContainerContainer const& cont_cont, Separator const& separator) {
|
||||
return sprout::algorithm::detail::join(cont_cont, separator);
|
||||
}
|
||||
} // namespace algorithm
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
#ifndef SPROUT_ALGORITHM_STRING_JOIN2_HPP
|
||||
#define SPROUT_ALGORITHM_STRING_JOIN2_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/operation/fixed/append_back.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace algorithm {
|
||||
namespace result_of {
|
||||
//
|
||||
// join2
|
||||
//
|
||||
template<typename ContainerContainer, typename Separator>
|
||||
struct join2 {
|
||||
public:
|
||||
typedef typename sprout::container_transform_traits<
|
||||
typename sprout::container_traits<ContainerContainer>::value_type
|
||||
>::template rebind_size<
|
||||
sprout::container_traits<ContainerContainer>::static_size != 0
|
||||
? (
|
||||
sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer>::value_type
|
||||
>::static_size
|
||||
+ (sprout::container_traits<ContainerContainer>::static_size - 1) * (
|
||||
sprout::container_traits<Separator>::static_size
|
||||
+ sprout::container_traits<
|
||||
typename sprout::container_traits<ContainerContainer>::value_type
|
||||
>::static_size
|
||||
)
|
||||
)
|
||||
: 0
|
||||
>::type type;
|
||||
};
|
||||
} // namespace result_of
|
||||
|
||||
namespace detail {
|
||||
template<typename Result, typename ContainerIterator, typename Separator, typename Container>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
(sprout::container_traits<Container>::static_size == sprout::container_traits<Result>::static_size),
|
||||
Result
|
||||
>::type join2_impl_1(
|
||||
ContainerIterator first,
|
||||
ContainerIterator last,
|
||||
Separator const& separator,
|
||||
Container const& current
|
||||
)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
template<typename Result, typename ContainerIterator, typename Separator, typename Container>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
(sprout::container_traits<Container>::static_size < sprout::container_traits<Result>::static_size),
|
||||
Result
|
||||
>::type join2_impl_1(
|
||||
ContainerIterator first,
|
||||
ContainerIterator last,
|
||||
Separator const& separator,
|
||||
Container const& current
|
||||
)
|
||||
{
|
||||
return sprout::algorithm::detail::join2_impl_1<Result>(
|
||||
sprout::next(first),
|
||||
last,
|
||||
separator,
|
||||
sprout::fixed::append_back(sprout::fixed::append_back(current, separator), *first)
|
||||
);
|
||||
}
|
||||
template<typename Result, typename ContainerIterator, typename Separator>
|
||||
inline SPROUT_CONSTEXPR Result join2_impl(
|
||||
ContainerIterator first,
|
||||
ContainerIterator last,
|
||||
Separator const& separator
|
||||
)
|
||||
{
|
||||
return first != last
|
||||
? sprout::algorithm::detail::join2_impl_1<Result>(
|
||||
sprout::next(first),
|
||||
last,
|
||||
separator,
|
||||
*first
|
||||
)
|
||||
: sprout::make<Result>()
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// join2
|
||||
//
|
||||
template<typename ContainerContainer, typename Separator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join2<ContainerContainer, Separator>::type join2(
|
||||
ContainerContainer const& cont_cont,
|
||||
Separator const& separator
|
||||
)
|
||||
{
|
||||
return sprout::algorithm::detail::join2_impl<typename sprout::algorithm::result_of::join2<ContainerContainer, Separator>::type>(
|
||||
sprout::begin(cont_cont),
|
||||
sprout::end(cont_cont),
|
||||
separator
|
||||
);
|
||||
}
|
||||
} // namespace algorithm
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_STRING_JOIN2_HPP
|
|
@ -10,7 +10,8 @@ namespace sprout {
|
|||
// empty
|
||||
//
|
||||
template<typename Container>
|
||||
inline SPROUT_CONSTEXPR bool empty(Container const& cont) {
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
empty(Container const& cont) {
|
||||
return sprout::begin(cont) == sprout::end(cont);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -12,7 +12,8 @@ namespace sprout {
|
|||
// size
|
||||
//
|
||||
template<typename Container>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::difference_type size(Container const& cont) {
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::difference_type
|
||||
size(Container const& cont) {
|
||||
return NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::begin(cont), sprout::end(cont));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -179,4 +179,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_INTEGER_HPP
|
||||
|
||||
|
|
|
@ -63,4 +63,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_INTEGER_INTEGER_MASK_HPP
|
||||
|
||||
|
|
|
@ -5,4 +5,3 @@
|
|||
#include <sprout/functional/hash/hash.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HPP
|
||||
|
||||
|
|
|
@ -14,4 +14,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_ARRAY_HPP
|
||||
|
||||
|
|
|
@ -270,4 +270,3 @@ namespace sprout {
|
|||
} //namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_HPP
|
||||
|
||||
|
|
|
@ -33,4 +33,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_FWD_HPP
|
||||
|
||||
|
|
|
@ -14,4 +14,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_ARRAY_HPP
|
||||
|
||||
|
|
|
@ -6,4 +6,3 @@
|
|||
#include <sprout/string/hash.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_STRING_HPP
|
||||
|
||||
|
|
|
@ -14,4 +14,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_SUB_ARRAY_HPP
|
||||
|
||||
|
|
|
@ -5,4 +5,3 @@
|
|||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_FWD_HPP
|
||||
|
||||
|
|
447
sprout/iterator/size_enum_iterator.hpp
Normal file
447
sprout/iterator/size_enum_iterator.hpp
Normal file
|
@ -0,0 +1,447 @@
|
|||
#ifndef SPROUT_ITERATOR_SIZE_ENUM_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_SIZE_ENUM_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/container/size.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// size_enum_iterator
|
||||
//
|
||||
template<typename Iterator, bool Separated = false>
|
||||
class size_enum_iterator
|
||||
: public std::iterator<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type*,
|
||||
typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef Iterator iterator_type;
|
||||
typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category;
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type value_type;
|
||||
typedef value_type reference;
|
||||
typedef typename std::iterator_traits<iterator_type>::difference_type difference_type;
|
||||
typedef value_type* pointer;
|
||||
protected:
|
||||
iterator_type current;
|
||||
public:
|
||||
size_enum_iterator() = default;
|
||||
size_enum_iterator(size_enum_iterator const&) = default;
|
||||
explicit SPROUT_CONSTEXPR size_enum_iterator(iterator_type it)
|
||||
: current(it)
|
||||
{}
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR size_enum_iterator(size_enum_iterator<U> const& it)
|
||||
: current(it.current)
|
||||
{}
|
||||
template<typename U>
|
||||
size_enum_iterator& operator=(size_enum_iterator<U> const& it) {
|
||||
size_enum_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_separator() const {
|
||||
return false;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return sprout::size(*current);
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &sprout::size(*current);
|
||||
}
|
||||
size_enum_iterator& operator++() {
|
||||
++current;
|
||||
return *this;
|
||||
}
|
||||
size_enum_iterator operator++(int) {
|
||||
size_enum_iterator result(*this);
|
||||
++current;
|
||||
return result;
|
||||
}
|
||||
size_enum_iterator& operator--() {
|
||||
--current;
|
||||
return *this;
|
||||
}
|
||||
size_enum_iterator operator--(int) {
|
||||
size_enum_iterator temp(*this);
|
||||
--current;
|
||||
return temp;
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator operator+(difference_type n) const {
|
||||
return size_enum_iterator(current + n);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator operator-(difference_type n) const {
|
||||
return size_enum_iterator(current - n);
|
||||
}
|
||||
size_enum_iterator& operator+=(difference_type n) {
|
||||
size_enum_iterator temp(current + n);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
size_enum_iterator& operator-=(difference_type n) {
|
||||
size_enum_iterator temp(current - n);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
||||
return sprout::size(current[n]);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator next() const {
|
||||
return size_enum_iterator(sprout::next(current));
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator prev() const {
|
||||
return size_enum_iterator(sprout::prev(current));
|
||||
}
|
||||
void swap(size_enum_iterator& other) {
|
||||
using std::swap;
|
||||
swap(current, other.current);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// size_enum_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
class size_enum_iterator<Iterator, true>
|
||||
: public std::iterator<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type*,
|
||||
typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef Iterator iterator_type;
|
||||
typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category;
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>::difference_type value_type;
|
||||
typedef value_type reference;
|
||||
typedef typename std::iterator_traits<iterator_type>::difference_type difference_type;
|
||||
typedef value_type* pointer;
|
||||
protected:
|
||||
iterator_type current;
|
||||
value_type sep_size;
|
||||
bool is_sep;
|
||||
public:
|
||||
size_enum_iterator() = default;
|
||||
size_enum_iterator(size_enum_iterator const&) = default;
|
||||
explicit SPROUT_CONSTEXPR size_enum_iterator(iterator_type it, value_type size = 0, bool sep = false)
|
||||
: current(it)
|
||||
, sep_size(size)
|
||||
, is_sep(sep)
|
||||
{}
|
||||
template<typename U, bool V>
|
||||
SPROUT_CONSTEXPR size_enum_iterator(size_enum_iterator<U, V> const& it)
|
||||
: current(it.current)
|
||||
, sep_size(it.sep_size)
|
||||
, is_sep(it.is_sep)
|
||||
{}
|
||||
template<typename U, bool V>
|
||||
size_enum_iterator& operator=(size_enum_iterator<U, V> const& it) {
|
||||
size_enum_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type separator_size() const {
|
||||
return sep_size;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_separator() const {
|
||||
return is_sep;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return is_sep ? sep_size : sprout::size(*current);
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &(is_sep ? sep_size : sprout::size(*current));
|
||||
}
|
||||
size_enum_iterator& operator++() {
|
||||
if (is_sep) {
|
||||
++current;
|
||||
is_sep = false;
|
||||
} else {
|
||||
is_sep = true;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
size_enum_iterator operator++(int) {
|
||||
size_enum_iterator result(*this);
|
||||
if (is_sep) {
|
||||
++current;
|
||||
is_sep = false;
|
||||
} else {
|
||||
is_sep = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
size_enum_iterator& operator--() {
|
||||
if (is_sep) {
|
||||
is_sep = false;
|
||||
} else {
|
||||
--current;
|
||||
is_sep = true;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
size_enum_iterator operator--(int) {
|
||||
size_enum_iterator temp(*this);
|
||||
if (is_sep) {
|
||||
is_sep = false;
|
||||
} else {
|
||||
--current;
|
||||
is_sep = true;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator operator+(difference_type n) const {
|
||||
return size_enum_iterator(current + (n + is_sep) / 2, sep_size, (n + is_sep) % 2);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator operator-(difference_type n) const {
|
||||
return size_enum_iterator(current - (n - is_sep) / 2, sep_size, (n - is_sep) % 2);
|
||||
}
|
||||
size_enum_iterator& operator+=(difference_type n) {
|
||||
size_enum_iterator temp(current + (n + is_sep) / 2, sep_size, (n + is_sep) % 2);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
size_enum_iterator& operator-=(difference_type n) {
|
||||
size_enum_iterator temp(current - (n - is_sep) / 2, sep_size, (n - is_sep) % 2);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
||||
return sprout::size(current[(n + is_sep) / 2]);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator next() const {
|
||||
return is_sep
|
||||
? size_enum_iterator(sprout::next(current), sep_size, false)
|
||||
: size_enum_iterator(current, sep_size, true)
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR size_enum_iterator prev() const {
|
||||
return is_sep
|
||||
? size_enum_iterator(current, sep_size, false)
|
||||
: size_enum_iterator(sprout::prev(current), sep_size, true)
|
||||
;
|
||||
}
|
||||
void swap(size_enum_iterator& other) {
|
||||
using std::swap;
|
||||
swap(current, other.current);
|
||||
swap(sep_size, other.sep_size);
|
||||
swap(is_sep, other.is_sep);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename Iterator1, bool Separated1,
|
||||
typename Iterator2, bool Separated2
|
||||
>
|
||||
SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::size_enum_iterator<Iterator1, Separated1> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2, Separated2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base() && lhs.is_separator() == rhs.is_separator();
|
||||
}
|
||||
template<
|
||||
typename Iterator1, bool Separated1,
|
||||
typename Iterator2, bool Separated2
|
||||
>
|
||||
SPROUT_CONSTEXPR bool operator!=(
|
||||
sprout::size_enum_iterator<Iterator1, Separated1> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2, Separated2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<
|
||||
typename Iterator1, bool Separated1,
|
||||
typename Iterator2, bool Separated2
|
||||
>
|
||||
SPROUT_CONSTEXPR bool operator<(
|
||||
sprout::size_enum_iterator<Iterator1, Separated1> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2, Separated2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() < rhs.base()
|
||||
|| (lhs.base() == rhs.base() && !lhs.is_separator() && rhs.is_separator())
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename Iterator1, bool Separated1,
|
||||
typename Iterator2, bool Separated2
|
||||
>
|
||||
SPROUT_CONSTEXPR bool operator>(
|
||||
sprout::size_enum_iterator<Iterator1, Separated1> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2, Separated2> const& rhs
|
||||
)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<
|
||||
typename Iterator1, bool Separated1,
|
||||
typename Iterator2, bool Separated2
|
||||
>
|
||||
SPROUT_CONSTEXPR bool operator<=(
|
||||
sprout::size_enum_iterator<Iterator1, Separated1> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2, Separated2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<
|
||||
typename Iterator1, bool Separated1,
|
||||
typename Iterator2, bool Separated2
|
||||
>
|
||||
SPROUT_CONSTEXPR bool operator>=(
|
||||
sprout::size_enum_iterator<Iterator1, Separated1> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2, Separated2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2>
|
||||
SPROUT_CONSTEXPR decltype(std::declval<Iterator1>() - std::declval<Iterator2>()) operator-(
|
||||
sprout::size_enum_iterator<Iterator1> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() - rhs.base();
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2>
|
||||
SPROUT_CONSTEXPR decltype(std::declval<Iterator1>() - std::declval<Iterator2>()) operator-(
|
||||
sprout::size_enum_iterator<Iterator1, true> const& lhs,
|
||||
sprout::size_enum_iterator<Iterator2, true> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() - rhs.base() + (
|
||||
lhs.is_separator()
|
||||
? rhs.is_separator() ? 0 : -1
|
||||
: rhs.is_separator() ? 1 : 0
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Iterator, bool Separated>
|
||||
SPROUT_CONSTEXPR sprout::size_enum_iterator<Iterator, Separated> operator+(
|
||||
typename sprout::size_enum_iterator<Iterator, Separated>::difference_type n,
|
||||
sprout::size_enum_iterator<Iterator, Separated> const& it
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// make_size_enum_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR sprout::size_enum_iterator<Iterator>
|
||||
make_size_enum_iterator(Iterator it) {
|
||||
return sprout::size_enum_iterator<Iterator>(it);
|
||||
}
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR sprout::size_enum_iterator<Iterator, true>
|
||||
make_size_enum_iterator(
|
||||
Iterator it,
|
||||
typename sprout::size_enum_iterator<Iterator, true>::value_type sep_size,
|
||||
bool sep = false
|
||||
)
|
||||
{
|
||||
return sprout::size_enum_iterator<Iterator, true>(it, sep_size, sep);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename Iterator, bool Separated>
|
||||
void swap(
|
||||
sprout::size_enum_iterator<Iterator, Separated>& lhs,
|
||||
sprout::size_enum_iterator<Iterator, Separated>& rhs
|
||||
)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// next
|
||||
//
|
||||
template<typename Iterator, bool Separated>
|
||||
SPROUT_CONSTEXPR sprout::size_enum_iterator<Iterator, Separated> next(
|
||||
sprout::size_enum_iterator<Iterator, Separated> const& it
|
||||
)
|
||||
{
|
||||
return it.next();
|
||||
}
|
||||
template<typename Iterator, bool Separated>
|
||||
SPROUT_CONSTEXPR sprout::size_enum_iterator<Iterator, Separated> next(
|
||||
sprout::size_enum_iterator<Iterator, Separated> const& it,
|
||||
typename sprout::size_enum_iterator<Iterator, Separated>::difference_type n
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// prev
|
||||
//
|
||||
template<typename Iterator, bool Separated>
|
||||
SPROUT_CONSTEXPR sprout::size_enum_iterator<Iterator, Separated> prev(
|
||||
sprout::size_enum_iterator<Iterator, Separated> const& it
|
||||
)
|
||||
{
|
||||
return it.prev();
|
||||
}
|
||||
template<typename Iterator, bool Separated>
|
||||
SPROUT_CONSTEXPR sprout::size_enum_iterator<Iterator, Separated> prev(
|
||||
sprout::size_enum_iterator<Iterator, Separated> const& it,
|
||||
typename sprout::size_enum_iterator<Iterator, Separated>::difference_type n
|
||||
)
|
||||
{
|
||||
return it - n;
|
||||
}
|
||||
|
||||
//
|
||||
// distance
|
||||
//
|
||||
template<typename Iterator, bool Separated>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<sprout::size_enum_iterator<Iterator, Separated> >::difference_type
|
||||
distance(
|
||||
sprout::size_enum_iterator<Iterator, Separated> first,
|
||||
sprout::size_enum_iterator<Iterator, Separated> last
|
||||
)
|
||||
{
|
||||
return last - first;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_SIZE_ENUM_ITERATOR_HPP
|
143
sprout/iterator/traits.hpp
Normal file
143
sprout/iterator/traits.hpp
Normal file
|
@ -0,0 +1,143 @@
|
|||
#ifndef SPROUT_ITERATOR_TRAITS_HPP
|
||||
#define SPROUT_ITERATOR_TRAITS_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
// has_iterator_category
|
||||
SPROUT_HAS_XXX_TYPE_DEF_LAZY(iterator_category);
|
||||
} // namespace detail
|
||||
//
|
||||
// is_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_iterator
|
||||
: sprout::detail::has_iterator_category<std::iterator_traits<Iterator> >
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_input_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_input_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::input_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_input_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_input_iterator
|
||||
: sprout::detail::is_input_iterator_impl<Iterator>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_output_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_output_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::output_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_output_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_output_iterator
|
||||
: sprout::detail::is_output_iterator_impl<Iterator>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_forward_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_forward_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::forward_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_forward_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_forward_iterator
|
||||
: sprout::detail::is_forward_iterator_impl<Iterator>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_bidirectional_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_bidirectional_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::bidirectional_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_bidirectional_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_bidirectional_iterator
|
||||
: sprout::detail::is_bidirectional_iterator_impl<Iterator>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_random_access_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_random_access_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::random_access_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_random_access_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_random_access_iterator
|
||||
: sprout::detail::is_random_access_iterator_impl<Iterator>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_TRAITS_HPP
|
|
@ -5,4 +5,3 @@
|
|||
#include <sprout/numeric/fft/bitrev_table.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_FFT_HPP
|
||||
|
||||
|
|
|
@ -10,4 +10,3 @@
|
|||
#define SPROUT_PP_CAT_I(a, b) a ## b
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_CAT_HPP
|
||||
|
||||
|
|
|
@ -9,4 +9,3 @@
|
|||
#define SPROUT_PP_EMPTY()
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_EMPTY_HPP
|
||||
|
||||
|
|
|
@ -7,4 +7,3 @@
|
|||
#include <sprout/preprocessor/u32str.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_STR_ALL_HPP
|
||||
|
||||
|
|
|
@ -10,4 +10,3 @@
|
|||
#define SPROUT_PP_STRINGIZE_I(text) #text
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_STRINGIZE_HPP
|
||||
|
||||
|
|
|
@ -8,4 +8,3 @@
|
|||
#include <sprout/preprocessor/u32stringize.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_STRINGIZE_ALL_HPP
|
||||
|
||||
|
|
|
@ -10,4 +10,3 @@
|
|||
#define SPROUT_PP_U16STR_I(str) u ## str
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_U16STR_HPP
|
||||
|
||||
|
|
|
@ -11,4 +11,3 @@
|
|||
#define SPROUT_PP_U16STRINGIZE_II(str) u ## str
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_U16STRINGIZE_HPP
|
||||
|
||||
|
|
|
@ -10,4 +10,3 @@
|
|||
#define SPROUT_PP_U32STR_I(str) U ## str
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_U32STR_HPP
|
||||
|
||||
|
|
|
@ -11,4 +11,3 @@
|
|||
#define SPROUT_PP_U32STRINGIZE_II(str) U ## str
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_U32STRINGIZE_HPP
|
||||
|
||||
|
|
|
@ -20,4 +20,3 @@
|
|||
SPROUT_PP_U32STR(" : ") SPROUT_PP_U32STR(__FILE__) SPROUT_PP_U32STR(":") SPROUT_PP_U32STRINGIZE(__LINE__)
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_UNIQUE_STRING_HPP
|
||||
|
||||
|
|
|
@ -10,4 +10,3 @@
|
|||
#define SPROUT_PP_WSTR_I(str) L ## str
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_WSTR_HPP
|
||||
|
||||
|
|
|
@ -11,4 +11,3 @@
|
|||
#define SPROUT_PP_WSTRINGIZE_II(str) L ## str
|
||||
|
||||
#endif // #ifndef SPROUT_PREPROCESSOR_WSTRINGIZE_HPP
|
||||
|
||||
|
|
|
@ -159,4 +159,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP
|
||||
|
||||
|
|
|
@ -447,4 +447,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_BINOMIAL_DISTRIBUTION_HPP
|
||||
|
||||
|
|
|
@ -131,4 +131,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_DETAIL_CONST_MOD_HPP
|
||||
|
||||
|
|
|
@ -20,4 +20,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_DETAIL_GENERATOR_BITS_HPP
|
||||
|
||||
|
|
|
@ -70,4 +70,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_DETAIL_PTR_HELPER_HPP
|
||||
|
||||
|
|
|
@ -60,4 +60,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // SPROUT_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS_HPP
|
||||
|
||||
|
|
|
@ -71,4 +71,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
|
||||
|
||||
|
|
|
@ -466,4 +466,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_MERSENNE_TWISTER_HPP
|
||||
|
||||
|
|
|
@ -323,4 +323,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_RANDOM_ITERATOR_HPP
|
||||
|
||||
|
|
|
@ -260,4 +260,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_RANDOM_RESULT_HPP
|
||||
|
||||
|
|
|
@ -129,4 +129,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_UNIFORM_01_HPP
|
||||
|
||||
|
|
|
@ -543,4 +543,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
|
||||
|
||||
|
|
|
@ -335,4 +335,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
|
||||
|
||||
|
|
|
@ -271,4 +271,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_UNIFORM_SMALLINT_HPP
|
||||
|
||||
|
|
|
@ -53,4 +53,3 @@ namespace sprout {
|
|||
#define SPROUT_UNIQUE_SEED_SEQ(N) (::sprout::make_seed_seq<N>(SPROUT_PP_UNIQUE_STRING))
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_UNIQUE_SEED_HPP
|
||||
|
||||
|
|
|
@ -80,4 +80,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_VARIATE_GENERATOR_HPP
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/sinusoid_iterator.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
|
@ -33,7 +32,6 @@ namespace sprout {
|
|||
typedef sprout::range::range_container<
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
copied_range() = default;
|
||||
copied_range(copied_range const&) = default;
|
||||
|
@ -92,7 +90,7 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Result>
|
||||
SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<sprout::pit<Result> >::type
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<sprout::pit<Result> >::type
|
||||
operator|(Range&& lhs, sprout::adaptors::copy_holder<Result> const& rhs) {
|
||||
return sprout::range::fixed::copy(sprout::lvalue_forward<Range>(lhs), sprout::pit<Result>());
|
||||
}
|
||||
|
|
191
sprout/range/adaptor/size_enumed.hpp
Normal file
191
sprout/range/adaptor/size_enumed.hpp
Normal file
|
@ -0,0 +1,191 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_SIZE_ENUMED_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_SIZE_ENUMED_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/size_enum_iterator.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
//
|
||||
// size_enumed_range
|
||||
//
|
||||
template<typename Range, bool Separated = false>
|
||||
class size_enumed_range
|
||||
: public sprout::range::range_container<
|
||||
sprout::size_enum_iterator<
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
{
|
||||
public:
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<
|
||||
sprout::size_enum_iterator<
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
size_enumed_range() = default;
|
||||
size_enumed_range(size_enumed_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR size_enumed_range(range_type& range)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range)),
|
||||
iterator(sprout::end(range))
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
template<typename Range>
|
||||
class size_enumed_range<Range, true>
|
||||
: public sprout::range::range_container<
|
||||
sprout::size_enum_iterator<
|
||||
typename sprout::container_traits<Range>::iterator, true
|
||||
>
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
{
|
||||
public:
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<
|
||||
sprout::size_enum_iterator<
|
||||
typename sprout::container_traits<Range>::iterator, true
|
||||
>
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::value_type value_type;
|
||||
public:
|
||||
size_enumed_range() = default;
|
||||
size_enumed_range(size_enumed_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR size_enumed_range(
|
||||
range_type& range,
|
||||
value_type sep_size = 0,
|
||||
bool omit_last = false
|
||||
)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), sep_size),
|
||||
omit_last
|
||||
? sprout::empty(range)
|
||||
? iterator(sprout::end(range), sep_size)
|
||||
: iterator(sprout::prev(sprout::end(range)), sep_size, true)
|
||||
: iterator(sprout::end(range), sep_size)
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// size_enum_holder
|
||||
//
|
||||
template<typename Size>
|
||||
class size_enum_holder {
|
||||
public:
|
||||
typedef Size size_type;
|
||||
private:
|
||||
size_type sep_size_;
|
||||
bool omit_last_;
|
||||
public:
|
||||
size_enum_holder() = default;
|
||||
size_enum_holder(size_enum_holder const&) = default;
|
||||
explicit SPROUT_CONSTEXPR size_enum_holder(size_type size, bool omit_last = false)
|
||||
: sep_size_(size)
|
||||
, omit_last_(omit_last)
|
||||
{}
|
||||
SPROUT_CONSTEXPR size_type separator_size() const {
|
||||
return sep_size_;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool omit_last() const {
|
||||
return omit_last_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// size_enumed_forwarder
|
||||
//
|
||||
class size_enumed_forwarder {
|
||||
public:
|
||||
template<typename Size>
|
||||
SPROUT_CONSTEXPR typename sprout::adaptors::size_enum_holder<Size>
|
||||
operator()(Size size, bool omit_last = false) {
|
||||
return typename sprout::adaptors::size_enum_holder<Size>(size, omit_last);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// size_enumed
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::size_enumed_forwarder size_enumed{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename Size>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::size_enumed_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
||||
true
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::size_enum_holder<Size> const& rhs) {
|
||||
return sprout::adaptors::size_enumed_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
||||
true
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs),
|
||||
rhs.separator_size(),
|
||||
rhs.omit_last()
|
||||
);
|
||||
}
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::size_enumed_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::size_enumed_forwarder const& rhs) {
|
||||
return sprout::adaptors::size_enumed_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs)
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Range, bool Separated>
|
||||
struct container_construct_traits<sprout::adaptors::size_enumed_range<Range, Separated> > {
|
||||
public:
|
||||
typedef typename sprout::container_construct_traits<Range>::copied_type copied_type;
|
||||
public:
|
||||
template<typename Cont>
|
||||
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
|
||||
return sprout::range::fixed::copy(sprout::forward<Cont>(cont), sprout::pit<copied_type>());
|
||||
}
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
|
||||
return sprout::make<copied_type>(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename Cont, typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type remake(
|
||||
Cont&& cont,
|
||||
typename sprout::container_traits<sprout::adaptors::size_enumed_range<Range> >::difference_type size,
|
||||
Args&&... args
|
||||
)
|
||||
{
|
||||
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_SIZE_ENUMED_HPP
|
|
@ -45,8 +45,8 @@ namespace sprout {
|
|||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::size_type size_type;
|
||||
public:
|
||||
transformed_range() = default;
|
||||
transformed_range(transformed_range const&) = default;
|
||||
SPROUT_CONSTEXPR transformed_range() = default;
|
||||
SPROUT_CONSTEXPR transformed_range(transformed_range const&) = default;
|
||||
SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range1, range2_type& range2)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range1), sprout::begin(range2), func),
|
||||
|
@ -77,8 +77,8 @@ namespace sprout {
|
|||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
transformed_range() = default;
|
||||
transformed_range(transformed_range const&) = default;
|
||||
SPROUT_CONSTEXPR transformed_range() = default;
|
||||
SPROUT_CONSTEXPR transformed_range(transformed_range const&) = default;
|
||||
SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), func),
|
||||
|
|
|
@ -225,4 +225,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_INT_P_HPP
|
||||
|
||||
|
|
|
@ -201,4 +201,3 @@ namespace sprout {
|
|||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_UINT_P_HPP
|
||||
|
||||
|
|
|
@ -27,6 +27,22 @@ namespace sprout {
|
|||
: public sprout::weed::traits::is_c_str<T>
|
||||
{};
|
||||
template<std::size_t N>
|
||||
struct is_c_str<char[N]>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<std::size_t N>
|
||||
struct is_c_str<wchar_t[N]>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<std::size_t N>
|
||||
struct is_c_str<char16_t[N]>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<std::size_t N>
|
||||
struct is_c_str<char32_t[N]>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<std::size_t N>
|
||||
struct is_c_str<char const[N]>
|
||||
: public std::true_type
|
||||
{};
|
||||
|
|
Loading…
Add table
Reference in a new issue