mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add container_range_traits default
This commit is contained in:
parent
0080332dd5
commit
8efb1a3748
23 changed files with 1822 additions and 1384 deletions
76
sprout/container/detail/range_empty.hpp
Normal file
76
sprout/container/detail/range_empty.hpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*=============================================================================
|
||||
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_DETAIL_RANGE_EMPTY_HPP
|
||||
#define SPROUT_CONTAINER_DETAIL_RANGE_EMPTY_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/container/traits_fwd.hpp>
|
||||
#include <sprout/container/container_traits.hpp>
|
||||
#include <sprout/container/range_functions_fwd.hpp>
|
||||
#include <sprout/adl/not_found.hpp>
|
||||
|
||||
namespace sprout_adl {
|
||||
sprout::not_found_via_adl range_empty(...);
|
||||
} // namespace sprout_adl
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
struct has_mem_empty_test {
|
||||
public:
|
||||
template<
|
||||
typename U = T,
|
||||
typename = typename sprout::identity<decltype(std::declval<U>().empty())>::type
|
||||
>
|
||||
static sprout::true_type test(int);
|
||||
static sprout::false_type test(...);
|
||||
};
|
||||
#if defined(_MSC_VER) && (_MSC_VER > 1900)
|
||||
template<typename T, typename Base_ = typename sprout::identity<decltype(sprout::detail::has_mem_empty_test<T>::test(0))>::type>
|
||||
struct has_mem_empty
|
||||
: public Base_
|
||||
{};
|
||||
#else
|
||||
template<typename T>
|
||||
struct has_mem_empty
|
||||
: public sprout::identity<decltype(sprout::detail::has_mem_empty_test<T>::test(0))>::type
|
||||
{};
|
||||
#endif
|
||||
|
||||
template<typename Container>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sprout::detail::has_mem_empty<Container const>::value,
|
||||
bool
|
||||
>::type
|
||||
range_empty_impl(Container const& cont) {
|
||||
return cont.empty();
|
||||
}
|
||||
template<typename Container>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!sprout::detail::has_mem_empty<Container const>::value,
|
||||
bool
|
||||
>::type
|
||||
range_empty_impl(Container const& cont) {
|
||||
return sprout::size(cont) == 0;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout_container_range_detail {
|
||||
template<typename Container>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
range_empty(Container const& cont) {
|
||||
return sprout::detail::range_empty_impl(cont);
|
||||
}
|
||||
} // namespace sprout_container_range_detail
|
||||
|
||||
#endif // #ifndef SPROUT_CONTAINER_DETAIL_RANGE_EMPTY_HPP
|
Loading…
Add table
Add a link
Reference in a new issue