1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/weed/attr_cnv/shift_left.hpp

133 lines
5.6 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
Copyright (c) 2011-2019 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
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)
=============================================================================*/
2011-11-13 08:54:38 +00:00
#ifndef SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP
#define SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/operation/fixed/append_back.hpp>
#include <sprout/operation/fixed/push_back.hpp>
#include <sprout/operation/fixed/push_front.hpp>
#include <sprout/tuple/operation/append_back.hpp>
#include <sprout/tuple/operation/push_back.hpp>
#include <sprout/tuple/operation/push_front.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_tuple_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_tuple.hpp>
#include <sprout/weed/detail/is_same_elem.hpp>
#include <sprout/weed/detail/is_different_elem.hpp>
#include <sprout/weed/detail/is_elem_and_unused.hpp>
#include <sprout/weed/detail/is_unused_and_elem.hpp>
#include <sprout/weed/detail/is_both_unused.hpp>
#include <sprout/weed/attr_cnv/results/shift_left.hpp>
2011-11-13 08:54:38 +00:00
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// shift_left
//
// container<V, N> >> container<V, M> -> container<V, N + M>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_same_container<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
return sprout::fixed::append_back(t, u);
}
// container<V, N> >> V -> container<V, N + 1>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_container_and_elem<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
return sprout::fixed::push_back(t, u);
}
// V >> container<V, N> -> container<V, N + 1>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_elem_and_container<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
2013-06-26 15:36:17 +00:00
return sprout::fixed::push_front(u, t);
2011-11-13 08:54:38 +00:00
}
// tuple<Vs...> >> tuple<Ws...> -> tuple<Vs..., Ws...>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_both_tuple<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
return sprout::tuples::append_back(t, u);
}
// tuple<Vs...> >> V -> tuple<Vs..., V>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_tuple_and_elem<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
return sprout::tuples::push_back(t, u);
}
// V >> tuple<Vs...> -> tuple<V, Vs...>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_elem_and_tuple<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
2013-06-26 15:36:17 +00:00
return sprout::tuples::push_front(u, t);
2011-11-13 08:54:38 +00:00
}
// V >> V -> container<V, 2>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_same_elem<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
typedef typename sprout::weed::attr_cnv::results::shift_left<T, U>::type type;
return sprout::make<type>(t, u);
2011-11-13 08:54:38 +00:00
}
// V >> W -> tuple<V, W>
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_different_elem<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2011-11-13 08:54:38 +00:00
>::type shift_left(T const& t, U const& u) {
return typename sprout::weed::attr_cnv::results::shift_left<T, U>::type(t, u);
2011-11-13 08:54:38 +00:00
}
// V >> unused -> V
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_elem_and_unused<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2013-07-22 13:00:09 +00:00
>::type shift_left(T const& t, U const&) {
2011-11-13 08:54:38 +00:00
return t;
}
// unused >> V -> V
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_unused_and_elem<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2013-07-22 13:00:09 +00:00
>::type shift_left(T const&, U const& u) {
2011-11-13 08:54:38 +00:00
return u;
}
// unused >> unused -> unused
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename std::enable_if<
2011-11-13 08:54:38 +00:00
sprout::weed::detail::is_both_unused<T, U>::value,
typename sprout::weed::attr_cnv::results::shift_left<T, U>::type
2013-07-22 13:00:09 +00:00
>::type shift_left(T const&, U const&) {
2011-11-13 08:54:38 +00:00
return sprout::weed::unused();
}
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP