Edit: /usr/include/boost/hana/intersperse.hpp (2586B)
/*!
@file
Defines `boost::hana::intersperse`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_INTERSPERSE_HPP
#define BOOST_HANA_INTERSPERSE_HPP
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
BOOST_HANA_NAMESPACE_BEGIN
//! @cond
template
constexpr auto intersperse_t::operator()(Xs&& xs, Z&& z) const {
using S = typename hana::tag_of::type;
using Intersperse = BOOST_HANA_DISPATCH_IF(intersperse_impl,
hana::Sequence::value
);
#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
static_assert(hana::Sequence::value,
"hana::intersperse(xs, z) requires 'xs' to be a Sequence");
#endif
return Intersperse::apply(static_cast(xs), static_cast(z));
}
//! @endcond
template
struct intersperse_impl> : default_ {
template
static constexpr decltype(auto)
pick(Xs&&, Z&& z, hana::false_ /* odd index */)
{ return static_cast(z); }
template
static constexpr decltype(auto)
pick(Xs&& xs, Z&&, hana::true_ /* even index */)
{ return hana::at_c<(i + 1) / 2>(static_cast(xs)); }
template
static constexpr auto
intersperse_helper(Xs&& xs, Z&& z, std::index_sequence) {
return hana::make(
pick(static_cast(xs), static_cast(z),
hana::bool_c<(i % 2 == 0)>)...
);
}
template
static constexpr auto apply(Xs&& xs, Z&& z) {
constexpr std::size_t size = decltype(hana::length(xs))::value;
constexpr std::size_t new_size = size == 0 ? 0 : (size * 2) - 1;
return intersperse_helper(static_cast(xs), static_cast(z),
std::make_index_sequence{});
}
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_INTERSPERSE_HPP