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

add rebind_type container metafunction

This commit is contained in:
bolero-MURAKAMI 2016-04-02 19:55:55 +09:00
parent 802f2fbaed
commit dd58135a93
7 changed files with 174 additions and 0 deletions

View file

@ -33,6 +33,19 @@ namespace sprout {
typedef Array<T, Size> type;
};
template<typename Container, typename Type>
struct default_array_rebind_type;
template<
template<typename, std::size_t> class Array,
typename T,
std::size_t N,
typename Type
>
struct default_array_rebind_type<Array<T, N>, Type> {
public:
typedef Array<Type, N> type;
};
template<typename Container, typename = void>
struct inherit_default_rebind_size {};
template<typename Container>
@ -46,11 +59,26 @@ namespace sprout {
: public sprout::detail::default_array_rebind_size<Container, Size>
{};
};
template<typename Container, typename = void>
struct inherit_default_rebind_type {};
template<typename Container>
struct inherit_default_rebind_type<
Container,
typename std::enable_if<sprout::detail::is_array_like<Container>::value>::type
> {
public:
template<typename Type>
struct rebind_type
: public sprout::detail::default_array_rebind_type<Container, Type>
{};
};
} // namespace detail
template<typename Container>
struct container_transform_traits
: public sprout::detail::inherit_default_rebind_size<Container>
, public sprout::detail::inherit_default_rebind_type<Container>
{};
template<typename Container>
struct container_transform_traits<Container const> {
@ -59,6 +87,10 @@ namespace sprout {
struct rebind_size {
typedef typename sprout::container_transform_traits<Container>::template rebind_size<Size>::type const type;
};
template<typename Type>
struct rebind_type {
typedef typename sprout::container_transform_traits<Container>::template rebind_type<Type>::type const type;
};
};
template<typename T, std::size_t N>
@ -69,6 +101,11 @@ namespace sprout {
public:
typedef T type[Size];
};
template<typename Type>
struct rebind_type {
public:
typedef Type type[N];
};
};
template<typename T, std::size_t N>
struct container_transform_traits<T const[N]> {
@ -78,6 +115,11 @@ namespace sprout {
public:
typedef T const type[Size];
};
template<typename Type>
struct rebind_type {
public:
typedef Type type[N];
};
};
} // namespace sprout

View file

@ -21,6 +21,7 @@
#include <sprout/container/static_size.hpp>
#include <sprout/container/copied_type.hpp>
#include <sprout/container/rebind_size.hpp>
#include <sprout/container/rebind_type.hpp>
#include <sprout/container/weak_rebind_size.hpp>
#include <sprout/container/internal.hpp>
#include <sprout/container/deep_internal.hpp>

View file

@ -0,0 +1,26 @@
/*=============================================================================
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_CONTAINER_REBIND_TYPE_HPP
#define SPROUT_CONTAINER_REBIND_TYPE_HPP
#include <sprout/config.hpp>
#include <sprout/container/container_transform_traits.hpp>
namespace sprout {
namespace containers {
//
// rebind_type
//
template<typename Container, typename Type>
struct rebind_type
: public sprout::container_transform_traits<Container>::template rebind_type<Type>
{};
} // namespace containers
} // namespace sprout
#endif // #ifndef SPROUT_CONTAINER_REBIND_TYPE_HPP

View file

@ -0,0 +1,84 @@
/*=============================================================================
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_DETAIL_ALGORITHM_MASK_INDEX_HPP
#define SPROUT_DETAIL_ALGORITHM_MASK_INDEX_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/algorithm/fixed/results.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/detail/container_complate.hpp>
namespace sprout {
namespace detail {
template<typename InputIterator, typename Result, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == sizeof...(Args),
typename sprout::results::algorithm<Result>::type
>::type
mask_index_impl(InputIterator const&, InputIterator const&, Result const& result, Predicate,
typename sprout::container_traits<Result>::size_type,
Args const&... args
)
{
return sprout::remake<Result>(result, sprout::size(result), args...);
}
template<typename InputIterator, typename Result, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size != sizeof...(Args),
typename sprout::results::algorithm<Result>::type
>::type
mask_index_impl(
InputIterator const& first, InputIterator const& last, Result const& result,
typename sprout::container_traits<Result>::size_type size,
typename sprout::container_traits<Result>::difference_type n,
Args const&... args
)
{
return first != last && sizeof...(Args) < size
? *first
? sprout::detail::mask_index_impl(sprout::next(first), last, result, size, n + 1, args..., n)
: sprout::detail::mask_index_impl(sprout::next(first), last, result, size, n + 1, args...)
: sprout::detail::container_complate(result, args...)
;
}
template<typename InputIterator, typename Result>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_fixed_container<Result>::value,
typename sprout::results::algorithm<Result>::type
>::type
mask_index_(InputIterator const& first, InputIterator const& last, Result const& result) {
return sprout::detail::mask_index_impl(first, last, result, sprout::size(result), 0);
}
//
// mask_index
//
// recursion depth:
// O(log N)
//
template<typename InputIterator, typename Result>
inline SPROUT_CONSTEXPR typename sprout::results::algorithm<Result>::type
mask_index(InputIterator first, InputIterator last, Result const& result) {
return sprout::detail::mask_index_(first, last, result);
}
template<typename Result, typename InputIterator>
inline SPROUT_CONSTEXPR typename sprout::results::algorithm<Result>::type
mask_index(InputIterator first, InputIterator last) {
return sprout::mask_index_(first, last, sprout::pit<Result>());
}
} // namespace detail
} // namespace sprout
#endif // #ifndef SPROUT_DETAIL_ALGORITHM_MASK_INDEX_HPP

View file

@ -95,6 +95,13 @@ namespace sprout {
typename sprout::container_transform_traits<Container>::template rebind_size<Size>::type
> type;
};
template<typename Type>
struct rebind_type {
public:
typedef sprout::pit<
typename sprout::container_transform_traits<Container>::template rebind_type<Type>::type
> type;
};
};
} // namespace sprout

View file

@ -52,6 +52,11 @@ namespace sprout {
public:
typedef sprout::basic_string<T, Size, Traits> type;
};
template<typename Type>
struct rebind_type {
public:
typedef sprout::basic_string<Type, N, Traits> type;
};
};
} // namespace sprout

View file

@ -89,6 +89,15 @@ namespace sprout {
>::template rebind_size<Size>::type
> type;
};
template<typename Type>
struct rebind_type {
public:
typedef sprout::sub_array<
typename sprout::container_transform_traits<
typename std::remove_reference<Container>::type
>::template rebind_type<Type>::type
> type;
};
};
//