mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-02-11 10:03:59 +00:00
add valarray
This commit is contained in:
parent
5ff6029d51
commit
1b8c051008
27 changed files with 3330 additions and 5 deletions
|
@ -27,7 +27,7 @@ namespace sprout {
|
|||
>::type
|
||||
mask_index_impl(InputIterator const&, InputIterator const&, Result const& result,
|
||||
typename sprout::container_traits<Result>::size_type,
|
||||
typename sprout::container_traits<Result>::difference_type n,
|
||||
typename sprout::container_traits<Result>::difference_type,
|
||||
Args const&... args
|
||||
)
|
||||
{
|
||||
|
|
|
@ -11,5 +11,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/unary_function.hpp>
|
||||
#include <sprout/functional/binary_function.hpp>
|
||||
#include <sprout/functional/transparent.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BASE_HPP
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace sprout {
|
|||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(std::declval<T>() >> std::declval<U>())
|
||||
operator()(T&& x, U&& y)
|
||||
const SPROUT_NOEXCEPT_IF_EXPR(std::declval<T>() << std::declval<U>())
|
||||
const SPROUT_NOEXCEPT_IF_EXPR(std::declval<T>() >> std::declval<U>())
|
||||
{
|
||||
return SPROUT_FORWARD(T, x) >> SPROUT_FORWARD(U, y);
|
||||
}
|
||||
|
|
24
sprout/functional/transparent.hpp
Normal file
24
sprout/functional/transparent.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*=============================================================================
|
||||
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_FUNCTIONAL_TRANSPARENT_HPP
|
||||
#define SPROUT_FUNCTIONAL_TRANSPARENT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// transparent
|
||||
//
|
||||
template<typename T = void>
|
||||
struct transparent {
|
||||
public:
|
||||
typedef T is_transparent;
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_TRANSPARENT_HPP
|
|
@ -123,7 +123,7 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
return first != last && sizeof...(Args) + 1 < size
|
||||
? partial_sum_impl_1(sprout::next(first), last, result, size, binary_op(value, *first), args..., value)
|
||||
? partial_sum_impl_1(sprout::next(first), last, result, binary_op, size, binary_op(value, *first), args..., value)
|
||||
: sprout::detail::container_complate(result, args..., value)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace sprout {
|
|||
static SPROUT_CONSTEXPR copied_type
|
||||
remake(Cont&&, typename sprout::container_traits<sprout::basic_string<T, N, Traits> >::difference_type size, Args&&... args) {
|
||||
typedef sprout::detail::make_construct_impl<copied_type> impl_type;
|
||||
return impl_type::make(static_cast<typename copied_type::size_type>(size), SPROUT_FORWARD(Args, args)...);
|
||||
return impl_type::sized_make(static_cast<typename copied_type::size_type>(size), SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1230,7 +1230,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type
|
||||
make(typename copied_type::size_type size, Args&&... args) {
|
||||
sized_make(typename copied_type::size_type size, Args&&... args) {
|
||||
typedef sprout::detail::string_construct_access<T, N, Traits> access_type;
|
||||
return access_type::raw_construct(size, SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
|
|
31
sprout/valarray.hpp
Normal file
31
sprout/valarray.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2015 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_VALARRAY_HPP
|
||||
#define SPROUT_VALARRAY_HPP
|
||||
|
||||
#include <sprout/valarray/valarray_fwd.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/valarray/slice_array.hpp>
|
||||
#include <sprout/valarray/gslice_array.hpp>
|
||||
#include <sprout/valarray/mask_array.hpp>
|
||||
#include <sprout/valarray/indirect_array.hpp>
|
||||
#include <sprout/valarray/arithmetic.hpp>
|
||||
#include <sprout/valarray/comparison.hpp>
|
||||
#include <sprout/valarray/logical.hpp>
|
||||
#include <sprout/valarray/bitwise.hpp>
|
||||
#include <sprout/valarray/trigonometric.hpp>
|
||||
#include <sprout/valarray/hyperbolic.hpp>
|
||||
#include <sprout/valarray/exponential.hpp>
|
||||
#include <sprout/valarray/power.hpp>
|
||||
#include <sprout/valarray/container.hpp>
|
||||
#include <sprout/valarray/hash.hpp>
|
||||
#include <sprout/valarray/tuple.hpp>
|
||||
#include <sprout/valarray/make_valarray.hpp>
|
||||
#include <sprout/valarray/type_traits.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_HPP
|
116
sprout/valarray/arithmetic.hpp
Normal file
116
sprout/valarray/arithmetic.hpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_ARITHMETIC_HPP
|
||||
#define SPROUT_VALARRAY_ARITHMETIC_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/functional/plus.hpp>
|
||||
#include <sprout/functional/minus.hpp>
|
||||
#include <sprout/functional/multiplies.hpp>
|
||||
#include <sprout/functional/divides.hpp>
|
||||
#include <sprout/functional/modulus.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/functional/bind1st.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// operator+
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator+(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::plus<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator+(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::plus<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator+(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::plus<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator-
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator-(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::minus<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator-(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::minus<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator-(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::minus<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator*
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator*(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::multiplies<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator*(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::multiplies<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator*(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::multiplies<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator/
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator/(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::divides<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator/(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::divides<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator/(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::divides<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator%
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator%(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::modulus<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator%(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::modulus<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator%(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::modulus<>(), lhs));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_ARITHMETIC_HPP
|
116
sprout/valarray/bitwise.hpp
Normal file
116
sprout/valarray/bitwise.hpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_BITWISE_HPP
|
||||
#define SPROUT_VALARRAY_BITWISE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/functional/bit_and.hpp>
|
||||
#include <sprout/functional/bit_or.hpp>
|
||||
#include <sprout/functional/bit_xor.hpp>
|
||||
#include <sprout/functional/shift_left.hpp>
|
||||
#include <sprout/functional/shift_right.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/functional/bind1st.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// operator&
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator&(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::bit_and<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator&(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::bit_and<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator&(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::bit_and<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator|(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::bit_or<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator|(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::bit_or<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator|(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::bit_or<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator^
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator^(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::bit_xor<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator^(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::bit_xor<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator^(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::bit_xor<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator<<
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator<<(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::shift_left<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator<<(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::shift_left<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator<<(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::shift_left<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator>>
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator>>(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::shift_right<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator>>(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::shift_right<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator>>(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::shift_right<>(), lhs));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_BITWISE_HPP
|
131
sprout/valarray/comparison.hpp
Normal file
131
sprout/valarray/comparison.hpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_COMPARISON_HPP
|
||||
#define SPROUT_VALARRAY_COMPARISON_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/functional/equal_to.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/functional/bind1st.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// operator==
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator==(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), sprout::valarray<bool, N>(lhs.size()), sprout::equal_to<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator==(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), sprout::valarray<bool, N>(lhs.size()), sprout::bind2nd(sprout::equal_to<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator==(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), sprout::valarray<bool, N>(rhs.size()), sprout::bind1st(sprout::equal_to<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator!=
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator!=(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator!=(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator!=(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
//
|
||||
// operator<
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator<(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), sprout::valarray<bool, N>(lhs.size()), sprout::less<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator<(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), sprout::valarray<bool, N>(lhs.size()), sprout::bind2nd(sprout::less<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator<(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), sprout::valarray<bool, N>(rhs.size()), sprout::bind1st(sprout::less<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator>
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator>(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator>(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator>(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
//
|
||||
// operator<=
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator<=(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator<=(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator<=(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
//
|
||||
// operator>=
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator>=(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator>=(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator>=(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_COMPARISON_HPP
|
63
sprout/valarray/container.hpp
Normal file
63
sprout/valarray/container.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_CONTAINER_HPP
|
||||
#define SPROUT_VALARRAY_CONTAINER_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
struct container_construct_traits<sprout::valarray<T, N> > {
|
||||
public:
|
||||
typedef sprout::valarray<T, N> copied_type;
|
||||
public:
|
||||
template<typename Cont>
|
||||
static SPROUT_CONSTEXPR copied_type
|
||||
deep_copy(Cont&& cont) {
|
||||
return SPROUT_FORWARD(Cont, cont);
|
||||
}
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type
|
||||
make(Args&&... args) {
|
||||
typedef sprout::detail::make_construct_impl<copied_type> impl_type;
|
||||
return impl_type::make(SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
template<typename Cont, typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type
|
||||
remake(Cont&&, typename sprout::container_traits<sprout::valarray<T, N> >::difference_type size, Args&&... args) {
|
||||
typedef sprout::detail::make_construct_impl<copied_type> impl_type;
|
||||
return impl_type::sized_make(static_cast<typename copied_type::size_type>(size), SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// container_transform_traits
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
struct container_transform_traits<sprout::valarray<T, N> > {
|
||||
public:
|
||||
template<typename sprout::container_traits<sprout::valarray<T, N> >::size_type Size>
|
||||
struct rebind_size {
|
||||
public:
|
||||
typedef sprout::valarray<T, Size> type;
|
||||
};
|
||||
template<typename Type>
|
||||
struct rebind_type {
|
||||
public:
|
||||
typedef sprout::valarray<Type, N> type;
|
||||
};
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_CONTAINER_HPP
|
260
sprout/valarray/exponential.hpp
Normal file
260
sprout/valarray/exponential.hpp
Normal file
|
@ -0,0 +1,260 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_EXPONENTIAL_HPP
|
||||
#define SPROUT_VALARRAY_EXPONENTIAL_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/math/exp.hpp>
|
||||
#include <sprout/math/exp10.hpp>
|
||||
#include <sprout/math/exp2.hpp>
|
||||
#include <sprout/math/expm1.hpp>
|
||||
#include <sprout/math/log.hpp>
|
||||
#include <sprout/math/log10.hpp>
|
||||
#include <sprout/math/log1p.hpp>
|
||||
#include <sprout/math/log2.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout_math_detail {
|
||||
using sprout::math::exp;
|
||||
using sprout::math::exp10;
|
||||
using sprout::math::exp2;
|
||||
using sprout::math::expm1;
|
||||
using sprout::math::log;
|
||||
using sprout::math::log10;
|
||||
using sprout::math::log1p;
|
||||
using sprout::math::log2;
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(exp(std::declval<T>()))
|
||||
call_exp(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(exp(std::declval<T>()))
|
||||
{
|
||||
return exp(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(exp10(std::declval<T>()))
|
||||
call_exp10(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(exp10(std::declval<T>()))
|
||||
{
|
||||
return exp10(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(exp2(std::declval<T>()))
|
||||
call_exp2(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(exp2(std::declval<T>()))
|
||||
{
|
||||
return exp2(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(expm1(std::declval<T>()))
|
||||
call_expm1(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(expm1(std::declval<T>()))
|
||||
{
|
||||
return expm1(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(log(std::declval<T>()))
|
||||
call_log(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(log(std::declval<T>()))
|
||||
{
|
||||
return log(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(log10(std::declval<T>()))
|
||||
call_log10(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(log10(std::declval<T>()))
|
||||
{
|
||||
return log10(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(log1p(std::declval<T>()))
|
||||
call_log1p(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(log1p(std::declval<T>()))
|
||||
{
|
||||
return log1p(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(log2(std::declval<T>()))
|
||||
call_log2(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(log2(std::declval<T>()))
|
||||
{
|
||||
return log2(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
struct exp_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_exp(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_exp(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_exp(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct exp10_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_exp10(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_exp10(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_exp10(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct exp2_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_exp2(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_exp2(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_exp2(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct expm1_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_expm1(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_expm1(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_expm1(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct log_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_log(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_log(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_log(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct log10_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_log10(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_log10(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_log10(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct log1p_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_log1p(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_log1p(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_log1p(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct log2_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_log2(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_log2(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_log2(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// exp
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
exp(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::exp_f());
|
||||
}
|
||||
//
|
||||
// exp10
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
exp10(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::exp10_f());
|
||||
}
|
||||
//
|
||||
// exp2
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
exp2(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::exp2_f());
|
||||
}
|
||||
//
|
||||
// expm1
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
expm1(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::expm1_f());
|
||||
}
|
||||
//
|
||||
// log
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
log(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::log_f());
|
||||
}
|
||||
//
|
||||
// log10
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
log10(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::log10_f());
|
||||
}
|
||||
//
|
||||
// log1p
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
log1p(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::log1p_f());
|
||||
}
|
||||
//
|
||||
// log2
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
log2(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::log2_f());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_EXPONENTIAL_HPP
|
261
sprout/valarray/gslice_array.hpp
Normal file
261
sprout/valarray/gslice_array.hpp
Normal file
|
@ -0,0 +1,261 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2015 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_VALARRAY_GSLICE_ARRAY_HPP
|
||||
#define SPROUT_VALARRAY_GSLICE_ARRAY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/index_iterator.hpp>
|
||||
#include <sprout/functional/multiplies.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/fill.hpp>
|
||||
#include <sprout/range/numeric/fixed/partial_sum.hpp>
|
||||
#include <sprout/range/adaptor/copied.hpp>
|
||||
#include <sprout/range/adaptor/reversed.hpp>
|
||||
#include <sprout/valarray/valarray_fwd.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// gslice
|
||||
//
|
||||
template<std::size_t N>
|
||||
class gslice {
|
||||
private:
|
||||
std::size_t start_;
|
||||
sprout::valarray<std::size_t, N> size_;
|
||||
sprout::valarray<std::size_t, N> stride_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR gslice()
|
||||
: start_(), size_(), stride_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR gslice(std::size_t start, sprout::valarray<std::size_t, N> const& size, sprout::valarray<std::size_t, N> const& stride)
|
||||
: start_(start), size_(size), stride_(stride)
|
||||
{}
|
||||
SPROUT_CONSTEXPR std::size_t start() const {
|
||||
return start_;
|
||||
}
|
||||
SPROUT_CONSTEXPR sprout::valarray<std::size_t, N> size() const {
|
||||
return size_;
|
||||
}
|
||||
SPROUT_CONSTEXPR sprout::valarray<std::size_t, N> stride() const {
|
||||
return stride_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// gslice_array
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
class gslice_array {
|
||||
friend class sprout::valarray<T, N>;
|
||||
private:
|
||||
typedef sprout::valarray<T, N> valarray_type;
|
||||
public:
|
||||
typedef typename valarray_type::value_type value_type;
|
||||
typedef typename valarray_type::reference reference;
|
||||
typedef typename valarray_type::size_type size_type;
|
||||
typedef typename valarray_type::difference_type difference_type;
|
||||
typedef typename valarray_type::pointer pointer;
|
||||
typedef sprout::index_iterator<gslice_array const&> iterator;
|
||||
private:
|
||||
typedef sprout::gslice<M> gslice_type;
|
||||
typedef sprout::valarray<size_type, (M < N ? M : N)> indexes_type;
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR size_type static_size = valarray_type::static_size;
|
||||
private:
|
||||
sprout::value_holder<valarray_type&> arr_;
|
||||
std::size_t start_;
|
||||
sprout::valarray<std::size_t, M> size_;
|
||||
sprout::valarray<std::size_t, M> stride_;
|
||||
private:
|
||||
gslice_array() = delete;
|
||||
SPROUT_CONSTEXPR gslice_array(sprout::valarray<T, N>& arr, gslice_type const& gslice)
|
||||
: arr_(arr)
|
||||
, start_(gslice.start())
|
||||
, size_(
|
||||
sprout::range::fixed::partial_sum(gslice.size() | sprout::adaptors::reversed, gslice.size(), sprout::multiplies<>())
|
||||
| sprout::adaptors::reversed | sprout::adaptors::copied(gslice.size())
|
||||
)
|
||||
, stride_(gslice.stride())
|
||||
{}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
SPROUT_CONSTEXPR size_type index_impl(
|
||||
size_type i,
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2
|
||||
) const
|
||||
{
|
||||
return first1 != last1 ? *first2 * (i / *first1) + index_impl(
|
||||
i % *first1,
|
||||
sprout::next(first1), last1,
|
||||
sprout::next(first2)
|
||||
)
|
||||
: *first2 * i
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type index(size_type i) const {
|
||||
return i < size() ? start_ + index_impl(i, sprout::next(size_.begin()), size_.end(), stride_.begin())
|
||||
: arr_->max_size()
|
||||
;
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR gslice_array(gslice_array const& other)
|
||||
: arr_(other.arr_), start_(other.start_), size_(other.size_), stride_(other.stride_)
|
||||
{}
|
||||
template<std::size_t N2, std::size_t M2>
|
||||
SPROUT_CXX14_CONSTEXPR gslice_array const&
|
||||
operator=(gslice_array<T, N2, M2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
return *this;
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(sprout::valarray<T, N2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(T const& value) const {
|
||||
sprout::fill(begin(), end(), value);
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator+=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 += *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator-=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 -= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator*=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 *= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator/=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 /= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator%=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 %= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator&=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 &= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator|=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 |= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator^=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 ^= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator<<=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 <<= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator>>=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 >>= *it;
|
||||
}
|
||||
}
|
||||
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
swap(gslice_array& other) SPROUT_NOEXCEPT {
|
||||
sprout::swap(arr_, other.arr_);
|
||||
sprout::swap(start_, other.start_);
|
||||
sprout::swap(size_, other.size_);
|
||||
sprout::swap(stride_, other.stride_);
|
||||
}
|
||||
|
||||
// iterators:
|
||||
SPROUT_CONSTEXPR iterator
|
||||
begin() const {
|
||||
return iterator(*this, 0);
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator
|
||||
end() const {
|
||||
return iterator(*this, size());
|
||||
}
|
||||
// capacity:
|
||||
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
|
||||
return size_.front();
|
||||
}
|
||||
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
|
||||
return size() == 0;
|
||||
}
|
||||
// element access:
|
||||
SPROUT_CONSTEXPR reference operator[](size_type i) const {
|
||||
return (*arr_)[index(i)];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference at(size_type i) const {
|
||||
return arr_->at(index(i));
|
||||
}
|
||||
SPROUT_CONSTEXPR reference front() const {
|
||||
return (*this)[0];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference back() const {
|
||||
return (*this)[size() - 1];
|
||||
}
|
||||
};
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::gslice_array<T, N, M>::size_type sprout::gslice_array<T, N, M>::static_size;
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::gslice_array<T, N, M>& lhs, sprout::gslice_array<T, N, M>& rhs)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_GSLICE_ARRAY_HPP
|
45
sprout/valarray/hash.hpp
Normal file
45
sprout/valarray/hash.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_HASH_HPP
|
||||
#define SPROUT_VALARRAY_HASH_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::valarray<T, N> const& v) {
|
||||
return sprout::hash_range(v);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// hash
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
struct hash<sprout::valarray<T, N> >
|
||||
: public sprout::hash<sprout::valarray<T, N> >
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_HASH_HPP
|
202
sprout/valarray/hyperbolic.hpp
Normal file
202
sprout/valarray/hyperbolic.hpp
Normal file
|
@ -0,0 +1,202 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_HYPERBOLIC_HPP
|
||||
#define SPROUT_VALARRAY_HYPERBOLIC_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/math/acosh.hpp>
|
||||
#include <sprout/math/asinh.hpp>
|
||||
#include <sprout/math/atanh.hpp>
|
||||
#include <sprout/math/cosh.hpp>
|
||||
#include <sprout/math/sinh.hpp>
|
||||
#include <sprout/math/tanh.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout_math_detail {
|
||||
using sprout::math::acosh;
|
||||
using sprout::math::asinh;
|
||||
using sprout::math::atanh;
|
||||
using sprout::math::cosh;
|
||||
using sprout::math::sinh;
|
||||
using sprout::math::tanh;
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(acosh(std::declval<T>()))
|
||||
call_acosh(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(acosh(std::declval<T>()))
|
||||
{
|
||||
return acosh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(asinh(std::declval<T>()))
|
||||
call_asinh(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(asinh(std::declval<T>()))
|
||||
{
|
||||
return asinh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(atanh(std::declval<T>()))
|
||||
call_atanh(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(atanh(std::declval<T>()))
|
||||
{
|
||||
return atanh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(cosh(std::declval<T>()))
|
||||
call_cosh(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(cosh(std::declval<T>()))
|
||||
{
|
||||
return cosh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(sinh(std::declval<T>()))
|
||||
call_sinh(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sinh(std::declval<T>()))
|
||||
{
|
||||
return sinh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(tanh(std::declval<T>()))
|
||||
call_tanh(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(tanh(std::declval<T>()))
|
||||
{
|
||||
return tanh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
struct acosh_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_acosh(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_acosh(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_acosh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct asinh_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_asinh(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_asinh(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_asinh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct atanh_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_atanh(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_atanh(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_atanh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct cosh_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_cosh(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_cosh(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_cosh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct sinh_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_sinh(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_sinh(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_sinh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct tanh_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_tanh(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_tanh(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_tanh(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// acosh
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
acosh(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::acosh_f());
|
||||
}
|
||||
//
|
||||
// asinh
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
asinh(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::asinh_f());
|
||||
}
|
||||
//
|
||||
// atanh
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
atanh(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::atanh_f());
|
||||
}
|
||||
//
|
||||
// cosh
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
cosh(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::cosh_f());
|
||||
}
|
||||
//
|
||||
// sinh
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
sinh(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::sinh_f());
|
||||
}
|
||||
//
|
||||
// tanh
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
tanh(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::tanh_f());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_HYPERBOLIC_HPP
|
199
sprout/valarray/indirect_array.hpp
Normal file
199
sprout/valarray/indirect_array.hpp
Normal file
|
@ -0,0 +1,199 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2015 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_VALARRAY_INDIRECT_ARRAY_HPP
|
||||
#define SPROUT_VALARRAY_INDIRECT_ARRAY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/iterator/index_iterator.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/fill.hpp>
|
||||
#include <sprout/valarray/valarray_fwd.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// indirect_array
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
class indirect_array {
|
||||
friend class sprout::valarray<T, N>;
|
||||
private:
|
||||
typedef sprout::valarray<T, N> valarray_type;
|
||||
public:
|
||||
typedef typename valarray_type::value_type value_type;
|
||||
typedef typename valarray_type::reference reference;
|
||||
typedef typename valarray_type::size_type size_type;
|
||||
typedef typename valarray_type::difference_type difference_type;
|
||||
typedef typename valarray_type::pointer pointer;
|
||||
typedef sprout::index_iterator<indirect_array const&> iterator;
|
||||
private:
|
||||
typedef sprout::valarray<size_type, M> indexes_type;
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR size_type static_size = valarray_type::static_size;
|
||||
private:
|
||||
sprout::value_holder<valarray_type&> arr_;
|
||||
indexes_type indexes_;
|
||||
private:
|
||||
indirect_array() = delete;
|
||||
SPROUT_CONSTEXPR indirect_array(sprout::valarray<T, N>& arr, indexes_type const& indexes)
|
||||
: arr_(arr)
|
||||
, indexes_(indexes)
|
||||
{}
|
||||
public:
|
||||
SPROUT_CONSTEXPR indirect_array(indirect_array const& other)
|
||||
: arr_(other.arr_), indexes_(other.indexes_)
|
||||
{}
|
||||
template<std::size_t N2, std::size_t M2>
|
||||
SPROUT_CXX14_CONSTEXPR indirect_array const&
|
||||
operator=(indirect_array<T, N2, M2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
return *this;
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(sprout::valarray<T, N2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(T const& value) const {
|
||||
sprout::fill(begin(), end(), value);
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator+=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 += *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator-=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 -= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator*=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 *= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator/=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 /= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator%=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 %= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator&=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 &= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator|=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 |= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator^=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 ^= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator<<=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 <<= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator>>=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 >>= *it;
|
||||
}
|
||||
}
|
||||
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
swap(indirect_array& other) SPROUT_NOEXCEPT {
|
||||
sprout::swap(arr_, other.arr_);
|
||||
sprout::swap(indexes_, other.indexes_);
|
||||
}
|
||||
|
||||
// iterators:
|
||||
SPROUT_CONSTEXPR iterator
|
||||
begin() const {
|
||||
return iterator(*this, 0);
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator
|
||||
end() const {
|
||||
return iterator(*this, size());
|
||||
}
|
||||
// capacity:
|
||||
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
|
||||
return indexes_.size();
|
||||
}
|
||||
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
|
||||
return size() == 0;
|
||||
}
|
||||
// element access:
|
||||
SPROUT_CONSTEXPR reference operator[](size_type i) const {
|
||||
return (*arr_)[indexes_[i]];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference at(size_type i) const {
|
||||
return arr_->at(indexes_.at(i));
|
||||
}
|
||||
SPROUT_CONSTEXPR reference front() const {
|
||||
return (*this)[0];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference back() const {
|
||||
return (*this)[size() - 1];
|
||||
}
|
||||
};
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::indirect_array<T, N, M>::size_type sprout::indirect_array<T, N, M>::static_size;
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::indirect_array<T, N, M>& lhs, sprout::indirect_array<T, N, M>& rhs)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_INDIRECT_ARRAY_HPP
|
59
sprout/valarray/logical.hpp
Normal file
59
sprout/valarray/logical.hpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_LOGICAL_HPP
|
||||
#define SPROUT_VALARRAY_LOGICAL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/functional/logical_and.hpp>
|
||||
#include <sprout/functional/logical_or.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/functional/bind1st.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// operator&&
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator&&(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), sprout::valarray<bool, N>(lhs.size()), sprout::logical_and<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator&&(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), sprout::valarray<bool, N>(lhs.size()), sprout::bind2nd(sprout::logical_and<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator&&(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), sprout::valarray<bool, N>(rhs.size()), sprout::bind1st(sprout::logical_and<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator||
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator||(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), sprout::valarray<bool, N>(lhs.size()), sprout::logical_or<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator||(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), sprout::valarray<bool, N>(lhs.size()), sprout::bind2nd(sprout::logical_or<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<bool, N>
|
||||
operator||(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), sprout::valarray<bool, N>(rhs.size()), sprout::bind1st(sprout::logical_or<>(), lhs));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_LOGICAL_HPP
|
73
sprout/valarray/make_valarray.hpp
Normal file
73
sprout/valarray/make_valarray.hpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_MAKE_VALARRAY_HPP
|
||||
#define SPROUT_VALARRAY_MAKE_VALARRAY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/index_tuple/metafunction.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/type_traits/common_decay.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
enum make_valarray_t {
|
||||
make_valarray_in_common_elements
|
||||
};
|
||||
} // namespace detail
|
||||
//
|
||||
// make_valarray
|
||||
//
|
||||
template<typename T, typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<typename std::remove_cv<T>::type, sizeof...(Types)>
|
||||
make_valarray(Types&&... args) {
|
||||
typedef sprout::valarray<typename std::remove_cv<T>::type, sizeof...(Types)> type;
|
||||
typedef sprout::detail::make_construct_impl<type> construct_type;
|
||||
return construct_type::make(T(SPROUT_FORWARD(Types, args))...);
|
||||
}
|
||||
template<sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
|
||||
make_valarray(Types&&... args) {
|
||||
typedef typename sprout::common_decay<Types...>::type value_type;
|
||||
typedef sprout::valarray<value_type, sizeof...(Types)> type;
|
||||
typedef sprout::detail::make_construct_impl<type> construct_type;
|
||||
return construct_type::make(value_type(SPROUT_FORWARD(Types, args))...);
|
||||
}
|
||||
|
||||
//
|
||||
// make_valarray_without_narrowing
|
||||
//
|
||||
template<typename T, typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<typename std::remove_cv<T>::type, sizeof...(Types)>
|
||||
make_valarray_without_narrowing(Types&&... args) {
|
||||
typedef sprout::valarray<typename std::remove_cv<T>::type, sizeof...(Types)> type;
|
||||
typedef sprout::detail::make_construct_impl<type> construct_type;
|
||||
return construct_type::make(SPROUT_FORWARD(Types, args)...);
|
||||
}
|
||||
template<sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
|
||||
make_valarray_without_narrowing(Types&&... args) {
|
||||
typedef typename sprout::common_decay<Types...>::type value_type;
|
||||
typedef sprout::valarray<value_type, sizeof...(Types)> type;
|
||||
typedef sprout::detail::make_construct_impl<type> construct_type;
|
||||
return construct_type::make(SPROUT_FORWARD(Types, args)...);
|
||||
}
|
||||
|
||||
//
|
||||
// make_common_valarray
|
||||
//
|
||||
template<typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
|
||||
make_common_valarray(Types&&... args) {
|
||||
return sprout::make_valarray(SPROUT_FORWARD(Types, args)...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_MAKE_VALARRAY_HPP
|
207
sprout/valarray/mask_array.hpp
Normal file
207
sprout/valarray/mask_array.hpp
Normal file
|
@ -0,0 +1,207 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2015 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_VALARRAY_MASKE_ARRAY_HPP
|
||||
#define SPROUT_VALARRAY_MASKE_ARRAY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/iterator/index_iterator.hpp>
|
||||
#include <sprout/algorithm/count.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/fill.hpp>
|
||||
#include <sprout/valarray/valarray_fwd.hpp>
|
||||
#include <sprout/detail/algorithm/mask_index.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// mask_array
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
class mask_array {
|
||||
friend class sprout::valarray<T, N>;
|
||||
private:
|
||||
typedef sprout::valarray<T, N> valarray_type;
|
||||
public:
|
||||
typedef typename valarray_type::value_type value_type;
|
||||
typedef typename valarray_type::reference reference;
|
||||
typedef typename valarray_type::size_type size_type;
|
||||
typedef typename valarray_type::difference_type difference_type;
|
||||
typedef typename valarray_type::pointer pointer;
|
||||
typedef sprout::index_iterator<mask_array const&> iterator;
|
||||
private:
|
||||
typedef sprout::valarray<bool, M> mask_type;
|
||||
typedef sprout::valarray<size_type, (M < N ? M : N)> indexes_type;
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR size_type static_size = valarray_type::static_size;
|
||||
private:
|
||||
sprout::value_holder<valarray_type&> arr_;
|
||||
indexes_type indexes_;
|
||||
private:
|
||||
mask_array() = delete;
|
||||
SPROUT_CONSTEXPR mask_array(sprout::valarray<T, N>& arr, mask_type const& mask)
|
||||
: arr_(arr)
|
||||
, indexes_(
|
||||
sprout::detail::mask_index(
|
||||
mask.begin(), mask.end(),
|
||||
indexes_type(sprout::count(mask.begin(), mask.end(), true))
|
||||
)
|
||||
)
|
||||
{}
|
||||
public:
|
||||
SPROUT_CONSTEXPR mask_array(mask_array const& other)
|
||||
: arr_(other.arr_), indexes_(other.indexes_)
|
||||
{}
|
||||
template<std::size_t N2, std::size_t M2>
|
||||
SPROUT_CXX14_CONSTEXPR mask_array const&
|
||||
operator=(mask_array<T, N2, M2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
return *this;
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(sprout::valarray<T, N2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(T const& value) const {
|
||||
sprout::fill(begin(), end(), value);
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator+=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 += *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator-=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 -= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator*=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 *= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator/=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 /= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator%=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 %= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator&=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 &= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator|=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 |= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator^=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 ^= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator<<=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 <<= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator>>=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 >>= *it;
|
||||
}
|
||||
}
|
||||
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
swap(mask_array& other) SPROUT_NOEXCEPT {
|
||||
sprout::swap(arr_, other.arr_);
|
||||
sprout::swap(indexes_, other.indexes_);
|
||||
}
|
||||
|
||||
// iterators:
|
||||
SPROUT_CONSTEXPR iterator
|
||||
begin() const {
|
||||
return iterator(*this, 0);
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator
|
||||
end() const {
|
||||
return iterator(*this, size());
|
||||
}
|
||||
// capacity:
|
||||
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
|
||||
return indexes_.size();
|
||||
}
|
||||
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
|
||||
return size() == 0;
|
||||
}
|
||||
// element access:
|
||||
SPROUT_CONSTEXPR reference operator[](size_type i) const {
|
||||
return (*arr_)[indexes_[i]];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference at(size_type i) const {
|
||||
return arr_->at(indexes_.at(i));
|
||||
}
|
||||
SPROUT_CONSTEXPR reference front() const {
|
||||
return (*this)[0];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference back() const {
|
||||
return (*this)[size() - 1];
|
||||
}
|
||||
};
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::mask_array<T, N, M>::size_type sprout::mask_array<T, N, M>::static_size;
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::mask_array<T, N, M>& lhs, sprout::mask_array<T, N, M>& rhs)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_MASKE_ARRAY_HPP
|
234
sprout/valarray/power.hpp
Normal file
234
sprout/valarray/power.hpp
Normal file
|
@ -0,0 +1,234 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_POWER_HPP
|
||||
#define SPROUT_VALARRAY_POWER_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/math/cbrt.hpp>
|
||||
#include <sprout/math/abs.hpp>
|
||||
#include <sprout/math/hypot.hpp>
|
||||
#include <sprout/math/pow.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/math/log_a.hpp>
|
||||
#include <sprout/cstdlib/abs.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout_math_detail {
|
||||
using sprout::math::cbrt;
|
||||
using sprout::math::abs;
|
||||
using sprout::math::hypot;
|
||||
using sprout::math::pow;
|
||||
using sprout::math::sqrt;
|
||||
using sprout::math::log_a;
|
||||
using sprout::abs;
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(cbrt(std::declval<T>()))
|
||||
call_cbrt(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(cbrt(std::declval<T>()))
|
||||
{
|
||||
return cbrt(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(abs(std::declval<T>()))
|
||||
call_abs(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(abs(std::declval<T>()))
|
||||
{
|
||||
return abs(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T, typename U>
|
||||
inline SPROUT_CONSTEXPR decltype(hypot(std::declval<T>(), std::declval<U>()))
|
||||
call_hypot(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(hypot(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return hypot(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y));
|
||||
}
|
||||
template<typename T, typename U>
|
||||
inline SPROUT_CONSTEXPR decltype(pow(std::declval<T>(), std::declval<U>()))
|
||||
call_pow(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(pow(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return pow(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(sqrt(std::declval<T>()))
|
||||
call_sqrt(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sqrt(std::declval<T>()))
|
||||
{
|
||||
return sqrt(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T, typename U>
|
||||
inline SPROUT_CONSTEXPR decltype(log_a(std::declval<T>(), std::declval<U>()))
|
||||
call_log_a(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(log_a(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return log_a(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
struct cbrt_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_cbrt(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_cbrt(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_cbrt(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct abs_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_abs(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_abs(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_abs(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct hypot_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_hypot(std::declval<T>(), std::declval<U>()))
|
||||
operator()(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_hypot(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return sprout_math_detail::call_hypot(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y));
|
||||
}
|
||||
};
|
||||
struct pow_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_pow(std::declval<T>(), std::declval<U>()))
|
||||
operator()(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_pow(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return sprout_math_detail::call_pow(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y));
|
||||
}
|
||||
};
|
||||
struct sqrt_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_sqrt(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_sqrt(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_sqrt(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct log_a_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_log_a(std::declval<T>(), std::declval<U>()))
|
||||
operator()(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_log_a(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return sprout_math_detail::call_log_a(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// cbrt
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
cbrt(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::cbrt_f());
|
||||
}
|
||||
//
|
||||
// abs
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
abs(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::abs_f());
|
||||
}
|
||||
//
|
||||
// hypot
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
hypot(sprout::valarray<T, N> const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), y.end(), x, sprout::detail::hypot_f());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
hypot(sprout::valarray<T, N> const& x, T const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::bind2nd(sprout::detail::hypot_f(), y));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
hypot(T const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(y.begin(), y.end(), y, sprout::bind1st(sprout::detail::hypot_f(), x));
|
||||
}
|
||||
//
|
||||
// pow
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
pow(sprout::valarray<T, N> const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), y.end(), x, sprout::detail::pow_f());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
pow(sprout::valarray<T, N> const& x, T const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::bind2nd(sprout::detail::pow_f(), y));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
pow(T const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(y.begin(), y.end(), y, sprout::bind1st(sprout::detail::pow_f(), x));
|
||||
}
|
||||
//
|
||||
// sqrt
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
sqrt(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::sqrt_f());
|
||||
}
|
||||
//
|
||||
// log_a
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
log_a(sprout::valarray<T, N> const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), y.end(), x, sprout::detail::log_a_f());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
log_a(sprout::valarray<T, N> const& x, T const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::bind2nd(sprout::detail::log_a_f(), y));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
log_a(T const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(y.begin(), y.end(), y, sprout::bind1st(sprout::detail::log_a_f(), x));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_POWER_HPP
|
222
sprout/valarray/slice_array.hpp
Normal file
222
sprout/valarray/slice_array.hpp
Normal file
|
@ -0,0 +1,222 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2015 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_VALARRAY_SLICE_ARRAY_HPP
|
||||
#define SPROUT_VALARRAY_SLICE_ARRAY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/iterator/index_iterator.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/fill.hpp>
|
||||
#include <sprout/valarray/valarray_fwd.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// slice
|
||||
//
|
||||
class slice {
|
||||
private:
|
||||
std::size_t start_;
|
||||
std::size_t size_;
|
||||
std::size_t stride_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR slice()
|
||||
: start_(), size_(), stride_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR slice(std::size_t start, std::size_t size, std::size_t stride)
|
||||
: start_(start), size_(size), stride_(stride)
|
||||
{}
|
||||
SPROUT_CONSTEXPR std::size_t start() const {
|
||||
return start_;
|
||||
}
|
||||
SPROUT_CONSTEXPR std::size_t size() const {
|
||||
return size_;
|
||||
}
|
||||
SPROUT_CONSTEXPR std::size_t stride() const {
|
||||
return stride_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// slice_array
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
class slice_array {
|
||||
friend class sprout::valarray<T, N>;
|
||||
private:
|
||||
typedef sprout::valarray<T, N> valarray_type;
|
||||
public:
|
||||
typedef typename valarray_type::value_type value_type;
|
||||
typedef typename valarray_type::reference reference;
|
||||
typedef typename valarray_type::size_type size_type;
|
||||
typedef typename valarray_type::difference_type difference_type;
|
||||
typedef typename valarray_type::pointer pointer;
|
||||
typedef sprout::index_iterator<slice_array const&> iterator;
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR size_type static_size = valarray_type::static_size;
|
||||
private:
|
||||
sprout::value_holder<valarray_type&> arr_;
|
||||
sprout::slice slice_;
|
||||
private:
|
||||
slice_array() = delete;
|
||||
SPROUT_CONSTEXPR slice_array(sprout::valarray<T, N>& arr, sprout::slice const& slice)
|
||||
: arr_(arr), slice_(slice)
|
||||
{}
|
||||
public:
|
||||
SPROUT_CONSTEXPR slice_array(slice_array const& other)
|
||||
: arr_(other.arr_), slice_(other.slice_)
|
||||
{}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR slice_array const&
|
||||
operator=(slice_array<T, N2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
return *this;
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(sprout::valarray<T, N2> const& ar) const {
|
||||
sprout::copy(ar.begin(), ar.end(), begin());
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator=(T const& value) const {
|
||||
sprout::fill(begin(), end(), value);
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator+=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 += *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator-=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 -= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator*=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 *= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator/=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 /= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator%=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 %= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator&=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 &= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator|=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 |= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator^=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 ^= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator<<=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 <<= *it;
|
||||
}
|
||||
}
|
||||
template<std::size_t N2>
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
operator>>=(sprout::valarray<T, N2> const& xs) const {
|
||||
iterator it2 = begin();
|
||||
for (typename sprout::valarray<T, N2>::const_iterator it = xs.begin(), last = xs.end(); it != last; ++it, ++it2) {
|
||||
*it2 >>= *it;
|
||||
}
|
||||
}
|
||||
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
swap(slice_array& other) SPROUT_NOEXCEPT {
|
||||
sprout::swap(arr_, other.arr_);
|
||||
sprout::swap(slice_, other.slice_);
|
||||
}
|
||||
|
||||
// iterators:
|
||||
SPROUT_CONSTEXPR iterator
|
||||
begin() const {
|
||||
return iterator(*this, 0);
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator
|
||||
end() const {
|
||||
return iterator(*this, size());
|
||||
}
|
||||
// capacity:
|
||||
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
|
||||
return slice_.size();
|
||||
}
|
||||
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
|
||||
return size() == 0;
|
||||
}
|
||||
// element access:
|
||||
SPROUT_CONSTEXPR reference operator[](size_type i) const {
|
||||
return (*arr_)[slice_.start() + slice_.stride() * i];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference at(size_type i) const {
|
||||
return arr_->at(slice_.start() + slice_.stride() * i);
|
||||
}
|
||||
SPROUT_CONSTEXPR reference front() const {
|
||||
return (*this)[0];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference back() const {
|
||||
return (*this)[size() - 1];
|
||||
}
|
||||
};
|
||||
template<typename T, std::size_t N>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::slice_array<T, N>::size_type sprout::slice_array<T, N>::static_size;
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::slice_array<T, N>& lhs, sprout::slice_array<T, N>& rhs)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_SLICE_ARRAY_HPP
|
240
sprout/valarray/trigonometric.hpp
Normal file
240
sprout/valarray/trigonometric.hpp
Normal file
|
@ -0,0 +1,240 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_BITWISE_HPP
|
||||
#define SPROUT_VALARRAY_BITWISE_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/math/acos.hpp>
|
||||
#include <sprout/math/asin.hpp>
|
||||
#include <sprout/math/atan.hpp>
|
||||
#include <sprout/math/atan2.hpp>
|
||||
#include <sprout/math/cos.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/math/tan.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout_math_detail {
|
||||
using sprout::math::acos;
|
||||
using sprout::math::asin;
|
||||
using sprout::math::atan;
|
||||
using sprout::math::atan2;
|
||||
using sprout::math::cos;
|
||||
using sprout::math::sin;
|
||||
using sprout::math::tan;
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(acos(std::declval<T>()))
|
||||
call_acos(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(acos(std::declval<T>()))
|
||||
{
|
||||
return acos(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(asin(std::declval<T>()))
|
||||
call_asin(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(asin(std::declval<T>()))
|
||||
{
|
||||
return asin(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(atan(std::declval<T>()))
|
||||
call_atan(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(atan(std::declval<T>()))
|
||||
{
|
||||
return atan(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T, typename U>
|
||||
inline SPROUT_CONSTEXPR decltype(atan2(std::declval<T>(), std::declval<U>()))
|
||||
call_atan2(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(atan2(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return atan2(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, u));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(cos(std::declval<T>()))
|
||||
call_cos(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(cos(std::declval<T>()))
|
||||
{
|
||||
return cos(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(sin(std::declval<T>()))
|
||||
call_sin(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sin(std::declval<T>()))
|
||||
{
|
||||
return sin(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(tan(std::declval<T>()))
|
||||
call_tan(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(tan(std::declval<T>()))
|
||||
{
|
||||
return tan(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
struct acos_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_acos(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_acos(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_acos(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct asin_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_asin(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_asin(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_asin(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct atan_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_atan(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_atan(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_atan(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct atan2_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_atan2(std::declval<T>(), std::declval<U>()))
|
||||
operator()(T&& x, U&& y)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_atan2(std::declval<T>(), std::declval<U>()))
|
||||
{
|
||||
return sprout_math_detail::call_atan2(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y));
|
||||
}
|
||||
};
|
||||
struct cos_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_cos(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_cos(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_cos(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct sin_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_sin(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_sin(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_sin(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
struct tan_f
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(sprout_math_detail::call_tan(std::declval<T>()))
|
||||
operator()(T&& x)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_tan(std::declval<T>()))
|
||||
{
|
||||
return sprout_math_detail::call_tan(SPROUT_FORWARD(T, x));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// acos
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
acos(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::acos_f());
|
||||
}
|
||||
//
|
||||
// asin
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
asin(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::asin_f());
|
||||
}
|
||||
//
|
||||
// atan
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
atan(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::atan_f());
|
||||
}
|
||||
//
|
||||
// atan2
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
atan2(sprout::valarray<T, N> const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), y.end(), x, sprout::detail::atan2_f());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
atan2(sprout::valarray<T, N> const& lhs, T const& y) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::bind2nd(sprout::detail::atan2_f()()), y));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
atan2(T const& x, sprout::valarray<T, N> const& y) {
|
||||
return sprout::fixed::transform(y.begin(), y.end(), y, sprout::bind1st(sprout::detail::atan2_f()()), x));
|
||||
}
|
||||
//
|
||||
// cos
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
cos(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::cos_f());
|
||||
}
|
||||
//
|
||||
// sin
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
sin(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::sin_f());
|
||||
}
|
||||
//
|
||||
// tan
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
tan(sprout::valarray<T, N> const& x) {
|
||||
return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::tan_f());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_BITWISE_HPP
|
70
sprout/valarray/tuple.hpp
Normal file
70
sprout/valarray/tuple.hpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_TUPLE_HPP
|
||||
#define SPROUT_VALARRAY_TUPLE_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/tuple/tuple/get.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/detail/nil_base.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// tuple_get
|
||||
//
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR T&
|
||||
tuple_get(sprout::valarray<T, N>& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "tuple_get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
tuple_get(sprout::valarray<T, N> const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "tuple_get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR T&&
|
||||
tuple_get(sprout::valarray<T, N>&& t) SPROUT_NOEXCEPT {
|
||||
return sprout::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
struct tuple_size<sprout::valarray<T, N> >
|
||||
: public sprout::integral_constant<std::size_t, N>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
struct tuple_element<I, sprout::valarray<T, N> >
|
||||
: public std::conditional<(I < N), sprout::identity<T>, sprout::detail::nil_base>::type
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_TUPLE_HPP
|
43
sprout/valarray/type_traits.hpp
Normal file
43
sprout/valarray/type_traits.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*=============================================================================
|
||||
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_VALARRAY_TYPE_TRAITS_HPP
|
||||
#define SPROUT_VALARRAY_TYPE_TRAITS_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// is_valarray
|
||||
//
|
||||
template<typename T>
|
||||
struct is_valarray
|
||||
: public sprout::false_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_valarray<T const>
|
||||
: public sprout::is_valarray<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_valarray<T const volatile>
|
||||
: public sprout::is_valarray<T>
|
||||
{};
|
||||
template<typename T, std::size_t N>
|
||||
struct is_valarray<sprout::valarray<T, N> >
|
||||
: public sprout::true_type
|
||||
{};
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_valarray_v = sprout::is_valarray<T>::value;
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_TYPE_TRAITS_HPP
|
672
sprout/valarray/valarray.hpp
Normal file
672
sprout/valarray/valarray.hpp
Normal file
|
@ -0,0 +1,672 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2015 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_VALARRAY_VALARRAY_HPP
|
||||
#define SPROUT_VALARRAY_VALARRAY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
#include <initializer_list>
|
||||
#include <array>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/index_tuple/metafunction.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/math/less.hpp>
|
||||
#include <sprout/iterator/index_iterator.hpp>
|
||||
#include <sprout/iterator/reverse_iterator.hpp>
|
||||
#include <sprout/functional/negate.hpp>
|
||||
#include <sprout/functional/bit_not.hpp>
|
||||
#include <sprout/functional/logical_not.hpp>
|
||||
#include <sprout/functional/plus_assign.hpp>
|
||||
#include <sprout/functional/minus_assign.hpp>
|
||||
#include <sprout/functional/multiplies_assign.hpp>
|
||||
#include <sprout/functional/divides_assign.hpp>
|
||||
#include <sprout/functional/modulus_assign.hpp>
|
||||
#include <sprout/functional/bit_and_assign.hpp>
|
||||
#include <sprout/functional/bit_or_assign.hpp>
|
||||
#include <sprout/functional/bit_xor_assign.hpp>
|
||||
#include <sprout/functional/shift_left_assign.hpp>
|
||||
#include <sprout/functional/shift_right_assign.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/algorithm/min_element.hpp>
|
||||
#include <sprout/algorithm/max_element.hpp>
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
#include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/algorithm/fixed/rotate.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/fill.hpp>
|
||||
#include <sprout/algorithm/cxx14/for_each.hpp>
|
||||
#include <sprout/numeric/accumulate.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/value_holder/value_holder.hpp>
|
||||
#include <sprout/type_traits/is_nothrow_copy_constructible.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/valarray/valarray_fwd.hpp>
|
||||
#include <sprout/valarray/slice_array.hpp>
|
||||
#include <sprout/valarray/gslice_array.hpp>
|
||||
#include <sprout/valarray/mask_array.hpp>
|
||||
#include <sprout/valarray/indirect_array.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
struct valarray_raw_construct_t {};
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
class valarray_construct_access;
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
class valarray_impl {
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef sprout::array<value_type, N> array_type;
|
||||
public:
|
||||
static SPROUT_CONSTEXPR std::size_t
|
||||
checked_size(std::size_t n) {
|
||||
return N >= n ? n
|
||||
: throw std::length_error("valarray<>: length exceeded")
|
||||
;
|
||||
}
|
||||
public:
|
||||
array_type array_;
|
||||
std::size_t size_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR valarray_impl()
|
||||
: array_{{}}, size_(0)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR valarray_impl(std::size_t n)
|
||||
: array_{{}}, size_(checked_size(n))
|
||||
{}
|
||||
template<sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR valarray_impl(
|
||||
sprout::index_tuple<Indexes...>,
|
||||
value_type const& value, std::size_t n
|
||||
)
|
||||
: array_{{
|
||||
(sprout::math::less(Indexes, n) ? value
|
||||
: value_type()
|
||||
)...
|
||||
}}
|
||||
, size_(checked_size(n))
|
||||
{}
|
||||
template<typename RandomAccessIterator, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR valarray_impl(
|
||||
sprout::index_tuple<Indexes...>,
|
||||
RandomAccessIterator first, std::size_t n
|
||||
)
|
||||
: array_{{
|
||||
(sprout::math::less(Indexes, n) ? first[Indexes]
|
||||
: value_type()
|
||||
)...
|
||||
}}
|
||||
, size_(checked_size(n))
|
||||
{}
|
||||
valarray_impl(valarray_impl const& v) = default;
|
||||
valarray_impl(valarray_impl&& v) = default;
|
||||
template<typename... Args, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR valarray_impl(
|
||||
sprout::index_tuple<Indexes...>,
|
||||
sprout::detail::valarray_raw_construct_t, std::size_t n, Args&&... args
|
||||
)
|
||||
: array_{{
|
||||
(sprout::math::less(Indexes, n) ? static_cast<value_type>(SPROUT_FORWARD(Args, args))
|
||||
: value_type()
|
||||
)...
|
||||
}}
|
||||
, size_(n)
|
||||
{}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// valarray
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
class valarray {
|
||||
friend class sprout::detail::valarray_construct_access<T, N>;
|
||||
private:
|
||||
typedef sprout::detail::valarray_impl<T, N> impl_type;
|
||||
typedef typename impl_type::array_type array_type;
|
||||
public:
|
||||
typedef typename array_type::value_type value_type;
|
||||
typedef typename array_type::iterator iterator;
|
||||
typedef typename array_type::const_iterator const_iterator;
|
||||
typedef typename array_type::reference reference;
|
||||
typedef typename array_type::const_reference const_reference;
|
||||
typedef typename array_type::size_type size_type;
|
||||
typedef typename array_type::difference_type difference_type;
|
||||
typedef typename array_type::pointer pointer;
|
||||
typedef typename array_type::const_pointer const_pointer;
|
||||
typedef typename array_type::reverse_iterator reverse_iterator;
|
||||
typedef typename array_type::const_reverse_iterator const_reverse_iterator;
|
||||
typedef value_type result_type;
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR size_type static_size = N;
|
||||
private:
|
||||
impl_type impl_;
|
||||
private:
|
||||
template<typename... Args, typename Enable = typename std::enable_if<(sizeof...(Args) <= N)>::type>
|
||||
SPROUT_CONSTEXPR valarray(sprout::detail::valarray_raw_construct_t, size_type n, Args&&... args)
|
||||
: impl_(
|
||||
sprout::index_pack<Args...>::make(),
|
||||
sprout::detail::valarray_raw_construct_t(), n, SPROUT_FORWARD(Args, args)...
|
||||
)
|
||||
{}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
maxcheck(size_type n) const {
|
||||
if (n > max_size()) {
|
||||
throw std::out_of_range("valarray<>: index out of range");
|
||||
}
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
lengthcheck(size_type n) const {
|
||||
if (n > max_size()) {
|
||||
throw std::length_error("valarray<>: length exceeded");
|
||||
}
|
||||
}
|
||||
public:
|
||||
// construct/destroy:
|
||||
SPROUT_CONSTEXPR valarray() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL
|
||||
explicit SPROUT_CONSTEXPR valarray(std::size_t n)
|
||||
: impl_(n)
|
||||
{}
|
||||
SPROUT_CONSTEXPR valarray(value_type const& value, std::size_t n)
|
||||
: impl_(
|
||||
sprout::make_index_tuple<N>::make(),
|
||||
value, n
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR valarray(value_type const* first, std::size_t n)
|
||||
: impl_(
|
||||
sprout::make_index_tuple<N>::make(),
|
||||
first, n
|
||||
)
|
||||
{}
|
||||
valarray(valarray const&) = default;
|
||||
valarray(valarray&&) = default;
|
||||
SPROUT_INITIALIZER_LIST_CONSTEXPR valarray(std::initializer_list<value_type> il)
|
||||
: impl_(
|
||||
sprout::make_index_tuple<N>::make(),
|
||||
il.begin(), il.size()
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR valarray(sprout::slice_array<value_type, N> const& x)
|
||||
: impl_(
|
||||
sprout::make_index_tuple<N>::make(),
|
||||
x.begin(), x.size()
|
||||
)
|
||||
{}
|
||||
template<std::size_t M>
|
||||
SPROUT_CONSTEXPR valarray(sprout::gslice_array<value_type, N, M> const& x)
|
||||
: impl_(
|
||||
sprout::make_index_tuple<N>::make(),
|
||||
x.begin(), x.size()
|
||||
)
|
||||
{}
|
||||
template<std::size_t M>
|
||||
SPROUT_CONSTEXPR valarray(sprout::mask_array<value_type, N, M> const& x)
|
||||
: impl_(
|
||||
sprout::make_index_tuple<N>::make(),
|
||||
x.begin(), x.size()
|
||||
)
|
||||
{}
|
||||
template<std::size_t M>
|
||||
SPROUT_CONSTEXPR valarray(sprout::indirect_array<value_type, N, M> const& x)
|
||||
: impl_(
|
||||
sprout::make_index_tuple<N>::make(),
|
||||
x.begin(), x.size()
|
||||
)
|
||||
{}
|
||||
// assignment:
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(valarray const& rhs) {
|
||||
impl_.array_ = rhs.array_;
|
||||
impl_.size_ = rhs.size_;
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(valarray&& rhs) SPROUT_NOEXCEPT {
|
||||
impl_.array_ = sprout::move(rhs.array_);
|
||||
impl_.size_ = sprout::move(rhs.size_);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(value_type const& rhs) {
|
||||
impl_.array_.fill(rhs);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(std::initializer_list<value_type> rhs) {
|
||||
lengthcheck(rhs.size());
|
||||
sprout::copy(rhs.begin(), rhs.end(), begin());
|
||||
impl_.size_ = rhs.size();
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(sprout::slice_array<value_type, N> const& rhs) {
|
||||
lengthcheck(rhs.size());
|
||||
sprout::copy(rhs.begin(), rhs.end(), begin());
|
||||
impl_.size_ = rhs.size();
|
||||
return *this;
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(sprout::gslice_array<value_type, N, M> const& rhs) {
|
||||
lengthcheck(rhs.size());
|
||||
sprout::copy(rhs.begin(), rhs.end(), begin());
|
||||
impl_.size_ = rhs.size();
|
||||
return *this;
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(sprout::mask_array<value_type, N, M> const& rhs) {
|
||||
lengthcheck(rhs.size());
|
||||
sprout::copy(rhs.begin(), rhs.end(), begin());
|
||||
impl_.size_ = rhs.size();
|
||||
return *this;
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator=(sprout::indirect_array<value_type, N, M> const& rhs) {
|
||||
lengthcheck(rhs.size());
|
||||
sprout::copy(rhs.begin(), rhs.end(), begin());
|
||||
impl_.size_ = rhs.size();
|
||||
return *this;
|
||||
}
|
||||
// element access:
|
||||
SPROUT_CONSTEXPR value_type const&
|
||||
operator[](std::size_t i) const {
|
||||
return impl_.array_[i];
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR value_type&
|
||||
operator[](std::size_t i) {
|
||||
return impl_.array_[i];
|
||||
}
|
||||
// subset operations:
|
||||
SPROUT_CONSTEXPR valarray
|
||||
operator[](sprout::slice s) const {
|
||||
return valarray(sprout::slice_array<value_type, N>(const_cast<valarray&>(*this), s));
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR sprout::slice_array<value_type, N>
|
||||
operator[](sprout::slice s) {
|
||||
return sprout::slice_array<value_type, N>(*this, s);
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CONSTEXPR valarray
|
||||
operator[](sprout::gslice<M> const& gs) const {
|
||||
return valarray(sprout::gslice_array<value_type, N, M>(const_cast<valarray&>(*this), gs));
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CXX14_CONSTEXPR sprout::gslice_array<value_type, N, M>
|
||||
operator[](sprout::gslice<M> const& gs) {
|
||||
return sprout::gslice_array<value_type, N, M>(*this, gs);
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CONSTEXPR valarray
|
||||
operator[](valarray<bool, M> const& vb) const {
|
||||
return valarray(sprout::mask_array<value_type, N, M>(const_cast<valarray&>(*this), vb));
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CXX14_CONSTEXPR sprout::mask_array<value_type, N, M>
|
||||
operator[](valarray<bool, M> const& vb) {
|
||||
return sprout::mask_array<value_type, N, M>(*this, vb);
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CONSTEXPR valarray
|
||||
operator[](valarray<std::size_t, M> const& vs) const {
|
||||
return valarray(sprout::indirect_array<value_type, N, M>(const_cast<valarray&>(*this), vs));
|
||||
}
|
||||
template<std::size_t M>
|
||||
SPROUT_CXX14_CONSTEXPR sprout::indirect_array<value_type, N, M>
|
||||
operator[](valarray<std::size_t, M> const& vs) {
|
||||
return sprout::indirect_array<value_type, N, M>(*this, vs);
|
||||
}
|
||||
// unary operators:
|
||||
SPROUT_CONSTEXPR valarray
|
||||
operator+() const {
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray
|
||||
operator-() const {
|
||||
return sprout::fixed::transform(begin(), end(), *this, sprout::negate<>());
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray
|
||||
operator~() const {
|
||||
return sprout::fixed::transform(begin(), end(), *this, sprout::bit_not<>());
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray<bool, N>
|
||||
operator!() const {
|
||||
return sprout::fixed::transform<valarray<bool, N> >(begin(), end(), sprout::logical_not<>());
|
||||
}
|
||||
// computed assignment:
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator*=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::multiplies_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator/=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::divides_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator%=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::modulus_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator+=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::plus_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator-=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::minus_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator^=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::bit_xor_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator&=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::bit_and_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator|=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::bit_or_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator<<=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::shift_left_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR valarray&
|
||||
operator>>=(value_type const& x) {
|
||||
sprout::for_each(begin(), end(), sprout::bind2nd(sprout::shift_right_assign<>(), x));
|
||||
return *this;
|
||||
}
|
||||
// member functions:
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
swap(valarray& other) SPROUT_NOEXCEPT {
|
||||
sprout::swap(impl_.array_, other.impl_.array_);
|
||||
sprout::swap(impl_.size_, other.impl_.size_);
|
||||
}
|
||||
SPROUT_CONSTEXPR std::size_t
|
||||
size() const {
|
||||
return impl_.size_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type
|
||||
sum() const {
|
||||
return sprout::accumulate(begin(), end(), value_type());
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type
|
||||
min() const {
|
||||
return *sprout::min_element(begin(), end());
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type
|
||||
max() const {
|
||||
return *sprout::max_element(begin(), end());
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray
|
||||
shift(int i) const {
|
||||
return i > 0 ? sprout::fixed::copy(begin() + i, end(), *this)
|
||||
: i < 0 ? sprout::fixed::copy_backward(begin(), end() + i, *this)
|
||||
: *this
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray
|
||||
cshift(int i) const {
|
||||
return i > 0 ? sprout::fixed::rotate(*this, begin() + i)
|
||||
: i < 0 ? sprout::fixed::rotate(*this, end() + i)
|
||||
: *this
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray
|
||||
apply(value_type func(value_type)) const {
|
||||
return sprout::fixed::transform(begin(), end(), *this, func);
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray
|
||||
apply(value_type func(value_type const&)) const {
|
||||
return sprout::fixed::transform(begin(), end(), *this, func);
|
||||
}
|
||||
template<typename F>
|
||||
SPROUT_CONSTEXPR valarray
|
||||
apply(F func) const {
|
||||
return sprout::fixed::transform(begin(), end(), *this, func);
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
resize(std::size_t n, value_type x = value_type()) {
|
||||
lengthcheck(n);
|
||||
impl_.size_ = n;
|
||||
impl_.array_.fill(x);
|
||||
}
|
||||
|
||||
// modifiers (array):
|
||||
SPROUT_CXX14_CONSTEXPR void fill(const_reference value) {
|
||||
impl_.array_.fill(value);
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray fill(const_reference value) const {
|
||||
return valarray(value, size());
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void assign(const_reference value) {
|
||||
impl_.array_.assign(value);
|
||||
}
|
||||
SPROUT_CONSTEXPR valarray assign(const_reference value) const {
|
||||
return valarray(value, size());
|
||||
}
|
||||
// iterators (array):
|
||||
SPROUT_CXX14_CONSTEXPR iterator begin() SPROUT_NOEXCEPT {
|
||||
return impl_.array_.begin();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.begin();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR iterator end() SPROUT_NOEXCEPT {
|
||||
return impl_.array_.begin() + size();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.begin() + size();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR reverse_iterator rbegin() SPROUT_NOEXCEPT {
|
||||
return impl_.array_.rend() - size();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.rend() - size();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR reverse_iterator rend() SPROUT_NOEXCEPT {
|
||||
return impl_.array_.rend();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.rend();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.cbegin();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.cbegin() + size();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.crend() - size();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reverse_iterator crend() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.crend();
|
||||
}
|
||||
// capacity (array):
|
||||
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.max_size();
|
||||
}
|
||||
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
|
||||
return size() != 0;
|
||||
}
|
||||
// element access (array):
|
||||
SPROUT_CXX14_CONSTEXPR reference at(size_type i) {
|
||||
return i < size() ? (*this)[i]
|
||||
: (throw std::out_of_range("valarray<>: index out of range"), (*this)[i])
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference at(size_type i) const {
|
||||
return i < size() ? (*this)[i]
|
||||
: (throw std::out_of_range("valarray<>: index out of range"), (*this)[i])
|
||||
;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR reference front() {
|
||||
return impl_.array_.front();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference front() const {
|
||||
return impl_.array_.front();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR reference back() {
|
||||
return (*this)[size() - 1];
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference back() const {
|
||||
return (*this)[size() - 1];
|
||||
}
|
||||
|
||||
SPROUT_CXX14_CONSTEXPR pointer data() SPROUT_NOEXCEPT {
|
||||
return impl_.array_.data();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_pointer data() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.data();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR pointer c_array() SPROUT_NOEXCEPT {
|
||||
return impl_.array_.c_array();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_pointer c_array() const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.c_array();
|
||||
}
|
||||
// others (array):
|
||||
SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const {
|
||||
return i >= size() ? throw std::out_of_range("valarray<>: index out of range")
|
||||
: (void)0
|
||||
;
|
||||
}
|
||||
|
||||
SPROUT_CXX14_CONSTEXPR iterator nth(size_type i) {
|
||||
return i < size() ? begin() + i
|
||||
: (throw std::out_of_range("valarray<>: index out of range"), iterator())
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator nth(size_type i) const {
|
||||
return i < size() ? begin() + i
|
||||
: (throw std::out_of_range("valarray<>: index out of range"), const_iterator())
|
||||
;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR size_type index_of(iterator p) SPROUT_NOEXCEPT {
|
||||
return impl_.array_.index_of(p);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type index_of(const_iterator p) const SPROUT_NOEXCEPT {
|
||||
return impl_.array_.index_of(p);
|
||||
}
|
||||
};
|
||||
template<typename T, std::size_t N>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::valarray<T, N>::size_type sprout::valarray<T, N>::static_size;
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::valarray<T, N>& lhs, sprout::valarray<T, N>& rhs)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename T, std::size_t N>
|
||||
class valarray_construct_access {
|
||||
public:
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
raw_construct(typename sprout::valarray<T, N>::size_type n, Args&&... args) {
|
||||
return sprout::valarray<T, N>(sprout::detail::valarray_raw_construct_t(), n, SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Container>
|
||||
struct make_construct_impl;
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
struct make_construct_impl<sprout::valarray<T, N> > {
|
||||
private:
|
||||
typedef sprout::valarray<T, N> copied_type;
|
||||
public:
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type
|
||||
make(Args&&... args) {
|
||||
typedef sprout::detail::valarray_construct_access<T, N> access_type;
|
||||
return access_type::raw_construct(sizeof...(args), SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type
|
||||
sized_make(typename copied_type::size_type size, Args&&... args) {
|
||||
typedef sprout::detail::valarray_construct_access<T, N> access_type;
|
||||
return access_type::raw_construct(size, SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// to_valarray
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
to_valarray(sprout::valarray<T, N> const& arr)
|
||||
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<T>::value)
|
||||
{
|
||||
return arr;
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<typename std::remove_cv<T>::type, N>
|
||||
to_valarray(T (& arr)[N])
|
||||
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<typename std::remove_cv<T>::type>::value)
|
||||
{
|
||||
return sprout::valarray<typename std::remove_cv<T>::type, N>(arr, N);
|
||||
}
|
||||
namespace detail {
|
||||
template<typename T, std::size_t N, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
to_valarray_impl(std::array<T, N> const& arr, sprout::index_tuple<Indexes...>)
|
||||
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<T>::value)
|
||||
{
|
||||
typedef sprout::detail::make_construct_impl<sprout::valarray<T, N> > construct_type;
|
||||
return construct_type::make(arr[Indexes]...);
|
||||
}
|
||||
} // namespace detail
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
to_valarray(std::array<T, N> const& arr)
|
||||
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<T>::value)
|
||||
{
|
||||
return sprout::detail::to_valarray_impl(arr, sprout::make_index_tuple<N>::make());
|
||||
}
|
||||
namespace detail {
|
||||
template<typename T, std::size_t N, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
to_valarray_impl(sprout::array<T, N> const& arr, sprout::index_tuple<Indexes...>)
|
||||
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<T>::value)
|
||||
{
|
||||
typedef sprout::detail::make_construct_impl<sprout::valarray<T, N> > construct_type;
|
||||
return construct_type::make(arr[Indexes]...);
|
||||
}
|
||||
} // namespace detail
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
to_valarray(sprout::array<T, N> const& arr)
|
||||
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<T>::value)
|
||||
{
|
||||
return sprout::detail::to_valarray_impl(arr, sprout::make_index_tuple<N>::make());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_VALARRAY_HPP
|
56
sprout/valarray/valarray_fwd.hpp
Normal file
56
sprout/valarray/valarray_fwd.hpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2015 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_VALARRAY_VALARRAY_FWD_HPP
|
||||
#define SPROUT_VALARRAY_VALARRAY_FWD_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// valarray
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
class valarray;
|
||||
|
||||
//
|
||||
// slice
|
||||
//
|
||||
class slice;
|
||||
//
|
||||
// slice_array
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
class slice_array;
|
||||
|
||||
//
|
||||
// gslice
|
||||
//
|
||||
template<std::size_t N>
|
||||
class gslice;
|
||||
//
|
||||
// gslice_array
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
class gslice_array;
|
||||
|
||||
//
|
||||
// mask_array
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
class mask_array;
|
||||
|
||||
//
|
||||
// indirect_array
|
||||
//
|
||||
template<typename T, std::size_t N, std::size_t M>
|
||||
class indirect_array;
|
||||
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_VALARRAY_FWD_HPP
|
Loading…
Add table
Reference in a new issue