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/results/shift_left.hpp
2017-07-29 14:20:01 +09:00

175 lines
5.2 KiB
C++

/*=============================================================================
Copyright (c) 2011-2017 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_WEED_ATTR_CNV_RESULTS_SHIFT_LEFT_HPP
#define SPROUT_WEED_ATTR_CNV_RESULTS_SHIFT_LEFT_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/array/array.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/type_traits/identity.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_char_type.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>
namespace sprout {
namespace weed {
namespace attr_cnv {
namespace results {
//
// shift_left
//
template<typename T, typename U, typename = void>
struct shift_left;
// container<V, N> >> container<V, M> -> container<V, N + M>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_same_container<T, U>::value
>::type
>
: public sprout::fixed::results::append_back<T, U>
{};
// container<V, N> >> V -> container<V, N + 1>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_container_and_elem<T, U>::value
>::type
>
: public sprout::fixed::results::push_back<T, U>
{};
// V >> container<V, N> -> container<V, N + 1>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_container<T, U>::value
>::type
>
: public sprout::fixed::results::push_front<U, T>
{};
// tuple<Vs...> >> tuple<Ws...> -> tuple<Vs..., Ws...>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_both_tuple<T, U>::value
>::type
>
: public sprout::tuples::results::append_back<T, U>
{};
// tuple<Vs...> >> V -> tuple<Vs..., V>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_tuple_and_elem<T, U>::value
>::type
>
: public sprout::tuples::results::push_back<T, U>
{};
// V >> tuple<Vs...> -> tuple<V, Vs...>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_tuple<T, U>::value
>::type
>
: public sprout::tuples::results::push_front<U, T>
{};
// V >> V -> container<V, 2>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_same_elem<T, U>::value
>::type
>
: public std::conditional<
sprout::weed::traits::is_char_type<T>::value,
sprout::basic_string<T, 2>,
sprout::array<T, 2>
>
{};
// V >> W -> tuple<V, W>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_different_elem<T, U>::value
>::type
>
: public sprout::identity<sprout::tuples::tuple<T, U> >
{};
// V >> unused -> V
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_unused<T, U>::value
>::type
>
: public sprout::identity<T>
{};
// unused >> V -> V
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_unused_and_elem<T, U>::value
>::type
>
: public sprout::identity<U>
{};
// unused >> unused -> unused
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_both_unused<T, U>::value
>::type
>
: public sprout::identity<sprout::weed::unused>
{};
} // namespace results
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULTS_SHIFT_LEFT_HPP