fix io fromat from int

add range::sinusoidal
fix algorithm random_access_iterator parformance
This commit is contained in:
bolero-MURAKAMI 2012-04-30 19:41:24 +09:00
parent 3ff16b4054
commit cb830f141d
14 changed files with 438 additions and 12 deletions

View file

@ -30,7 +30,7 @@ namespace sprout {
result,
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? *sprout::next(first, Indexes - offset)
? first[Indexes - offset]
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);

View file

@ -31,7 +31,7 @@ namespace sprout {
result,
sprout::size(result),
(Indexes < offset && Indexes + size >= static_cast<std::size_t>(offset) && Indexes + input_size >= static_cast<std::size_t>(offset)
? *sprout::next(last, Indexes - offset)
? last[Indexes - offset]
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);

View file

@ -33,7 +33,7 @@ namespace sprout {
result,
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? NS_SSCRISK_CEL_OR_SPROUT::equal_to<T>()(*sprout::next(first, Indexes - offset), old_value) ? new_value : *sprout::next(first, Indexes - offset)
? NS_SSCRISK_CEL_OR_SPROUT::equal_to<T>()(first[Indexes - offset], old_value) ? new_value : first[Indexes - offset]
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);

View file

@ -32,7 +32,7 @@ namespace sprout {
result,
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? pred(*sprout::next(first, Indexes - offset)) ? new_value : *sprout::next(first, Indexes - offset)
? pred(first[Indexes - offset]) ? new_value : first[Indexes - offset]
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);

View file

@ -30,7 +30,7 @@ namespace sprout {
result,
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? *sprout::prev(last, 1 + Indexes - offset)
? last[-(1 + Indexes - offset)]
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);

View file

@ -32,8 +32,8 @@ namespace sprout {
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? (Indexes < offset + NS_SSCRISK_CEL_OR_SPROUT::distance(middle, last)
? *sprout::next(middle, Indexes - offset)
: *sprout::prev(sprout::next(first, Indexes - offset), NS_SSCRISK_CEL_OR_SPROUT::distance(first, middle))
? middle[Indexes - offset]
: first[(Indexes - offset) - NS_SSCRISK_CEL_OR_SPROUT::distance(first, middle)]
)
: *sprout::next(sprout::internal_begin(result), Indexes)
)...

View file

@ -36,7 +36,7 @@ namespace sprout {
? *pos2
: sprout::next(first, Indexes - offset) == pos2
? *pos1
: *sprout::next(first, Indexes - offset)
: first[Indexes - offset]
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);

View file

@ -31,7 +31,7 @@ namespace sprout {
result,
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? op(*sprout::next(first, Indexes - offset))
? op(first[Indexes - offset])
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);
@ -134,7 +134,7 @@ namespace sprout {
result,
sprout::size(result),
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
? op(*sprout::next(first1, Indexes - offset), *sprout::next(first2, Indexes - offset))
? op(first1[Indexes - offset], first2[Indexes - offset])
: *sprout::next(sprout::internal_begin(result), Indexes)
)...
);

View file

@ -674,7 +674,10 @@ namespace sprout {
//
template<
typename Elem, std::size_t N, typename T,
typename sprout::enabler_if<std::is_integral<T>::value>::type = sprout::enabler
typename sprout::enabler_if<
std::is_integral<T>::value
&& !sprout::weed::traits::is_char_type<T>::value
>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR auto
eval(sprout::io::format_holder<T> const& holder)

View file

@ -113,6 +113,7 @@ namespace sprout {
swap(deref_tmp, other.deref_tmp);
}
};
template<typename Iterator1, typename Iterator2>
SPROUT_CONSTEXPR bool operator==(
sprout::reverse_iterator<Iterator1> const& lhs,

View file

@ -0,0 +1,272 @@
#ifndef SPROUT_ITERATOR_SINUSOID_ITERATOR_HPP
#define SPROUT_ITERATOR_SINUSOID_ITERATOR_HPP
#include <cstddef>
#include <cmath>
#include <iterator>
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/iterator/prev.hpp>
#include <sprout/iterator/distance.hpp>
#include <sprout/math/constants.hpp>
namespace sprout {
//
// sinusoid_iterator
//
template<typename Value>
class sinusoid_iterator
: public std::iterator<
std::random_access_iterator_tag,
Value,
std::ptrdiff_t,
Value*,
Value
>
{
public:
typedef std::random_access_iterator_tag iterator_category;
typedef Value value_type;
typedef std::ptrdiff_t difference_type;
typedef value_type* pointer;
typedef value_type reference;
private:
value_type frequency_;
value_type amplitude_;
difference_type index_;
value_type d_;
private:
explicit SPROUT_CONSTEXPR sinusoid_iterator(sinusoid_iterator const& other, difference_type index)
: frequency_(other.frequency_)
, amplitude_(other.amplitude_)
, index_(index)
, d_(other.d_)
{}
public:
SPROUT_CONSTEXPR sinusoid_iterator()
: frequency_(1)
, amplitude_(1)
, index_()
, d_(value_type(2) * sprout::math::pi<value_type>())
{}
sinusoid_iterator(sinusoid_iterator const&) = default;
explicit SPROUT_CONSTEXPR sinusoid_iterator(
value_type const& frequency,
value_type const& amplitude = 1,
difference_type index = 0
)
: frequency_(frequency)
, amplitude_(amplitude)
, index_(index)
, d_(value_type(2) * sprout::math::pi<value_type>() * frequency)
{}
template<typename U>
SPROUT_CONSTEXPR sinusoid_iterator(sinusoid_iterator<U> const& it)
: frequency_(it.frequency_)
, amplitude_(it.amplitude_)
, index_(it.index_)
, d_(it.d_)
{}
template<typename U>
sinusoid_iterator& operator=(sinusoid_iterator<U> const& it) {
sinusoid_iterator temp(it);
temp.swap(*this);
return *this;
}
SPROUT_CONSTEXPR difference_type index() const {
return index_;
}
SPROUT_CONSTEXPR value_type const& frequency() const {
return frequency_;
}
SPROUT_CONSTEXPR value_type const& amplitude() const {
return amplitude_;
}
SPROUT_CONSTEXPR reference operator*() const {
using std::sin;
return amplitude_ * sin(d_ * value_type(index_));
}
SPROUT_CONSTEXPR pointer operator->() const {
return &operator*()();
}
sinusoid_iterator& operator++() {
++index_;
return *this;
}
sinusoid_iterator operator++(int) {
sinusoid_iterator result(*this);
++index_;
return result;
}
sinusoid_iterator& operator--() {
--index_;
return *this;
}
sinusoid_iterator operator--(int) {
sinusoid_iterator temp(*this);
--index_;
return temp;
}
SPROUT_CONSTEXPR sinusoid_iterator operator+(difference_type n) const {
return sinusoid_iterator(*this, index_ + n);
}
SPROUT_CONSTEXPR sinusoid_iterator operator-(difference_type n) const {
return sinusoid_iterator(*this, index_ - n);
}
sinusoid_iterator& operator+=(difference_type n) {
sinusoid_iterator temp(*this, index_ + n);
temp.swap(*this);
return *this;
}
sinusoid_iterator& operator-=(difference_type n) {
sinusoid_iterator temp(*this, index_ - n);
temp.swap(*this);
return *this;
}
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
using std::sin;
return amplitude_ * sin(d_ * value_type(index_ + n));
}
SPROUT_CONSTEXPR sinusoid_iterator next() const {
return sinusoid_iterator(*this, index_ + 1);
}
SPROUT_CONSTEXPR sinusoid_iterator prev() const {
return sinusoid_iterator(*this, index_ - 1);
}
void swap(sinusoid_iterator& other) {
using std::swap;
swap(frequency_, other.frequency_);
swap(amplitude_, other.amplitude_);
swap(index_, other.index_);
swap(d_, other.d_);
}
};
template<typename Value1, typename Value2>
SPROUT_CONSTEXPR bool operator==(
sprout::sinusoid_iterator<Value1> const& lhs,
sprout::sinusoid_iterator<Value2> const& rhs
)
{
return lhs.index() == rhs.index();
}
template<typename Value1, typename Value2>
SPROUT_CONSTEXPR bool operator!=(
sprout::sinusoid_iterator<Value1> const& lhs,
sprout::sinusoid_iterator<Value2> const& rhs
)
{
return !(lhs == rhs);
}
template<typename Value1, typename Value2>
SPROUT_CONSTEXPR bool operator<(
sprout::sinusoid_iterator<Value1> const& lhs,
sprout::sinusoid_iterator<Value2> const& rhs
)
{
return lhs.index() < rhs.index();
}
template<typename Value1, typename Value2>
SPROUT_CONSTEXPR bool operator>(
sprout::sinusoid_iterator<Value1> const& lhs,
sprout::sinusoid_iterator<Value2> const& rhs
)
{
return rhs < lhs;
}
template<typename Value1, typename Value2>
SPROUT_CONSTEXPR bool operator<=(
sprout::sinusoid_iterator<Value1> const& lhs,
sprout::sinusoid_iterator<Value2> const& rhs
)
{
return !(rhs < lhs);
}
template<typename Value1, typename Value2>
SPROUT_CONSTEXPR bool operator>=(
sprout::sinusoid_iterator<Value1> const& lhs,
sprout::sinusoid_iterator<Value2> const& rhs
)
{
return !(lhs < rhs);
}
template<typename Value1, typename Value2>
SPROUT_CONSTEXPR typename sprout::sinusoid_iterator<Value1>::difference_type operator-(
sprout::sinusoid_iterator<Value1> const& lhs,
sprout::sinusoid_iterator<Value2> const& rhs
)
{
return lhs.index() - rhs.index();
}
template<typename Value>
SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value> operator+(
typename sprout::sinusoid_iterator<Value>::difference_type n,
sprout::sinusoid_iterator<Value> const& it
)
{
return it + n;
}
//
// swap
//
template<typename Value>
void swap(sprout::sinusoid_iterator<Value>& lhs, sprout::sinusoid_iterator<Value>& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {
lhs.swap(rhs);
}
//
// next
//
template<typename Value>
SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value> next(
sprout::sinusoid_iterator<Value> const& it
)
{
return it.next();
}
template<typename Value>
SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value> next(
sprout::sinusoid_iterator<Value> const& it,
typename sprout::sinusoid_iterator<Value>::difference_type n
)
{
return it + n;
}
//
// prev
//
template<typename Value>
SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value> prev(
sprout::sinusoid_iterator<Value> const& it
)
{
return it.prev();
}
template<typename Value>
SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value> prev(
sprout::sinusoid_iterator<Value> const& it,
typename sprout::sinusoid_iterator<Value>::difference_type n
)
{
return it - n;
}
//
// distance
//
template<typename Value>
SPROUT_CONSTEXPR typename std::iterator_traits<sprout::sinusoid_iterator<Value> >::difference_type
distance(
sprout::sinusoid_iterator<Value> first,
sprout::sinusoid_iterator<Value> last
)
{
return last - first;
}
} // namespace sprout
#endif // #ifndef SPROUT_ITERATOR_SINUSOID_ITERATOR_HPP

View file

@ -3,5 +3,6 @@
#include <sprout/config.hpp>
#include <sprout/range/adaptor/transformed.hpp>
#include <sprout/range/adaptor/sinusoidal.hpp>
#endif // #ifndef SPROUT_RANGE_ADAPTOR_HPP

View file

@ -0,0 +1,149 @@
#ifndef SPROUT_RANGE_ADAPTOR_SINUSOIDAL_HPP
#define SPROUT_RANGE_ADAPTOR_SINUSOIDAL_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/pit.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/sinusoid_iterator.hpp>
#include <sprout/range/range_container.hpp>
#include <sprout/range/algorithm/copy.hpp>
#include <sprout/type_traits/lvalue_reference.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/lvalue_forward.hpp>
#include <sprout/utility/value_holder.hpp>
namespace sprout {
namespace range {
//
// sinusoidal_range
//
template<typename Value, typename Range = void>
class sinusoidal_range
: public sprout::range::range_container<
sprout::sinusoid_iterator<Value>
>
, public sprout::detail::inherit_if_fixed_size<Range>
{
public:
typedef Range range_type;
typedef sprout::range::range_container<
sprout::sinusoid_iterator<Value>
> base_type;
typedef typename base_type::iterator iterator;
typedef typename base_type::value_type value_type;
typedef typename base_type::difference_type difference_type;
public:
sinusoidal_range() = default;
sinusoidal_range(sinusoidal_range const&) = default;
explicit SPROUT_CONSTEXPR sinusoidal_range(
range_type& range,
value_type const& frequency = 1,
value_type const& amplitude = 1
)
: base_type(
iterator(frequency, amplitude, 0),
iterator(frequency, amplitude, sprout::size(range))
)
{}
};
template<typename Value>
class sinusoidal_range<Value, void>
: public sprout::range::range_container<
sprout::sinusoid_iterator<Value>
>
{
public:
typedef sprout::range::range_container<
sprout::sinusoid_iterator<Value>
> base_type;
typedef typename base_type::iterator iterator;
typedef typename base_type::value_type value_type;
typedef typename base_type::difference_type difference_type;
public:
sinusoidal_range() = default;
sinusoidal_range(sinusoidal_range const&) = default;
explicit SPROUT_CONSTEXPR sinusoidal_range(
value_type const& frequency = 1,
value_type const& amplitude = 1
)
: base_type(
iterator(frequency, amplitude, 0),
iterator(frequency, amplitude, -1)
)
{}
};
//
// sinusoidal_forwarder
//
class sinusoidal_forwarder {
public:
template<typename Value>
SPROUT_CONSTEXPR sprout::range::sinusoidal_range<Value>
operator()(
Value const& frequency = 1,
Value const& amplitude = 1
)
{
return sprout::range::sinusoidal_range<Value>(frequency, amplitude);
}
};
//
// sinusoidal
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::range::sinusoidal_forwarder sinusoidal{};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename Value>
inline SPROUT_CONSTEXPR sprout::range::sinusoidal_range<
Value,
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
>
operator|(Range&& lhs, sprout::range::sinusoidal_range<Value> const& rhs) {
return sprout::range::sinusoidal_range<
Value,
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
>(
sprout::lvalue_forward<Range>(lhs),
rhs.frequency(),
rhs.amplitude()
);
}
} // namespace range
//
// container_construct_traits
//
template<typename Value, typename Range>
struct container_construct_traits<sprout::range::sinusoidal_range<Value, Range> > {
public:
typedef typename sprout::container_construct_traits<Range>::copied_type copied_type;
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
return sprout::range::fixed::copy(sprout::forward<Cont>(cont), sprout::pit<copied_type>());
}
template<typename... Args>
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
return sprout::make<copied_type>(sprout::forward<Args>(args)...);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type remake(
Cont&& cont,
typename sprout::container_traits<sprout::range::sinusoidal_range<Value, Range> >::difference_type size,
Args&&... args
)
{
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_ADAPTOR_SINUSOIDAL_HPP

View file

@ -77,7 +77,7 @@ namespace sprout {
//
template<
typename Elem,
int Base,
int Base = 10,
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>