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

add advance C++14 constexpr version

This commit is contained in:
bolero-MURAKAMI 2013-10-05 13:35:26 +09:00
parent b76e0aeb7f
commit a90bbd5f38
28 changed files with 145 additions and 46 deletions

View file

@ -0,0 +1,31 @@
/*=============================================================================
Copyright (c) 2011-2013 Bolero MURAKAMI
Copyright (C) 2011 RiSK (sscrisk)
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_ALGORITHM_DETAIL_MAX_HPP
#define SPROUT_ALGORITHM_DETAIL_MAX_HPP
#include <sprout/config.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
// 25.4.7 Minimum and maximum
template<typename T, typename Compare>
inline SPROUT_CONSTEXPR T const&
max(T const& a, T const& b, Compare comp) {
return comp(a, b) ? b : a;
}
template<typename T>
inline SPROUT_CONSTEXPR T const&
max(T const& a, T const& b) {
return sprout::max(a, b, NS_SSCRISK_CEL_OR_SPROUT::less<T>());
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_DETAIL_MAX_HPP

View file

@ -0,0 +1,31 @@
/*=============================================================================
Copyright (c) 2011-2013 Bolero MURAKAMI
Copyright (C) 2011 RiSK (sscrisk)
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_ALGORITHM_DETAIL_MIN_HPP
#define SPROUT_ALGORITHM_DETAIL_MIN_HPP
#include <sprout/config.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
// 25.4.7 Minimum and maximum
template<typename T, typename Compare>
inline SPROUT_CONSTEXPR T const&
min(T const& a, T const& b, Compare comp) {
return comp(b, a) ? b : a;
}
template<typename T>
inline SPROUT_CONSTEXPR T const&
min(T const& a, T const& b) {
return sprout::min(a, b, NS_SSCRISK_CEL_OR_SPROUT::less<T>());
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_DETAIL_MIN_HPP

View file

@ -18,7 +18,7 @@
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
#include <sprout/detail/container_complate.hpp>
namespace sprout {

View file

@ -18,7 +18,7 @@
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/greater_equal.hpp>
#include <sprout/detail/container_complate_backward.hpp>
namespace sprout {

View file

@ -17,7 +17,7 @@
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/copy.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
#include <sprout/detail/container_complate.hpp>
#include <sprout/iterator/type_traits/category.hpp>

View file

@ -11,6 +11,7 @@
#include <initializer_list>
#include <sprout/config.hpp>
#include <sprout/algorithm/detail/max.hpp>
#include <sprout/algorithm/max_element.hpp>
#include <sprout/iterator/ptr_index_iterator.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
@ -18,18 +19,6 @@
namespace sprout {
// 25.4.7 Minimum and maximum
template<typename T, typename Compare>
inline SPROUT_CONSTEXPR T const&
max(T const& a, T const& b, Compare comp) {
return comp(a, b) ? b : a;
}
template<typename T>
inline SPROUT_CONSTEXPR T const&
max(T const& a, T const& b) {
return sprout::max(a, b, NS_SSCRISK_CEL_OR_SPROUT::less<T>());
}
#ifdef SPROUT_NO_CXX14_INITIALIZER_LIST
template<typename T, typename Compare>
inline SPROUT_CONSTEXPR T

View file

@ -11,7 +11,8 @@
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/iterator/distance.hpp>
#include <sprout/iterator/type_traits/category.hpp>
#include <sprout/utility/pair/pair.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT

View file

@ -11,6 +11,7 @@
#include <initializer_list>
#include <sprout/config.hpp>
#include <sprout/algorithm/detail/min.hpp>
#include <sprout/algorithm/min_element.hpp>
#include <sprout/iterator/ptr_index_iterator.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
@ -18,18 +19,6 @@
namespace sprout {
// 25.4.7 Minimum and maximum
template<typename T, typename Compare>
inline SPROUT_CONSTEXPR T const&
min(T const& a, T const& b, Compare comp) {
return comp(b, a) ? b : a;
}
template<typename T>
inline SPROUT_CONSTEXPR T const&
min(T const& a, T const& b) {
return sprout::min(a, b, NS_SSCRISK_CEL_OR_SPROUT::less<T>());
}
#ifdef SPROUT_NO_CXX14_INITIALIZER_LIST
template<typename T, typename Compare>
inline SPROUT_CONSTEXPR T

View file

@ -11,7 +11,8 @@
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/iterator/distance.hpp>
#include <sprout/iterator/type_traits/category.hpp>
#include <sprout/utility/pair/pair.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT

View file

@ -11,7 +11,6 @@
#include <sprout/config.hpp>
#include <sprout/detail/pow.hpp>
#include <sprout/type_traits/float_promote.hpp>
#include <sprout/math/comparison.hpp>
namespace sprout {
namespace compost {

View file

@ -44,7 +44,9 @@
# define SPROUT_NO_CXX11_UNICODE_LITERALS
#endif
#define SPROUT_NO_CXX14_CONSTEXPR
#if (!__has_feature(cxx_constexpr) || __cplusplus < 201305L)
# define SPROUT_NO_CXX14_CONSTEXPR
#endif
#if !defined(SPROUT_NO_CXX11_CONSTEXPR)
# define SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE

View file

@ -52,6 +52,8 @@
# define SPROUT_HAS_CONSTEXPR_BIT_OPERATION
#endif
#define SPROUT_NO_CXX14_CONSTEXPR
#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9) || __cplusplus < 201300L)
# define SPROUT_NO_CXX14_CONSTEXPR
#endif
#endif // #ifndef SPROUT_CONFIG_COMPILER_GCC_HPP

View file

@ -0,0 +1,56 @@
/*=============================================================================
Copyright (c) 2011-2013 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_ITERATOR_ADVANCE_HPP
#define SPROUT_ITERATOR_ADVANCE_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/assert.hpp>
#include <sprout/math/greater_equal.hpp>
namespace sprout {
namespace detail {
template<typename InputIterator, typename Distance>
inline SPROUT_CXX14_CONSTEXPR void
advance_impl(InputIterator& it, Distance n, std::input_iterator_tag*) {
SPROUT_ASSERT(sprout::math::greater_equal(n, 0));
for (; 0 < n; --n) {
++it;
}
}
template<typename BidirectionalIterator, typename Distance>
inline SPROUT_CXX14_CONSTEXPR void
advance_impl(BidirectionalIterator& it, Distance n, std::bidirectional_iterator_tag*) {
if (n > 0) {
for (; 0 < n; --n) {
++it;
}
} else {
for (; n < 0; ++n) {
--it;
}
}
}
template<typename RandomAccessIterator, typename Distance>
inline SPROUT_CXX14_CONSTEXPR void
advance_impl(RandomAccessIterator& it, Distance n, std::random_access_iterator_tag*) {
it += n;
}
} // namespace detail
//
// advance
//
template<typename Iterator, typename Distance>
inline SPROUT_CXX14_CONSTEXPR void
advance(Iterator& it, Distance n) {
typedef typename std::iterator_traits<Iterator>::iterator_category* category;
sprout::detail::advance_impl(it, n, category());
}
} // namespace sprout
#endif // #ifndef SPROUT_ITERATOR_ADVANCE_HPP

View file

@ -15,6 +15,7 @@
#include <sprout/iterator/prev_fwd.hpp>
#include <sprout/adl/not_found.hpp>
#include <sprout/assert.hpp>
#include <sprout/math/greater_equal.hpp>
namespace sprout_adl {
sprout::not_found_via_adl iterator_next(...);
@ -101,7 +102,7 @@ namespace sprout {
std::input_iterator_tag*
)
{
return SPROUT_ASSERT(n >= 0),
return SPROUT_ASSERT(sprout::math::greater_equal(n, 0)),
n == 0 ? it
: sprout::iterator_detail::next_impl_2(it, n)
;

View file

@ -12,5 +12,6 @@
#include <sprout/iterator/next.hpp>
#include <sprout/iterator/prev.hpp>
#include <sprout/iterator/distance.hpp>
#include <sprout/iterator/advance.hpp>
#endif // #ifndef SPROUT_ITERATOR_OPERATION_HPP

View file

@ -11,7 +11,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/limits.hpp>
#include <sprout/algorithm/max.hpp>
#include <sprout/algorithm/detail/max.hpp>
#include <sprout/math/fabs.hpp>
#include <sprout/type_traits/arithmetic_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>

View file

@ -19,7 +19,7 @@
#include <sprout/iterator/amplitude_spectrum_iterator.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
#include <sprout/numeric/dft/amplitude_spectrum_value.hpp>
#include <sprout/detail/container_complate.hpp>

View file

@ -19,7 +19,7 @@
#include <sprout/iterator/dft_iterator.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
#include <sprout/numeric/dft/dft_element.hpp>
#include <sprout/detail/container_complate.hpp>

View file

@ -19,7 +19,7 @@
#include <sprout/iterator/idft_iterator.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
#include <sprout/numeric/dft/idft_element.hpp>
#include <sprout/detail/container_complate.hpp>

View file

@ -19,7 +19,7 @@
#include <sprout/iterator/phase_spectrum_iterator.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
#include <sprout/numeric/dft/phase_spectrum_value.hpp>
#include <sprout/detail/container_complate.hpp>

View file

@ -15,7 +15,6 @@
#include <sprout/container/indexes.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/floor.hpp>
#include <sprout/detail/container_complate.hpp>

View file

@ -15,7 +15,6 @@
#include <sprout/container/indexes.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/constants.hpp>
#include <sprout/math/sin.hpp>
#include <sprout/detail/container_complate.hpp>

View file

@ -15,7 +15,6 @@
#include <sprout/container/indexes.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/numeric/dft/fixed/sawtooth.hpp>
#include <sprout/detail/container_complate.hpp>

View file

@ -15,7 +15,6 @@
#include <sprout/container/indexes.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/sin.hpp>
#include <sprout/math/asin.hpp>
#include <sprout/math/constants.hpp>

View file

@ -15,7 +15,7 @@
#include <sprout/limits.hpp>
#include <sprout/random/detail/const_mod.hpp>
#include <sprout/random/random_result.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/greater_equal.hpp>
#include <sprout/assert.hpp>
namespace sprout {

View file

@ -15,7 +15,7 @@
#include <sprout/limits.hpp>
#include <sprout/random/detail/const_mod.hpp>
#include <sprout/random/random_result.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/greater_equal.hpp>
#include <sprout/assert.hpp>
namespace sprout {

View file

@ -29,7 +29,7 @@
#include <sprout/utility/swap.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/string/npos.hpp>
#include <sprout/string/detail/operations.hpp>

View file

@ -27,7 +27,7 @@
#include <sprout/functional/type_traits/weak_result_type.hpp>
#include <sprout/variant/variant_fwd.hpp>
#include <sprout/variant/visitor_result.hpp>
#include <sprout/math/comparison.hpp>
#include <sprout/math/less.hpp>
namespace sprout {
namespace detail {