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/bitwise_or.hpp

158 lines
7.1 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2014-01-08 07:48:12 +00:00
Copyright (c) 2011-2014 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_BITWISE_OR_HPP
#define SPROUT_WEED_ATTR_CNV_BITWISE_OR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/make.hpp>
2011-11-13 08:54:38 +00:00
#include <sprout/operation/fixed/realign_to.hpp>
#include <sprout/tuple/algorithm/copy.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_container.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_same_elem.hpp>
#include <sprout/weed/detail/is_different_elem.hpp>
2011-11-13 08:54:38 +00:00
#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/bitwise_or.hpp>
2011-11-13 08:54:38 +00:00
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// bitwise_or
//
// container<V, N> | container<V, M> -> container<V, max(N, M)>
template<typename T, typename U, typename X>
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::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
2011-11-13 08:54:38 +00:00
return sprout::fixed::realign_to<type>(x);
}
// container<V, N> | V -> container<V, N ? N : 1>
template<typename T, typename U, typename X>
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
&& sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
2011-11-13 08:54:38 +00:00
return sprout::fixed::realign_to<type>(x);
}
template<typename T, typename U, typename X>
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
&& !sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
return sprout::make<type>(x);
2011-11-13 08:54:38 +00:00
}
// V | container<V, N> -> container<V, N ? N : 1>
template<typename T, typename U, typename X>
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
&& sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
2011-11-13 08:54:38 +00:00
return sprout::fixed::realign_to<type>(x);
}
template<typename T, typename U, typename X>
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
&& !sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
return sprout::make<type>(x);
2011-11-13 08:54:38 +00:00
}
// tuple<Vs...> | tuple<Ws...> -> tuple<max(Vs..., Ws...)>
template<typename T, typename U, typename X>
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::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
2011-11-13 08:54:38 +00:00
return sprout::tuples::copy(type(), x);
}
// V | V -> V
template<typename T, typename U, typename X>
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::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
return x;
}
// V | W -> variant<V, W>
template<typename T, typename U, typename X>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::weed::detail::is_different_elem<T, U>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
return typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type(x);
}
2011-11-13 08:54:38 +00:00
// V | unused -> container<V, 1>
template<typename T, typename U, typename X>
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
&& !sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
return sprout::make<type>(x);
2011-11-13 08:54:38 +00:00
}
template<typename T, typename U, typename X>
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
&& sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2013-07-22 13:00:09 +00:00
>::type bitwise_or(X const&) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
return sprout::make<type>();
2011-11-13 08:54:38 +00:00
}
// unused | V -> container<V, 1>
template<typename T, typename U, typename X>
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
&& !sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2011-11-13 08:54:38 +00:00
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
return sprout::make<type>(x);
2011-11-13 08:54:38 +00:00
}
template<typename T, typename U, typename X>
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
&& sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type
2013-07-22 13:00:09 +00:00
>::type bitwise_or(X const&) {
typedef typename sprout::weed::attr_cnv::results::bitwise_or<T, U>::type type;
return sprout::make<type>();
2011-11-13 08:54:38 +00:00
}
// unused | unused -> unused
2011-11-13 08:54:38 +00:00
template<typename T, typename U, typename X>
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::bitwise_or<T, U>::type
2013-07-22 13:00:09 +00:00
>::type bitwise_or(X 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_BITWISE_OR_HPP