mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix weed warnings.
add compost library.
This commit is contained in:
parent
ac80a04970
commit
d01ee064e2
31 changed files with 1566 additions and 120 deletions
10
sprout/compost.hpp
Normal file
10
sprout/compost.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef SPROUT_COMPOST_HPP
|
||||
#define SPROUT_COMPOST_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/compost/waves.hpp>
|
||||
#include <sprout/compost/effects.hpp>
|
||||
#include <sprout/compost/formats.hpp>
|
||||
#include <sprout/compost/sources.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_HPP
|
10
sprout/compost/effects.hpp
Normal file
10
sprout/compost/effects.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/compost/effects/clip.hpp>
|
||||
#include <sprout/compost/effects/change_volume.hpp>
|
||||
#include <sprout/compost/effects/distort.hpp>
|
||||
#include <sprout/compost/effects/synthesize.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_HPP
|
71
sprout/compost/effects/change_volume.hpp
Normal file
71
sprout/compost/effects/change_volume.hpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_CHANGE_VOLUME_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_CHANGE_VOLUME_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/multiplies.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace effects {
|
||||
//
|
||||
// change_volume_holder
|
||||
//
|
||||
template<typename T>
|
||||
class change_volume_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
private:
|
||||
value_type value_;
|
||||
public:
|
||||
change_volume_holder() = default;
|
||||
change_volume_holder(change_volume_holder const&) = default;
|
||||
explicit SPROUT_CONSTEXPR change_volume_holder(value_type const& value)
|
||||
: value_(value)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& value() const {
|
||||
return value_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// changed_volume_forwarder
|
||||
//
|
||||
class changed_volume_forwarder {
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::change_volume_holder<T>
|
||||
operator()(T const& value) {
|
||||
return sprout::compost::effects::change_volume_holder<T>(value);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// changed_volume
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::changed_volume_forwarder changed_volume{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::change_volume_holder<T> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::bind2nd(sprout::multiplies<>(), rhs.value()))
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::bind2nd(sprout::multiplies<>(), rhs.value()))
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_CHANGE_VOLUME_HPP
|
85
sprout/compost/effects/clip.hpp
Normal file
85
sprout/compost/effects/clip.hpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_CLIP_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_CLIP_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/adaptor/clamped.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace effects {
|
||||
//
|
||||
// clip_holder
|
||||
//
|
||||
template<typename T>
|
||||
class clip_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
private:
|
||||
value_type low_;
|
||||
value_type up_;
|
||||
public:
|
||||
clip_holder() = default;
|
||||
clip_holder(clip_holder const&) = default;
|
||||
explicit SPROUT_CONSTEXPR clip_holder(value_type const& low = -1, value_type const& up = 1)
|
||||
: low_(low), up_(up)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& lower() const {
|
||||
return low_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& upper() const {
|
||||
return up_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// clipped_forwarder
|
||||
//
|
||||
class clipped_forwarder {
|
||||
public:
|
||||
template<typename T = double>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::clip_holder<T>
|
||||
operator()(T const& low = -1, T const& up = 1) {
|
||||
return sprout::compost::effects::clip_holder<T>(low, up);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// clipped
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::clipped_forwarder clipped{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::clip_holder<T> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::clamped(rhs.lower(), rhs.upper())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::clamped(rhs.lower(), rhs.upper())
|
||||
;
|
||||
}
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::clipped_forwarder const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::clamped(-1., 1.)
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::clamped(-1., 1.)
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_CLIP_HPP
|
78
sprout/compost/effects/distort.hpp
Normal file
78
sprout/compost/effects/distort.hpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_DISTORT_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_DISTORT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/compost/effects/clip.hpp>
|
||||
#include <sprout/compost/effects/change_volume.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace effects {
|
||||
//
|
||||
// distort_holder
|
||||
//
|
||||
template<typename T>
|
||||
class distort_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
private:
|
||||
value_type gain_;
|
||||
value_type level_;
|
||||
public:
|
||||
distort_holder() = default;
|
||||
distort_holder(distort_holder const&) = default;
|
||||
SPROUT_CONSTEXPR distort_holder(value_type const& gain, value_type const& level)
|
||||
: gain_(gain) , level_(level)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& gain() const {
|
||||
return gain_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& level() const {
|
||||
return level_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// distorted_forwarder
|
||||
//
|
||||
class distorted_forwarder {
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::distort_holder<T>
|
||||
operator()(T const& gain, T const& level) {
|
||||
return sprout::compost::effects::distort_holder<T>(gain, level);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// distorted
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::distorted_forwarder distorted{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::distort_holder<T> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::compost::effects::changed_volume(rhs.gain())
|
||||
| sprout::compost::effects::clipped()
|
||||
| sprout::compost::effects::changed_volume(rhs.level())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::compost::effects::changed_volume(rhs.gain())
|
||||
| sprout::compost::effects::clipped()
|
||||
| sprout::compost::effects::changed_volume(rhs.level())
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_DISTORT_HPP
|
77
sprout/compost/effects/synthesize.hpp
Normal file
77
sprout/compost/effects/synthesize.hpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_SYNTHESIZED_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_SYNTHESIZED_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/plus.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/value_holder.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace effects {
|
||||
//
|
||||
// synthesize_holder
|
||||
//
|
||||
template<typename RRange>
|
||||
class synthesize_holder {
|
||||
public:
|
||||
typedef RRange range2_type;
|
||||
private:
|
||||
sprout::value_holder<range2_type&> range_;
|
||||
public:
|
||||
synthesize_holder() = default;
|
||||
synthesize_holder(synthesize_holder const&) = default;
|
||||
explicit SPROUT_CONSTEXPR synthesize_holder(range2_type& range)
|
||||
: range_(range)
|
||||
{}
|
||||
SPROUT_CONSTEXPR range2_type& range() const {
|
||||
return range_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// synthesized_forwarder
|
||||
//
|
||||
class synthesized_forwarder {
|
||||
public:
|
||||
template<typename RRange>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::synthesize_holder<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
|
||||
>
|
||||
operator()(RRange&& range) {
|
||||
return sprout::compost::effects::synthesize_holder<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<RRange>(range)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// synthesized
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::synthesized_forwarder synthesized{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::synthesize_holder<T> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(rhs.range(), sprout::plus<>())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(rhs.range(), sprout::plus<>())
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_SYNTHESIZED_HPP
|
7
sprout/compost/formats.hpp
Normal file
7
sprout/compost/formats.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef SPROUT_COMPOST_FORMATS_HPP
|
||||
#define SPROUT_COMPOST_FORMATS_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/compost/formats/as_pcm_wave.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_FORMATS_HPP
|
92
sprout/compost/formats/as_pcm_wave.hpp
Normal file
92
sprout/compost/formats/as_pcm_wave.hpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
#ifndef SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP
|
||||
#define SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/clamp.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/type_traits/is_int.hpp>
|
||||
#include <sprout/type_traits/is_uint.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace formats {
|
||||
//
|
||||
// normalized_to_pcm_wave
|
||||
//
|
||||
template<typename IntType, typename = void>
|
||||
struct normalized_to_pcm_wave;
|
||||
template<typename IntType>
|
||||
struct normalized_to_pcm_wave<
|
||||
IntType,
|
||||
typename std::enable_if<sprout::is_int<IntType>::value>::type
|
||||
> {
|
||||
public:
|
||||
typedef IntType result_type;
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR result_type operator()(T const& x) const {
|
||||
return static_cast<result_type>(sprout::clamp(x, -1, 1) * std::numeric_limits<result_type>::max());
|
||||
}
|
||||
};
|
||||
template<typename IntType>
|
||||
struct normalized_to_pcm_wave<
|
||||
IntType,
|
||||
typename std::enable_if<sprout::is_uint<IntType>::value>::type
|
||||
> {
|
||||
public:
|
||||
typedef IntType result_type;
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR result_type operator()(T const& x) const {
|
||||
return static_cast<result_type>(sprout::clamp((x + 1) / 2, 0, 1) * std::numeric_limits<result_type>::max());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// as_pcm_wave_forwarder
|
||||
//
|
||||
template<typename IntType>
|
||||
class as_pcm_wave_forwarder {};
|
||||
|
||||
//
|
||||
// as_pcm_wave
|
||||
//
|
||||
template<typename IntType>
|
||||
inline SPROUT_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder<IntType>
|
||||
as_pcm_wave() {
|
||||
return sprout::compost::formats::as_pcm_wave_forwarder<IntType>();
|
||||
}
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename IntType>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::formats::as_pcm_wave_forwarder<IntType> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::formats::normalized_to_pcm_wave<IntType>())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::formats::normalized_to_pcm_wave<IntType>())
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// as_pcm_wave8
|
||||
// as_pcm_wave16
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder<std::uint8_t> as_pcm_wave8{};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder<std::int16_t> as_pcm_wave16{};
|
||||
} // anonymous-namespace
|
||||
} // namespace formats
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP
|
68
sprout/compost/load/source.hpp
Normal file
68
sprout/compost/load/source.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
#ifndef COMPOST_DEF_LOAD_SOURCE_IDENTIFIER
|
||||
# error should define COMPOST_DEF_LOAD_SOURCE_IDENTIFIER.
|
||||
#endif
|
||||
|
||||
#ifndef COMPOST_DEF_LOAD_SOURCE_FILE
|
||||
# error should define COMPOST_DEF_LOAD_SOURCE_FILE.
|
||||
#endif
|
||||
|
||||
#ifndef COMPOST_DEF_LOAD_SOURCE_DATA_INDEX
|
||||
# define COMPOST_DEF_LOAD_SOURCE_DATA_INDEX -1
|
||||
#endif
|
||||
|
||||
#define COMPOST_LOAD_IDENTIFIER_DETAIL_CAT(id, suffix) COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_I(id, suffix)
|
||||
#define COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_I(id, suffix) COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_II(id ## suffix)
|
||||
#define COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_II(res) res
|
||||
|
||||
#define COMPOST_LOAD_DETAIL_IDENTIFIER(id) COMPOST_LOAD_IDENTIFIER_DETAIL_CAT( \
|
||||
COMPOST_LOAD_IDENTIFIER_DETAIL_CAT(COMPOST_DEF_LOAD_SOURCE_IDENTIFIER, id), \
|
||||
_compost_load_source_detail \
|
||||
)
|
||||
|
||||
#define COMPOST_LOAD_IDENTIFIER COMPOST_DEF_LOAD_SOURCE_IDENTIFIER
|
||||
#ifdef COMPOST_DEF_LOAD_INFO_IDENTIFIER
|
||||
# define COMPOST_LOAD_INFO_IDENTIFIER COMPOST_DEF_LOAD_INFO_IDENTIFIER
|
||||
#else
|
||||
# define COMPOST_LOAD_INFO_IDENTIFIER COMPOST_LOAD_DETAIL_IDENTIFIER(info)
|
||||
#endif
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::sources::version_type COMPOST_LOAD_DETAIL_IDENTIFIER(version) =
|
||||
# define COMPOST_LOADING_SOURCE_VERSION
|
||||
# include COMPOST_DEF_LOAD_SOURCE_FILE
|
||||
# undef COMPOST_LOADING_SOURCE_VERSION
|
||||
;
|
||||
|
||||
static_assert(COMPOST_LOAD_DETAIL_IDENTIFIER(version) <= 0, "Unsupported compost src version");
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::sources::info_type COMPOST_LOAD_INFO_IDENTIFIER = {
|
||||
# define COMPOST_LOADING_SOURCE_INFO
|
||||
# include COMPOST_DEF_LOAD_SOURCE_FILE
|
||||
# undef COMPOST_LOADING_SOURCE_INFO
|
||||
};
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::sources::sound_type<
|
||||
COMPOST_LOAD_INFO_IDENTIFIER.size
|
||||
> COMPOST_LOAD_IDENTIFIER(
|
||||
COMPOST_LOAD_INFO_IDENTIFIER,
|
||||
# define COMPOST_LOADING_SOURCE_DATA
|
||||
# define COMPOST_LOADING_SOURCE_DATA_INDEX COMPOST_DEF_LOAD_SOURCE_DATA_INDEX
|
||||
# include COMPOST_DEF_LOAD_SOURCE_FILE
|
||||
# undef COMPOST_LOADING_SOURCE_DATA_INDEX
|
||||
# undef COMPOST_LOADING_SOURCE_DATA
|
||||
);
|
||||
|
||||
#undef COMPOST_LOAD_IDENTIFIER
|
||||
#undef COMPOST_LOAD_INFO_IDENTIFIER
|
||||
|
||||
#undef COMPOST_LOAD_DETAIL_IDENTIFIER
|
||||
|
||||
#undef COMPOST_LOAD_IDENTIFIER_DETAIL_CAT
|
||||
#undef COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_I
|
||||
#undef COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_II
|
||||
|
||||
#undef COMPOST_DEF_LOAD_SOURCE_IDENTIFIER
|
||||
#undef COMPOST_DEF_LOAD_SOURCE_FILE
|
||||
#ifdef COMPOST_DEF_LOAD_INFO_IDENTIFIER
|
||||
# undef COMPOST_DEF_LOAD_INFO_IDENTIFIER
|
||||
#endif
|
7
sprout/compost/sources.hpp
Normal file
7
sprout/compost/sources.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef SPROUT_COMPOST_SOURCES_HPP
|
||||
#define SPROUT_COMPOST_SOURCES_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/compost/sources/source.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_SOURCES_HPP
|
80
sprout/compost/sources/source.hpp
Normal file
80
sprout/compost/sources/source.hpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#ifndef SPROUT_COMPOST_SOURCES_SOURCE_HPP
|
||||
#define SPROUT_COMPOST_SOURCES_SOURCE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
|
||||
//
|
||||
// COMPOST_LOAD_SOURCE
|
||||
//
|
||||
#define COMPOST_LOAD_SOURCE <sprout/compost/load/source.hpp>
|
||||
|
||||
//
|
||||
// COMPOST_SRC_VERSION
|
||||
//
|
||||
#define COMPOST_SRC_VERSION(NUM) NUM
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace sources {
|
||||
//
|
||||
// version_type
|
||||
//
|
||||
typedef unsigned long version_type;
|
||||
//
|
||||
// info_type
|
||||
//
|
||||
struct info_type {
|
||||
public:
|
||||
std::uint16_t format_tag; // フォーマットID
|
||||
std::uint16_t channels; // チャンネル数
|
||||
std::uint32_t samples_per_sec; // サンプリングレート
|
||||
std::uint32_t bytes_per_sec; // データ速度 (Byte/sec)
|
||||
std::uint16_t block_size; // ブロックサイズ (Byte/sample*チャンネル数)
|
||||
std::uint16_t bits_per_sample; // サンプルあたりのビット数 (bit/sample)
|
||||
std::size_t size; // 要素数
|
||||
};
|
||||
//
|
||||
// sound_type
|
||||
//
|
||||
template<std::size_t Size, typename Elem = double>
|
||||
struct sound_type {
|
||||
public:
|
||||
typedef Elem element_type;
|
||||
typedef element_type value_type;
|
||||
typedef std::size_t size_type;
|
||||
SPROUT_STATIC_CONSTEXPR size_type static_size = Size;
|
||||
typedef sprout::array<value_type, static_size> elements_type;
|
||||
private:
|
||||
elements_type elements_;
|
||||
public:
|
||||
template<typename... Elems>
|
||||
SPROUT_CONSTEXPR sound_type(info_type const& info, Elems const&... elems)
|
||||
: elements_{{
|
||||
(static_cast<typename std::make_signed<Elems>::type>(elems) / static_cast<value_type>(32768.0))...
|
||||
}}
|
||||
{
|
||||
static_assert(sizeof...(Elems) == static_size, "sound_type<>: unmatch source size");
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const&
|
||||
operator()(size_type x) const {
|
||||
return elements_[x];
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
size() const {
|
||||
return static_size;
|
||||
}
|
||||
SPROUT_CONSTEXPR elements_type const&
|
||||
elements() const {
|
||||
return elements_;
|
||||
}
|
||||
};
|
||||
template<std::size_t Size, typename Elem>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::compost::sources::sound_type<Size, Elem>::size_type
|
||||
sprout::compost::sources::sound_type<Size, Elem>::static_size;
|
||||
} // namespace sources
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_SOURCES_SOURCE_HPP
|
11
sprout/compost/waves.hpp
Normal file
11
sprout/compost/waves.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef SPROUT_COMPOST_WAVES_HPP
|
||||
#define SPROUT_COMPOST_WAVES_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/compost/waves/sinusoidal.hpp>
|
||||
#include <sprout/compost/waves/sawtooth_wave.hpp>
|
||||
#include <sprout/compost/waves/triangle_wave.hpp>
|
||||
#include <sprout/compost/waves/square_wave.hpp>
|
||||
#include <sprout/compost/waves/white_noise.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_WAVES_HPP
|
20
sprout/compost/waves/sawtooth_wave.hpp
Normal file
20
sprout/compost/waves/sawtooth_wave.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_WAVES_SAWTOOTH_WAVE_HPP
|
||||
#define SPROUT_COMPOST_WAVES_SAWTOOTH_WAVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/sawtooth_wave.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace waves {
|
||||
//
|
||||
// sawtooth_wave
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::sawtooth_wave_forwarder sawtooth_wave{};
|
||||
} // anonymous-namespace
|
||||
} // namespace waves
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_WAVES_SAWTOOTH_WAVE_HPP
|
20
sprout/compost/waves/sinusoidal.hpp
Normal file
20
sprout/compost/waves/sinusoidal.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_WAVES_SINUSOIDAL_HPP
|
||||
#define SPROUT_COMPOST_WAVES_SINUSOIDAL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/sinusoidal.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace waves {
|
||||
//
|
||||
// sinusoidal
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::sinusoidal_forwarder sinusoidal{};
|
||||
} // anonymous-namespace
|
||||
} // namespace waves
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_WAVES_SINUSOIDAL_HPP
|
20
sprout/compost/waves/square_wave.hpp
Normal file
20
sprout/compost/waves/square_wave.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_WAVES_SQUARE_WAVE_HPP
|
||||
#define SPROUT_COMPOST_WAVES_SQUARE_WAVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/square_wave.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace waves {
|
||||
//
|
||||
// square_wave
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::square_wave_forwarder square_wave{};
|
||||
} // anonymous-namespace
|
||||
} // namespace waves
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_WAVES_SQUARE_WAVE_HPP
|
20
sprout/compost/waves/triangle_wave.hpp
Normal file
20
sprout/compost/waves/triangle_wave.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_WAVES_TRIANGLE_WAVE_HPP
|
||||
#define SPROUT_COMPOST_WAVES_TRIANGLE_WAVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/triangle_wave.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace waves {
|
||||
//
|
||||
// triangle_wave
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::triangle_wave_forwarder triangle_wave{};
|
||||
} // anonymous-namespace
|
||||
} // namespace waves
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_WAVES_TRIANGLE_WAVE_HPP
|
179
sprout/compost/waves/white_noise.hpp
Normal file
179
sprout/compost/waves/white_noise.hpp
Normal file
|
@ -0,0 +1,179 @@
|
|||
#ifndef SPROUT_COMPOST_WAVES_WHITE_NOISE_HPP
|
||||
#define SPROUT_COMPOST_WAVES_WHITE_NOISE_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/generator_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/random/normal_distribution.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace waves {
|
||||
//
|
||||
// white_noise_range
|
||||
//
|
||||
template<typename Value, typename UniformRandomNumberGenerator, typename Range = void>
|
||||
class white_noise_range
|
||||
: public sprout::range::range_container<
|
||||
sprout::generator_iterator<
|
||||
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<Value> >
|
||||
>
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
{
|
||||
public:
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<
|
||||
sprout::generator_iterator<
|
||||
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<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;
|
||||
typedef typename iterator::generator_type generator_type;
|
||||
typedef typename generator_type::engine_type engine_type;
|
||||
typedef typename generator_type::distribution_type distribution_type;
|
||||
public:
|
||||
white_noise_range() = default;
|
||||
white_noise_range(white_noise_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR white_noise_range(
|
||||
range_type& range,
|
||||
engine_type const& gen,
|
||||
value_type const& sigma = 1
|
||||
)
|
||||
: base_type(
|
||||
iterator(distribution_type(0, sigma)(gen), sprout::size(range)),
|
||||
iterator()
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR engine_type const& engine() const {
|
||||
return base_type::begin().generator().engine();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& sigma() const {
|
||||
return base_type::begin().generator().distribution().sigma();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Value, typename UniformRandomNumberGenerator>
|
||||
class white_noise_range<Value, UniformRandomNumberGenerator, void>
|
||||
: public sprout::range::range_container<
|
||||
sprout::generator_iterator<
|
||||
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<Value> >
|
||||
>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef sprout::range::range_container<
|
||||
sprout::generator_iterator<
|
||||
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<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;
|
||||
typedef typename iterator::generator_type generator_type;
|
||||
typedef typename generator_type::engine_type engine_type;
|
||||
typedef typename generator_type::distribution_type distribution_type;
|
||||
public:
|
||||
white_noise_range() = default;
|
||||
white_noise_range(white_noise_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR white_noise_range(
|
||||
engine_type const& gen,
|
||||
value_type const& sigma = 1
|
||||
)
|
||||
: base_type(
|
||||
iterator(distribution_type(0, sigma)(gen)),
|
||||
iterator()
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR engine_type const& engine() const {
|
||||
return base_type::begin().generator().engine();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& sigma() const {
|
||||
return base_type::begin().generator().distribution().sigma();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// white_noise_forwarder
|
||||
//
|
||||
class white_noise_forwarder {
|
||||
public:
|
||||
template<typename UniformRandomNumberGenerator, typename Value = double>
|
||||
SPROUT_CONSTEXPR sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator>
|
||||
operator()(
|
||||
UniformRandomNumberGenerator const& gen,
|
||||
Value const& sigma = 1
|
||||
) const
|
||||
{
|
||||
return sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator>(gen, sigma);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// white_noise
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::waves::white_noise_forwarder white_noise{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename Value, typename UniformRandomNumberGenerator>
|
||||
inline SPROUT_CONSTEXPR sprout::compost::waves::white_noise_range<
|
||||
Value, UniformRandomNumberGenerator,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator> const& rhs) {
|
||||
return sprout::compost::waves::white_noise_range<
|
||||
Value, UniformRandomNumberGenerator,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs),
|
||||
rhs.engine(), rhs.sigma()
|
||||
);
|
||||
}
|
||||
} // namespace waves
|
||||
} // namespace compost
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Value, typename UniformRandomNumberGenerator, typename Range>
|
||||
struct container_construct_traits<sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator, 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::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator, 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_COMPOST_WAVES_WHITE_NOISE_HPP
|
|
@ -11,12 +11,18 @@
|
|||
#define DARKROOM_LOAD_IDENTIFIER_DETAIL_CAT_I(id, suffix) DARKROOM_LOAD_IDENTIFIER_DETAIL_CAT_II(id ## suffix)
|
||||
#define DARKROOM_LOAD_IDENTIFIER_DETAIL_CAT_II(res) res
|
||||
|
||||
#define DARKROOM_LOAD_IDENTIFIER DARKROOM_DEF_LOAD_TEXTURE_IDENTIFIER
|
||||
#define DARKROOM_LOAD_DETAIL_IDENTIFIER(id) DARKROOM_LOAD_IDENTIFIER_DETAIL_CAT( \
|
||||
DARKROOM_LOAD_IDENTIFIER_DETAIL_CAT(DARKROOM_DEF_LOAD_TEXTURE_IDENTIFIER, id), \
|
||||
_darkroom_load_texture_detail \
|
||||
)
|
||||
|
||||
#define DARKROOM_LOAD_IDENTIFIER DARKROOM_DEF_LOAD_TEXTURE_IDENTIFIER
|
||||
#ifdef DARKROOM_DEF_LOAD_INFO_IDENTIFIER
|
||||
# define DARKROOM_LOAD_INFO_IDENTIFIER DARKROOM_DEF_LOAD_INFO_IDENTIFIER
|
||||
#else
|
||||
# define DARKROOM_LOAD_INFO_IDENTIFIER DARKROOM_LOAD_DETAIL_IDENTIFIER(info)
|
||||
#endif
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::version_type DARKROOM_LOAD_DETAIL_IDENTIFIER(version) =
|
||||
# define DARKROOM_LOADING_TEXTURE_VERSION
|
||||
# include DARKROOM_DEF_LOAD_TEXTURE_FILE
|
||||
|
@ -25,24 +31,25 @@ SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::version_type DARKROOM_LOAD_D
|
|||
|
||||
static_assert(DARKROOM_LOAD_DETAIL_IDENTIFIER(version) <= 0, "Unsupported darkroom tex version");
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::info_type DARKROOM_LOAD_DETAIL_IDENTIFIER(info) = {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::info_type DARKROOM_LOAD_INFO_IDENTIFIER = {
|
||||
# define DARKROOM_LOADING_TEXTURE_INFO
|
||||
# include DARKROOM_DEF_LOAD_TEXTURE_FILE
|
||||
# undef DARKROOM_LOADING_TEXTURE_INFO
|
||||
};
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::image_type<
|
||||
DARKROOM_LOAD_DETAIL_IDENTIFIER(info).width,
|
||||
DARKROOM_LOAD_DETAIL_IDENTIFIER(info).height
|
||||
DARKROOM_LOAD_INFO_IDENTIFIER.width,
|
||||
DARKROOM_LOAD_INFO_IDENTIFIER.height
|
||||
> DARKROOM_LOAD_IDENTIFIER(
|
||||
DARKROOM_LOAD_DETAIL_IDENTIFIER(info).image_format,
|
||||
DARKROOM_LOAD_DETAIL_IDENTIFIER(info).pixel_format,
|
||||
DARKROOM_LOAD_INFO_IDENTIFIER,
|
||||
# define DARKROOM_LOADING_TEXTURE_PIXEL
|
||||
# include DARKROOM_DEF_LOAD_TEXTURE_FILE
|
||||
# undef DARKROOM_LOADING_TEXTURE_PIXEL
|
||||
);
|
||||
|
||||
#undef DARKROOM_LOAD_IDENTIFIER
|
||||
#undef DARKROOM_LOAD_INFO_IDENTIFIER
|
||||
|
||||
#undef DARKROOM_LOAD_DETAIL_IDENTIFIER
|
||||
|
||||
#undef DARKROOM_LOAD_IDENTIFIER_DETAIL_CAT
|
||||
|
@ -51,3 +58,6 @@ SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::image_type<
|
|||
|
||||
#undef DARKROOM_DEF_LOAD_TEXTURE_IDENTIFIER
|
||||
#undef DARKROOM_DEF_LOAD_TEXTURE_FILE
|
||||
#ifdef DARKROOM_DEF_LOAD_INFO_IDENTIFIER
|
||||
# undef DARKROOM_DEF_LOAD_INFO_IDENTIFIER
|
||||
#endif
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace sprout {
|
|||
pixels_type pixels_;
|
||||
public:
|
||||
template<typename... Elems>
|
||||
SPROUT_CONSTEXPR image_type(unsigned long image_format, unsigned long pixel_format, Elems const&... elems)
|
||||
SPROUT_CONSTEXPR image_type(info_type const& info, Elems const&... elems)
|
||||
: pixels_{{
|
||||
color_type(
|
||||
static_cast<color_component_type>((elems >> 16) & 0xFF) / 0xFF,
|
||||
|
@ -89,6 +89,12 @@ namespace sprout {
|
|||
return pixels_;
|
||||
}
|
||||
};
|
||||
template<std::size_t Width, std::size_t Height, typename Color>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::darkroom::textures::image_type<Width, Height, Color>::size_type
|
||||
sprout::darkroom::textures::image_type<Width, Height, Color>::static_width;
|
||||
template<std::size_t Width, std::size_t Height, typename Color>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::darkroom::textures::image_type<Width, Height, Color>::size_type
|
||||
sprout::darkroom::textures::image_type<Width, Height, Color>::static_height;
|
||||
} // namespace textures
|
||||
} // namespace darkroom
|
||||
} // namespace sprout
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <sprout/functional/mem_fn.hpp>
|
||||
#include <sprout/functional/bind.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
#include <sprout/functional/type_traits.hpp>
|
||||
#include <sprout/functional/polymorphic.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HPP
|
||||
|
|
|
@ -1,34 +1,68 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIND1ST_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIND1ST_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/base.hpp>
|
||||
#include <sprout/functional/type_traits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
// D.9.1 Class template binder1st
|
||||
template<typename Fn>
|
||||
class binder1st
|
||||
template<typename Fn, typename T = void, typename = void>
|
||||
class binder1st;
|
||||
template<typename Fn, typename T>
|
||||
class binder1st<
|
||||
Fn, T,
|
||||
typename std::enable_if<sprout::is_strict_binary_function<Fn>::value>::type
|
||||
>
|
||||
: public sprout::unary_function<typename Fn::second_argument_type, typename Fn::result_type>
|
||||
{
|
||||
public:
|
||||
typedef typename std::conditional<
|
||||
std::is_void<T>::value,
|
||||
typename Fn::first_argument_type,
|
||||
T
|
||||
>::type value_type;
|
||||
protected:
|
||||
Fn op;
|
||||
typename Fn::first_argument_type value;
|
||||
value_type value;
|
||||
public:
|
||||
SPROUT_CONSTEXPR binder1st(Fn const& x, typename Fn::first_argument_type const& y)
|
||||
SPROUT_CONSTEXPR binder1st(Fn const& x, value_type const& y)
|
||||
: op(x), value(y)
|
||||
{}
|
||||
SPROUT_CONSTEXPR typename Fn::result_type operator()(typename Fn::second_argument_type const& x) const {
|
||||
SPROUT_CONSTEXPR typename Fn::result_type
|
||||
operator()(typename Fn::second_argument_type const& x) const {
|
||||
return op(value, x);
|
||||
}
|
||||
};
|
||||
template<typename Fn, typename T>
|
||||
class binder1st<
|
||||
Fn, T,
|
||||
typename std::enable_if<!sprout::is_strict_binary_function<Fn>::value>::type
|
||||
> {
|
||||
public:
|
||||
typedef T value_type;
|
||||
protected:
|
||||
Fn op;
|
||||
value_type value;
|
||||
public:
|
||||
SPROUT_CONSTEXPR binder1st(Fn const& x, value_type const& y)
|
||||
: op(x), value(y)
|
||||
{}
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR decltype(op(value, std::declval<U const&>()))
|
||||
operator()(U const& x) const {
|
||||
return op(value, x);
|
||||
}
|
||||
};
|
||||
|
||||
// D.9.2 bind1st
|
||||
template<typename Fn, typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::binder1st<Fn>
|
||||
inline SPROUT_CONSTEXPR sprout::binder1st<Fn, T>
|
||||
bind1st(Fn const& fn, T const& x) {
|
||||
return sprout::binder1st<Fn>(fn, typename Fn::first_argument_type(x));
|
||||
return sprout::binder1st<Fn, T>(fn, typename sprout::binder1st<Fn, T>::value_type(x));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -8,27 +8,59 @@ namespace sprout {
|
|||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
// D.9.3 Class template binder2nd
|
||||
template<typename Fn>
|
||||
class binder2nd
|
||||
template<typename Fn, typename T = void, typename = void>
|
||||
class binder2nd;
|
||||
template<typename Fn, typename T>
|
||||
class binder2nd<
|
||||
Fn, T,
|
||||
typename std::enable_if<sprout::is_strict_binary_function<Fn>::value>::type
|
||||
>
|
||||
: public sprout::unary_function<typename Fn::first_argument_type, typename Fn::result_type>
|
||||
{
|
||||
public:
|
||||
typedef typename std::conditional<
|
||||
std::is_void<T>::value,
|
||||
typename Fn::second_argument_type,
|
||||
T
|
||||
>::type value_type;
|
||||
protected:
|
||||
Fn op;
|
||||
typename Fn::second_argument_type value;
|
||||
value_type value;
|
||||
public:
|
||||
SPROUT_CONSTEXPR binder2nd(Fn const& x, typename Fn::second_argument_type const& y)
|
||||
SPROUT_CONSTEXPR binder2nd(Fn const& x, value_type const& y)
|
||||
: op(x), value(y)
|
||||
{}
|
||||
SPROUT_CONSTEXPR typename Fn::result_type operator()(typename Fn::first_argument_type const& x) const {
|
||||
SPROUT_CONSTEXPR typename Fn::result_type
|
||||
operator()(typename Fn::first_argument_type const& x) const {
|
||||
return op(x, value);
|
||||
}
|
||||
};
|
||||
template<typename Fn, typename T>
|
||||
class binder2nd<
|
||||
Fn, T,
|
||||
typename std::enable_if<!sprout::is_strict_binary_function<Fn>::value>::type
|
||||
> {
|
||||
public:
|
||||
typedef T value_type;
|
||||
protected:
|
||||
Fn op;
|
||||
value_type value;
|
||||
public:
|
||||
SPROUT_CONSTEXPR binder2nd(Fn const& x, value_type const& y)
|
||||
: op(x), value(y)
|
||||
{}
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR decltype(op(std::declval<U const&>(), value))
|
||||
operator()(U const& x) const {
|
||||
return op(x, value);
|
||||
}
|
||||
};
|
||||
|
||||
// D.9.4 bind2nd
|
||||
// D.9.3 bind2nd
|
||||
template<typename Fn, typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::binder2nd<Fn>
|
||||
bind2nd(Fn const& op, T const& x) {
|
||||
return sprout::binder2nd<Fn>(op, typename Fn::second_argument_type(x));
|
||||
inline SPROUT_CONSTEXPR sprout::binder2nd<Fn, T>
|
||||
bind2nd(Fn const& fn, T const& x) {
|
||||
return sprout::binder2nd<Fn, T>(fn, typename sprout::binder2nd<Fn, T>::value_type(x));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
57
sprout/functional/type_traits.hpp
Normal file
57
sprout/functional/type_traits.hpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_TYPE_TRAITS_HPP
|
||||
#define SPROUT_FUNCTIONAL_TYPE_TRAITS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
#include <sprout/type_traits/inherit_if_xxx.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// has_result_type
|
||||
// has_argument_type
|
||||
// has_first_argument_type
|
||||
// has_second_argument_type
|
||||
//
|
||||
SPROUT_HAS_XXX_TYPE_DEF_LAZY(result_type);
|
||||
SPROUT_HAS_XXX_TYPE_DEF_LAZY(argument_type);
|
||||
SPROUT_HAS_XXX_TYPE_DEF_LAZY(first_argument_type);
|
||||
SPROUT_HAS_XXX_TYPE_DEF_LAZY(second_argument_type);
|
||||
|
||||
//
|
||||
// inhert_if_result_type
|
||||
// inhert_if_argument_type
|
||||
// inhert_if_first_argument_type
|
||||
// inhert_if_second_argument_type
|
||||
//
|
||||
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(result_type);
|
||||
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(argument_type);
|
||||
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(first_argument_type);
|
||||
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(second_argument_type);
|
||||
|
||||
//
|
||||
// is_strict_unary_function
|
||||
//
|
||||
template<typename Fn>
|
||||
struct is_strict_unary_function
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
sprout::has_result_type<Fn>::value
|
||||
&& sprout::has_argument_type<Fn>::value
|
||||
>
|
||||
{};
|
||||
//
|
||||
// is_strict_binary_function
|
||||
//
|
||||
template<typename Fn>
|
||||
struct is_strict_binary_function
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
sprout::has_result_type<Fn>::value
|
||||
&& sprout::has_first_argument_type<Fn>::value
|
||||
&& sprout::has_second_argument_type<Fn>::value
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_TYPE_TRAITS_HPP
|
264
sprout/iterator/clamp_iterator.hpp
Normal file
264
sprout/iterator/clamp_iterator.hpp
Normal file
|
@ -0,0 +1,264 @@
|
|||
#ifndef SPROUT_ITERATOR_CLAMP_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_CLAMP_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/algorithm/clamp.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// clamp_iterator
|
||||
//
|
||||
template<typename Iterator, typename Compare = NS_SSCRISK_CEL_OR_SPROUT::less<typename std::iterator_traits<Iterator>::value_type> >
|
||||
class clamp_iterator
|
||||
: public std::iterator<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
typename std::iterator_traits<Iterator>::value_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
typename std::iterator_traits<Iterator>::pointer,
|
||||
typename std::iterator_traits<Iterator>::reference
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef Iterator iterator_type;
|
||||
typedef Compare compare_type;
|
||||
typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category;
|
||||
typedef typename std::iterator_traits<iterator_type>::value_type value_type;
|
||||
typedef typename std::iterator_traits<iterator_type>::difference_type difference_type;
|
||||
typedef typename std::iterator_traits<iterator_type>::pointer pointer;
|
||||
typedef typename std::iterator_traits<iterator_type>::reference reference;
|
||||
protected:
|
||||
iterator_type current;
|
||||
compare_type comp;
|
||||
value_type low;
|
||||
value_type up;
|
||||
private:
|
||||
public:
|
||||
clamp_iterator() = default;
|
||||
clamp_iterator(clamp_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR clamp_iterator(iterator_type it, value_type const& low, value_type const& up, compare_type comp = compare_type())
|
||||
: current(it), comp(comp), low(low), up(up)
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR clamp_iterator(clamp_iterator<U, V> const& it)
|
||||
: current(it.current), comp(it.comp), low(it.low), up(it.up)
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
clamp_iterator& operator=(clamp_iterator<U, V> const& it) {
|
||||
clamp_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type const& base() const {
|
||||
return current;
|
||||
}
|
||||
SPROUT_CONSTEXPR compare_type const& compare() const {
|
||||
return comp;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& lower() const {
|
||||
return low;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& upper() const {
|
||||
return up;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return sprout::clamp(*current, low, up, comp);
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &sprout::clamp(*current, low, up, comp);
|
||||
}
|
||||
|
||||
clamp_iterator& operator++() {
|
||||
++current;
|
||||
return *this;
|
||||
}
|
||||
clamp_iterator operator++(int) {
|
||||
clamp_iterator result(*this);
|
||||
++current;
|
||||
return result;
|
||||
}
|
||||
clamp_iterator& operator--() {
|
||||
--current;
|
||||
return *this;
|
||||
}
|
||||
clamp_iterator operator--(int) {
|
||||
clamp_iterator temp(*this);
|
||||
--current;
|
||||
return temp;
|
||||
}
|
||||
SPROUT_CONSTEXPR clamp_iterator operator+(difference_type n) const {
|
||||
return clamp_iterator(sprout::next(current, n), low, up, comp);
|
||||
}
|
||||
SPROUT_CONSTEXPR clamp_iterator operator-(difference_type n) const {
|
||||
return clamp_iterator(sprout::prev(current, n), low, up, comp);
|
||||
}
|
||||
clamp_iterator& operator+=(difference_type n) {
|
||||
clamp_iterator temp(sprout::next(current, n), low, up, comp);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
clamp_iterator& operator-=(difference_type n) {
|
||||
clamp_iterator temp(sprout::prev(current, n), low, up, comp);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
||||
return sprout::clamp(*sprout::next(current, n), low, up, comp);
|
||||
}
|
||||
SPROUT_CONSTEXPR clamp_iterator next() const {
|
||||
return clamp_iterator(sprout::next(current), low, up, comp);
|
||||
}
|
||||
SPROUT_CONSTEXPR clamp_iterator prev() const {
|
||||
return clamp_iterator(sprout::prev(current), low, up, comp);
|
||||
}
|
||||
void swap(clamp_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(comp, other.comp))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(low, other.low))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(up, other.up))
|
||||
)
|
||||
{
|
||||
sprout::swap(current, other.current);
|
||||
sprout::swap(comp, other.comp);
|
||||
sprout::swap(low, other.low);
|
||||
sprout::swap(up, other.up);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Iterator1, typename Iterator2, typename Compare1, typename Compare2>
|
||||
inline SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::clamp_iterator<Iterator1, Compare1> const& lhs,
|
||||
sprout::clamp_iterator<Iterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base();
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2, typename Compare1, typename Compare2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator!=(sprout::clamp_iterator<Iterator1, Compare1> const& lhs, sprout::clamp_iterator<Iterator2, Compare2> const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2, typename Compare1, typename Compare2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<(sprout::clamp_iterator<Iterator1, Compare1> const& lhs, sprout::clamp_iterator<Iterator2, Compare2> const& rhs) {
|
||||
return lhs.base() < rhs.base();
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2, typename Compare1, typename Compare2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>(sprout::clamp_iterator<Iterator1, Compare1> const& lhs, sprout::clamp_iterator<Iterator2, Compare2> const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2, typename Compare1, typename Compare2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<=(sprout::clamp_iterator<Iterator1, Compare1> const& lhs, sprout::clamp_iterator<Iterator2, Compare2> const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2, typename Compare1, typename Compare2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>=(sprout::clamp_iterator<Iterator1, Compare1> const& lhs, sprout::clamp_iterator<Iterator2, Compare2> const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
template<typename Iterator1, typename Iterator2, typename Compare1, typename Compare2>
|
||||
inline SPROUT_CONSTEXPR decltype(std::declval<Iterator1>() - std::declval<Iterator2>())
|
||||
operator-(sprout::clamp_iterator<Iterator1, Compare1> const& lhs, sprout::clamp_iterator<Iterator2, Compare2> const& rhs) {
|
||||
return lhs.base() - rhs.base();
|
||||
}
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::clamp_iterator<Iterator, Compare>
|
||||
operator+(
|
||||
typename sprout::clamp_iterator<Iterator, Compare>::difference_type n,
|
||||
sprout::clamp_iterator<Iterator, Compare> const& it
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// make_clamp_iterator
|
||||
//
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::clamp_iterator<Iterator, Compare>
|
||||
make_clamp_iterator(
|
||||
Iterator it,
|
||||
typename std::iterator_traits<Iterator>::value_type const& low,
|
||||
typename std::iterator_traits<Iterator>::value_type const& up,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
return sprout::clamp_iterator<Iterator, Compare>(it, low, up, comp);
|
||||
}
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::clamp_iterator<Iterator, Compare>
|
||||
make_clamp_iterator(
|
||||
Iterator it,
|
||||
typename std::iterator_traits<Iterator>::value_type const& low,
|
||||
typename std::iterator_traits<Iterator>::value_type const& up
|
||||
)
|
||||
{
|
||||
return sprout::clamp_iterator<Iterator, Compare>(it, low, up);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename Iterator, typename Compare>
|
||||
inline void
|
||||
swap(sprout::clamp_iterator<Iterator, Compare>& lhs, sprout::clamp_iterator<Iterator, Compare>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_distance
|
||||
//
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<sprout::clamp_iterator<Iterator, Compare> >::difference_type
|
||||
iterator_distance(sprout::clamp_iterator<Iterator, Compare> first, sprout::clamp_iterator<Iterator, Compare> last) {
|
||||
return last - first;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::clamp_iterator<Iterator, Compare>
|
||||
iterator_next(sprout::clamp_iterator<Iterator, Compare> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::clamp_iterator<Iterator, Compare>
|
||||
iterator_next(
|
||||
sprout::clamp_iterator<Iterator, Compare> const& it,
|
||||
typename sprout::clamp_iterator<Iterator, Compare>::difference_type n
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_prev
|
||||
//
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::clamp_iterator<Iterator, Compare>
|
||||
iterator_prev(sprout::clamp_iterator<Iterator, Compare> const& it) {
|
||||
return it.prev();
|
||||
}
|
||||
template<typename Iterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::clamp_iterator<Iterator, Compare>
|
||||
iterator_prev(
|
||||
sprout::clamp_iterator<Iterator, Compare> const& it,
|
||||
typename sprout::clamp_iterator<Iterator, Compare>::difference_type n
|
||||
)
|
||||
{
|
||||
return it - n;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // SPROUT_ITERATOR_CLAMP_ITERATOR_HPP
|
|
@ -71,7 +71,7 @@ namespace sprout {
|
|||
, last(last)
|
||||
, pred(pred)
|
||||
{}
|
||||
public:
|
||||
public:
|
||||
filter_iterator() = default;
|
||||
filter_iterator(filter_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR filter_iterator(predicate_type pred, iterator_type it, iterator_type last = iterator_type())
|
||||
|
|
|
@ -19,124 +19,139 @@ namespace sprout {
|
|||
: sprout::detail::has_iterator_category<std::iterator_traits<Iterator> >
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_input_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_input_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::input_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_input_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_input_iterator_category
|
||||
: public std::is_convertible<Category, std::input_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_output_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_output_iterator_category
|
||||
: public std::is_convertible<Category, std::output_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_forward_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_forward_iterator_category
|
||||
: public std::is_convertible<Category, std::forward_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_bidirectional_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_bidirectional_iterator_category
|
||||
: public std::is_convertible<Category, std::bidirectional_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_random_access_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_random_access_iterator_category
|
||||
: public std::is_convertible<Category, std::random_access_iterator_tag>
|
||||
{};
|
||||
|
||||
//
|
||||
// is_input_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_input_iterator
|
||||
: sprout::detail::is_input_iterator_impl<Iterator>
|
||||
: public sprout::is_input_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_output_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_output_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::output_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_output_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_output_iterator
|
||||
: sprout::detail::is_output_iterator_impl<Iterator>
|
||||
: public sprout::is_output_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_forward_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_forward_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::forward_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_forward_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_forward_iterator
|
||||
: sprout::detail::is_forward_iterator_impl<Iterator>
|
||||
: public sprout::is_forward_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_bidirectional_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_bidirectional_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::bidirectional_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_bidirectional_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_bidirectional_iterator
|
||||
: sprout::detail::is_bidirectional_iterator_impl<Iterator>
|
||||
: public sprout::is_bidirectional_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator, typename = void>
|
||||
struct is_random_access_iterator_impl
|
||||
: std::false_type
|
||||
{};
|
||||
template<typename Iterator>
|
||||
struct is_random_access_iterator_impl<
|
||||
Iterator,
|
||||
typename std::enable_if<sprout::is_iterator<Iterator>::value>::type
|
||||
>
|
||||
: std::is_convertible<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::random_access_iterator_tag
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// is_random_access_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_random_access_iterator
|
||||
: sprout::detail::is_random_access_iterator_impl<Iterator>
|
||||
: public sprout::is_random_access_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Category, bool IsRandomAccess, bool IsBidirectional, bool IsForward, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl;
|
||||
template<typename Category, bool IsBidirectional, bool IsForward, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl<Category, true, IsBidirectional, IsForward, IsSinglePassOrIncrementable>
|
||||
: public std::integral_constant<int, 4>
|
||||
{};
|
||||
template<typename Category, bool IsForward, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl<Category, false, true, IsForward, IsSinglePassOrIncrementable>
|
||||
: public std::integral_constant<int, 3>
|
||||
{};
|
||||
template<typename Category, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl<Category, false, false, true, IsSinglePassOrIncrementable>
|
||||
: public std::integral_constant<int, 2>
|
||||
{};
|
||||
template<typename Category>
|
||||
struct iterator_category_hierarchy_impl<Category, false, false, false, true>
|
||||
: public std::integral_constant<int, 1>
|
||||
{};
|
||||
|
||||
template<typename Category>
|
||||
struct iterator_category_hierarchy
|
||||
: public sprout::detail::iterator_category_hierarchy_impl<
|
||||
Category,
|
||||
sprout::is_random_access_iterator_category<Category>::value,
|
||||
sprout::is_bidirectional_iterator_category<Category>::value,
|
||||
sprout::is_forward_iterator_category<Category>::value,
|
||||
sprout::is_input_iterator_category<Category>::value || sprout::is_output_iterator_category<Category>::value
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Category1, typename Category2>
|
||||
struct iterator_category_less
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
(sprout::detail::iterator_category_hierarchy<Category1>::value < sprout::detail::iterator_category_hierarchy<Category2>::value)
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// min_iterator_category
|
||||
//
|
||||
template<typename Head, typename... Tail>
|
||||
struct min_iterator_category;
|
||||
template<typename Category>
|
||||
struct min_iterator_category<Category>
|
||||
: public std::common_type<Category>
|
||||
{};
|
||||
template<typename Category1, typename Category2>
|
||||
struct min_iterator_category<Category1, Category2>
|
||||
: public std::conditional<
|
||||
sprout::detail::iterator_category_less<Category1, Category2>::value,
|
||||
Category1, Category2
|
||||
>
|
||||
{};
|
||||
template<typename Head, typename... Tail>
|
||||
struct min_iterator_category
|
||||
: public sprout::min_iterator_category<
|
||||
Head,
|
||||
typename sprout::min_iterator_category<Tail...>::type
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/iterator/traits.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -17,7 +18,10 @@ namespace sprout {
|
|||
template<typename BinaryFunction, typename LIterator, typename RIterator = void>
|
||||
class transform_iterator
|
||||
: public std::iterator<
|
||||
typename std::iterator_traits<LIterator>::iterator_category,
|
||||
typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<LIterator>::iterator_category,
|
||||
typename std::iterator_traits<RIterator>::iterator_category
|
||||
>::type,
|
||||
typename std::remove_reference<
|
||||
typename std::result_of<
|
||||
BinaryFunction (
|
||||
|
@ -47,7 +51,10 @@ namespace sprout {
|
|||
typedef BinaryFunction functor_type;
|
||||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category;
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<LIterator>::iterator_category,
|
||||
typename std::iterator_traits<RIterator>::iterator_category
|
||||
>::type iterator_category;
|
||||
typedef typename std::result_of<
|
||||
BinaryFunction (
|
||||
typename std::iterator_traits<LIterator>::reference,
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace sprout {
|
|||
typedef Engine engine_type;
|
||||
typedef Distribution distribution_type;
|
||||
typedef typename distribution_value_type::result_type result_type;
|
||||
typedef sprout::random::random_result<engine_value_type, distribution_value_type> random_result_type;
|
||||
private:
|
||||
engine_type engine_;
|
||||
distribution_type distribution_;
|
||||
|
@ -40,7 +41,7 @@ namespace sprout {
|
|||
: engine_(engine)
|
||||
, distribution_(distribution)
|
||||
{}
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<engine_value_type, distribution_value_type> operator()() const {
|
||||
SPROUT_CONSTEXPR random_result_type operator()() const {
|
||||
return distribution_(engine_);
|
||||
}
|
||||
engine_reference_type engine() {
|
||||
|
|
164
sprout/range/adaptor/clamped.hpp
Normal file
164
sprout/range/adaptor/clamped.hpp
Normal file
|
@ -0,0 +1,164 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_CLAMPED_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_CLAMPED_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/clamp_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 HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
//
|
||||
// clamped_range
|
||||
//
|
||||
template<
|
||||
typename Range,
|
||||
typename Compare = NS_SSCRISK_CEL_OR_SPROUT::less<typename sprout::container_traits<Range>::value_type>
|
||||
>
|
||||
class clamped_range
|
||||
: public sprout::range::range_container<
|
||||
sprout::clamp_iterator<typename sprout::container_traits<Range>::iterator, Compare>
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
{
|
||||
public:
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<
|
||||
sprout::clamp_iterator<typename sprout::container_traits<Range>::iterator, Compare>
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::value_type value_type;
|
||||
typedef typename iterator::compare_type compare_type;
|
||||
public:
|
||||
clamped_range() = default;
|
||||
clamped_range(clamped_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR clamped_range(
|
||||
range_type& range,
|
||||
value_type const& low,
|
||||
value_type const& up,
|
||||
compare_type comp = compare_type()
|
||||
)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), low, up, comp),
|
||||
iterator(sprout::end(range), low, up, comp)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR compare_type const& compare() const {
|
||||
return base_type::begin().compare();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& lower() const {
|
||||
return base_type::begin().lower();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& upper() const {
|
||||
return base_type::begin().upper();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// clamp_holder
|
||||
//
|
||||
template<typename Value, typename Compare = NS_SSCRISK_CEL_OR_SPROUT::less<Value> >
|
||||
class clamp_holder {
|
||||
public:
|
||||
typedef Value value_type;
|
||||
typedef Compare compare_type;
|
||||
private:
|
||||
compare_type comp_;
|
||||
value_type low_;
|
||||
value_type up_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR clamp_holder(value_type const& low, value_type const& up, compare_type comp = compare_type())
|
||||
: comp_(comp), low_(low), up_(up)
|
||||
{}
|
||||
SPROUT_CONSTEXPR compare_type const& compare() const {
|
||||
return comp_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& lower() const {
|
||||
return low_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& upper() const {
|
||||
return up_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// clamped_forwarder
|
||||
//
|
||||
class clamped_forwarder {
|
||||
public:
|
||||
template<typename Value, typename Compare>
|
||||
SPROUT_CONSTEXPR sprout::adaptors::clamp_holder<Value, Compare>
|
||||
operator()(Value const& low, Value const& up, Compare comp) {
|
||||
return sprout::adaptors::clamp_holder<Value, Compare>(low, up, comp);
|
||||
}
|
||||
template<typename Value>
|
||||
SPROUT_CONSTEXPR sprout::adaptors::clamp_holder<Value>
|
||||
operator()(Value const& low, Value const& up) {
|
||||
return sprout::adaptors::clamp_holder<Value>(low, up);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// clamped
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::clamped_forwarder clamped{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename Value, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::clamped_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
||||
Compare
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::clamp_holder<Value, Compare> const& rhs) {
|
||||
return sprout::adaptors::clamped_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type,
|
||||
Compare
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs),
|
||||
rhs.lower(), rhs.upper(), rhs.compare()
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Range, typename Compare>
|
||||
struct container_construct_traits<sprout::adaptors::clamped_range<Range, Compare> > {
|
||||
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::adaptors::clamped_range<Range, Compare> >::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_CLAMPED_HPP
|
|
@ -62,7 +62,7 @@ namespace sprout {
|
|||
explicit SPROUT_CONSTEXPR copy_holder(result_type& result)
|
||||
: result_(result)
|
||||
{}
|
||||
SPROUT_CONSTEXPR result_type result() const {
|
||||
SPROUT_CONSTEXPR result_type const& result() const {
|
||||
return result_;
|
||||
}
|
||||
};
|
||||
|
@ -90,9 +90,9 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Result>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<sprout::pit<Result> >::type
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
operator|(Range&& lhs, sprout::adaptors::copy_holder<Result> const& rhs) {
|
||||
return sprout::range::fixed::copy(sprout::lvalue_forward<Range>(lhs), sprout::pit<Result>());
|
||||
return sprout::range::fixed::copy(sprout::lvalue_forward<Range>(lhs), rhs.result());
|
||||
}
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::copied_range<
|
||||
|
|
|
@ -143,7 +143,7 @@ namespace sprout {
|
|||
return sprout::adaptors::transform_holder<
|
||||
BinaryFunction,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
|
||||
> (
|
||||
>(
|
||||
func,
|
||||
sprout::lvalue_forward<RRange>(range)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue