1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-02-04 21:33:56 +00:00

add type_traits is_swappable, conjunction, disjunction, negation

This commit is contained in:
bolero-MURAKAMI 2016-04-05 02:49:50 +09:00
parent 913dc8ca44
commit aa8e265188
18 changed files with 323 additions and 10 deletions

View file

@ -9,8 +9,8 @@
#define SPROUT_CONTAINER_STD_COMPLEX_HPP
#include <complex>
#include <type_traits>
#include <stdexcept>
#include <type_traits>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/container/traits.hpp>
@ -25,7 +25,7 @@ namespace sprout {
operator()(Complex const& c, Index i) const {
return i == 0 ? c.real()
: i == 1 ? c.imag()
: throw std::out_of_range("std_complex_at<>: index out of range")
: throw std::out_of_range("std_complex_at: index out of range")
;
}
};

View file

@ -13,6 +13,7 @@
#include <cstdlib>
#include <functional>
#include <stdexcept>
#include <type_traits>
#include <tuple>
#include <sprout/config.hpp>
@ -29,7 +30,6 @@
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
#include <sprout/detail/static_size.hpp>
#include <sprout/assert.hpp>
namespace sprout {
//
@ -348,7 +348,7 @@ namespace sprout {
{
return i == 0 ? d.quot
: i == 1 ? d.rem
: (SPROUT_ASSERT(i < 2), d.quot)
: (throw std::out_of_range("div_at: index out of range"), d.quot)
;
}
template<typename Div>
@ -358,7 +358,7 @@ namespace sprout {
{
return i == 0 ? d.quot
: i == 1 ? d.rem
: (SPROUT_ASSERT(i < 2), d.quot)
: (throw std::out_of_range("div_at: index out of range"), d.quot)
;
}

View file

@ -21,7 +21,7 @@ namespace sprout {
template<typename Message>
static void warn() {}
};
template <>
template<>
struct static_warning<false> {
template<typename Message>
static void warn() {

View file

@ -38,7 +38,7 @@ namespace sprout {
: public sprout::detail::undecayed_common_type_impl<void, typename sprout::detail::undecayed_common_type2<T1, T2>::type, Tail...>
{};
} // namespace detail
template <typename... Types>
template<typename... Types>
struct undecayed_common_type
: public sprout::detail::undecayed_common_type_impl<void, Types...>
{};
@ -58,7 +58,7 @@ namespace sprout {
: public std::decay<typename CommonType::type>
{};
} // namespace detail
template <typename... Types>
template<typename... Types>
struct common_type
: public sprout::detail::common_type_impl<sprout::undecayed_common_type<Types...> >
{};

View file

@ -0,0 +1,29 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_CONJUNCTION_HPP
#define SPROUT_TYPE_TRAITS_CONJUNCTION_HPP
#include <sprout/config.hpp>
#include <sprout/tpp/algorithm/all_of.hpp>
namespace sprout {
//
// conjunction
//
template<typename... Types>
struct conjunction
: public sprout::tpp::all_of<Types...>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename... Types>
SPROUT_STATIC_CONSTEXPR bool conjunction_v = sprout::conjunction<Types...>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_CONJUNCTION_HPP

View file

@ -0,0 +1,29 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_DISJUNCTION_HPP
#define SPROUT_TYPE_TRAITS_DISJUNCTION_HPP
#include <sprout/config.hpp>
#include <sprout/tpp/algorithm/any_of.hpp>
namespace sprout {
//
// disjunction
//
template<typename... Types>
struct disjunction
: public sprout::tpp::any_of<Types...>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename... Types>
SPROUT_STATIC_CONSTEXPR bool disjunction_v = sprout::disjunction<Types...>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_DISJUNCTION_HPP

View file

@ -19,6 +19,11 @@ namespace sprout {
public:
typedef R type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename R = void>
using enable_if_has_type_t = typename sprout::enable_if_has_type<T, R>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_ENABLE_IF_HAS_TYPE_HPP

View file

@ -0,0 +1,29 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP
#define SPROUT_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/is_nothrow_swappable_with.hpp>
namespace sprout {
//
// is_nothrow_swappable
//
template<typename T>
struct is_nothrow_swappable
: public sprout::is_nothrow_swappable_with<T&, T&>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_nothrow_swappable_v = sprout::is_nothrow_swappable<T>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP

View file

@ -0,0 +1,53 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_WITH_HPP
#define SPROUT_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_WITH_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/is_swappable_with.hpp>
namespace sprout_nothrow_swappable_detail {
using std::swap;
template<typename T, typename U>
struct is_nothrow_swappable_with
: public sprout::bool_constant<
SPROUT_NOEXCEPT_EXPR(swap(std::declval<T>(), std::declval<U>()))
&& SPROUT_NOEXCEPT_EXPR(swap(std::declval<U>(), std::declval<T>()))
>::type
{};
} // namespace sprout_nothrow_swappable_detail
namespace sprout {
namespace detail {
template<typename T, typename U, bool = false>
struct is_nothrow_swappable_with_impl
: public sprout::false_type
{};
template<typename T, typename U>
struct is_nothrow_swappable_with_impl<T, U, true>
: public sprout_nothrow_swappable_detail::is_nothrow_swappable_with<T, U>
{};
} // namespace detail
//
// is_nothrow_swappable_with
//
template<typename T, typename U>
struct is_nothrow_swappable_with
: public sprout::detail::is_nothrow_swappable_with_impl<T, U, sprout::is_swappable_with<T, U>::value>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T, typename U>
SPROUT_STATIC_CONSTEXPR bool is_nothrow_swappable_with_v = sprout::is_nothrow_swappable_with<T>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_WITH_HPP

View file

@ -27,7 +27,7 @@ namespace sprout {
: public sprout::detail::type_traits_wrapper<std::is_signed<T> >
{};
} // namespace detail
template <typename T>
template<typename T>
struct is_signed
: public sprout::detail::is_signed_impl<T>
{};

View file

@ -0,0 +1,29 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_IS_SWAPPABLE_HPP
#define SPROUT_TYPE_TRAITS_IS_SWAPPABLE_WITH_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/is_swappable_with.hpp>
namespace sprout {
//
// is_swappable
//
template<typename T>
struct is_swappable
: public sprout::is_swappable_with<T&, T&>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_swappable_v = sprout::is_swappable<T>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_SWAPPABLE_HPP

View file

@ -0,0 +1,58 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_IS_SWAPPABLE_WITH_HPP
#define SPROUT_TYPE_TRAITS_IS_SWAPPABLE_WITH_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout_swappable_detail {
using std::swap;
template<typename T, typename U>
struct is_swappable_with_test {
public:
template<
typename T1 = T, typename U1 = U,
typename = typename sprout::identity<decltype(swap(std::declval<T1>(), std::declval<U1>()))>::type,
typename = typename sprout::identity<decltype(swap(std::declval<U1>(), std::declval<T1>()))>::type
>
static sprout::true_type test(int);
static sprout::false_type test(...);
};
#if defined(_MSC_VER) && (_MSC_VER > 1900)
template<typename T, typename U, typename Base_ = typename sprout::identity<decltype(sprout_swappable_detail::is_swappable_with_test<T, U>::test(0))>::type>
struct is_swappable_with
: public Base_
{};
#else
template<typename T, typename U>
struct is_swappable_with
: public sprout::identity<decltype(sprout_swappable_detail::is_swappable_with_test<T, U>::test(0))>::type
{};
#endif
} // namespace sprout_swappable_detail
namespace sprout {
//
// is_swappable_with
//
template<typename T, typename U>
struct is_swappable_with
: public sprout_swappable_detail::is_swappable_with<T, U>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T, typename U>
SPROUT_STATIC_CONSTEXPR bool is_swappable_with_v = sprout::is_swappable_with<T>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_SWAPPABLE_WITH_HPP

View file

@ -27,7 +27,7 @@ namespace sprout {
: public sprout::detail::type_traits_wrapper<std::is_unsigned<T> >
{};
} // namespace detail
template <typename T>
template<typename T>
struct is_unsigned
: public sprout::detail::is_unsigned_impl<T>
{};

View file

@ -0,0 +1,17 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_LOGICAL_HPP
#define SPROUT_TYPE_TRAITS_LOGICAL_HPP
#include <sprout/config.hpp>
// logical operator traits:
#include <sprout/type_traits/conjunction.hpp>
#include <sprout/type_traits/disjunction.hpp>
#include <sprout/type_traits/negation.hpp>
#endif // #ifndef SPROUT_TYPE_TRAITS_LOGICAL_HPP

View file

@ -0,0 +1,29 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_NEGATION_HPP
#define SPROUT_TYPE_TRAITS_NEGATION_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
namespace sprout {
//
// negation
//
template<typename T>
struct negation
: public sprout::bool_constant<!T::value>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T>
SPROUT_STATIC_CONSTEXPR bool negation_v = sprout::negation<T>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_NEGATION_HPP

View file

@ -30,6 +30,8 @@
#include <sprout/type_traits/is_assignable.hpp>
#include <sprout/type_traits/is_copy_assignable.hpp>
#include <sprout/type_traits/is_move_assignable.hpp>
#include <sprout/type_traits/is_swappable_with.hpp>
#include <sprout/type_traits/is_swappable.hpp>
#include <sprout/type_traits/is_destructible.hpp>
#include <sprout/type_traits/is_trivially_constructible.hpp>
#include <sprout/type_traits/is_trivially_default_constructible.hpp>
@ -46,6 +48,8 @@
#include <sprout/type_traits/is_nothrow_assignable.hpp>
#include <sprout/type_traits/is_nothrow_copy_assignable.hpp>
#include <sprout/type_traits/is_nothrow_move_assignable.hpp>
#include <sprout/type_traits/is_nothrow_swappable_with.hpp>
#include <sprout/type_traits/is_nothrow_swappable.hpp>
#include <sprout/type_traits/is_nothrow_destructible.hpp>
#include <sprout/type_traits/has_virtual_destructor.hpp>

View file

@ -21,5 +21,7 @@
#include <sprout/type_traits/array_modification.hpp>
#include <sprout/type_traits/pointer_modification.hpp>
#include <sprout/type_traits/transformation.hpp>
#include <sprout/type_traits/logical.hpp>
#include <sprout/type_traits/voider.hpp>
#endif // #ifndef SPROUT_TYPE_TRAITS_STD_TYPE_TRAITS_HPP

View file

@ -0,0 +1,29 @@
/*=============================================================================
Copyright (c) 2011-2016 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_TYPE_TRAITS_VOIDER_HPP
#define SPROUT_TYPE_TRAITS_VOIDER_HPP
#include <sprout/config.hpp>
namespace sprout {
//
// voider
//
template<typename...>
struct voider {
public:
typedef void type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename...>
using void_t = void;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_VOIDER_HPP