2011-11-04 13:17:25 +00:00
|
|
|
#ifndef SPROUT_ALGORITHM_STRING_JOIN2_HPP
|
|
|
|
#define SPROUT_ALGORITHM_STRING_JOIN2_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
2011-11-04 13:17:25 +00:00
|
|
|
#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:
|
2012-03-31 07:24:13 +00:00
|
|
|
typedef typename sprout::container_transform_traits<
|
|
|
|
typename sprout::container_traits<ContainerContainer>::value_type
|
|
|
|
>::template rebind_size<
|
|
|
|
sprout::container_traits<ContainerContainer>::static_size != 0
|
2011-11-04 13:17:25 +00:00
|
|
|
? (
|
2012-03-31 07:24:13 +00:00
|
|
|
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
|
2011-11-04 13:17:25 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
: 0
|
|
|
|
>::type type;
|
|
|
|
};
|
|
|
|
} // namespace result_of
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename Result, typename ContainerIterator, typename Separator, typename Container>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
(sprout::container_traits<Container>::static_size == sprout::container_traits<Result>::static_size),
|
2011-11-04 13:17:25 +00:00
|
|
|
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>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
(sprout::container_traits<Container>::static_size < sprout::container_traits<Result>::static_size),
|
2011-11-04 13:17:25 +00:00
|
|
|
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>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR Result join2_impl(
|
2011-11-04 13:17:25 +00:00
|
|
|
ContainerIterator first,
|
|
|
|
ContainerIterator last,
|
|
|
|
Separator const& separator
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return first != last
|
|
|
|
? sprout::algorithm::detail::join2_impl_1<Result>(
|
|
|
|
sprout::next(first),
|
|
|
|
last,
|
|
|
|
separator,
|
|
|
|
*first
|
|
|
|
)
|
2012-03-31 07:24:13 +00:00
|
|
|
: sprout::make<Result>()
|
2011-11-04 13:17:25 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// join2
|
|
|
|
//
|
|
|
|
template<typename ContainerContainer, typename Separator>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::algorithm::result_of::join2<ContainerContainer, Separator>::type join2(
|
2011-11-04 13:17:25 +00:00
|
|
|
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
|