mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-05-10 09:23:30 +00:00
fix polymorphic functor
This commit is contained in:
parent
ac5ac257e6
commit
53b99b25f8
9 changed files with 60 additions and 47 deletions
|
@ -11,7 +11,7 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// hash
|
// hash
|
||||||
//
|
//
|
||||||
template<typename T>
|
template<typename T = void>
|
||||||
struct hash {
|
struct hash {
|
||||||
public:
|
public:
|
||||||
typedef T argument_type;
|
typedef T argument_type;
|
||||||
|
|
|
@ -10,14 +10,23 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// amplitude_value
|
// amplitude_value
|
||||||
//
|
//
|
||||||
template<typename T>
|
template<typename T = void>
|
||||||
class amplitude_value {
|
class amplitude_value {
|
||||||
public:
|
public:
|
||||||
typedef typename T::value_type result_type;
|
typedef typename T::value_type result_type;
|
||||||
typedef T argument_type;
|
typedef T argument_type;
|
||||||
public:
|
public:
|
||||||
SPROUT_CONSTEXPR amplitude_value() {}
|
SPROUT_CONSTEXPR typename T::value_type
|
||||||
SPROUT_CONSTEXPR typename T::value_type operator()(T const& value) const {
|
operator()(T const& value) const {
|
||||||
|
return sprout::amplitude_spectrum_value(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
class amplitude_value<void> {
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
SPROUT_CONSTEXPR typename T::value_type
|
||||||
|
operator()(T const& value) const {
|
||||||
return sprout::amplitude_spectrum_value(value);
|
return sprout::amplitude_spectrum_value(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,14 +10,23 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// phase_value
|
// phase_value
|
||||||
//
|
//
|
||||||
template<typename T>
|
template<typename T = void>
|
||||||
class phase_value {
|
class phase_value {
|
||||||
public:
|
public:
|
||||||
typedef typename T::value_type result_type;
|
typedef typename T::value_type result_type;
|
||||||
typedef T argument_type;
|
typedef T argument_type;
|
||||||
public:
|
public:
|
||||||
SPROUT_CONSTEXPR phase_value() {}
|
SPROUT_CONSTEXPR typename T::value_type
|
||||||
SPROUT_CONSTEXPR typename T::value_type operator()(T const& value) const {
|
operator()(T const& value) const {
|
||||||
|
return sprout::phase_spectrum_value(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
class phase_value<void> {
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
SPROUT_CONSTEXPR typename T::value_type
|
||||||
|
operator()(T const& value) const {
|
||||||
return sprout::phase_spectrum_value(value);
|
return sprout::phase_spectrum_value(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,8 +19,7 @@ namespace sprout {
|
||||||
T new_;
|
T new_;
|
||||||
public:
|
public:
|
||||||
SPROUT_CONSTEXPR replace_value_if(Predicate pred, T const& new_value)
|
SPROUT_CONSTEXPR replace_value_if(Predicate pred, T const& new_value)
|
||||||
: pred_(pred)
|
: pred_(pred), new_(new_value)
|
||||||
, new_(new_value)
|
|
||||||
{}
|
{}
|
||||||
SPROUT_CONSTEXPR T operator()(T const& value) const {
|
SPROUT_CONSTEXPR T operator()(T const& value) const {
|
||||||
return pred_(value) ? new_ : value;
|
return pred_(value) ? new_ : value;
|
||||||
|
|
|
@ -12,16 +12,16 @@ namespace sprout {
|
||||||
class replace_value {
|
class replace_value {
|
||||||
public:
|
public:
|
||||||
typedef T result_type;
|
typedef T result_type;
|
||||||
typedef T const& argument_type;
|
typedef T argument_type;
|
||||||
private:
|
private:
|
||||||
T old_;
|
T old_;
|
||||||
T new_;
|
T new_;
|
||||||
public:
|
public:
|
||||||
SPROUT_CONSTEXPR replace_value(T const& old_value, T const& new_value)
|
SPROUT_CONSTEXPR replace_value(T const& old_value, T const& new_value)
|
||||||
: old_(old_value)
|
: old_(old_value), new_(new_value)
|
||||||
, new_(new_value)
|
|
||||||
{}
|
{}
|
||||||
SPROUT_CONSTEXPR T operator()(T const& value) const {
|
SPROUT_CONSTEXPR T
|
||||||
|
operator()(T const& value) const {
|
||||||
return (value == old_) ? new_ : value;
|
return (value == old_) ? new_ : value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -215,15 +215,24 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// gcd_evaluator
|
// gcd_evaluator
|
||||||
//
|
//
|
||||||
template<typename IntType>
|
template<typename IntType = void>
|
||||||
class gcd_evaluator {
|
class gcd_evaluator {
|
||||||
public:
|
public:
|
||||||
typedef IntType result_type;
|
typedef IntType result_type;
|
||||||
typedef IntType first_argument_type;
|
typedef IntType first_argument_type;
|
||||||
typedef IntType second_argument_type;
|
typedef IntType second_argument_type;
|
||||||
public:
|
public:
|
||||||
SPROUT_CONSTEXPR result_type
|
SPROUT_CONSTEXPR IntType
|
||||||
operator()(first_argument_type const& a, second_argument_type const& b) const {
|
operator()(IntType const& a, IntType const& b) const {
|
||||||
|
return sprout::math::detail::gcd_optimal(a, b);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
class gcd_evaluator<void> {
|
||||||
|
public:
|
||||||
|
template<typename IntType>
|
||||||
|
SPROUT_CONSTEXPR IntType
|
||||||
|
operator()(IntType const& a, IntType const& b) const {
|
||||||
return sprout::math::detail::gcd_optimal(a, b);
|
return sprout::math::detail::gcd_optimal(a, b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,15 +74,24 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// lcm_evaluator
|
// lcm_evaluator
|
||||||
//
|
//
|
||||||
template<typename IntType>
|
template<typename IntType = void>
|
||||||
class lcm_evaluator {
|
class lcm_evaluator {
|
||||||
public:
|
public:
|
||||||
typedef IntType result_type;
|
typedef IntType result_type;
|
||||||
typedef IntType first_argument_type;
|
typedef IntType first_argument_type;
|
||||||
typedef IntType second_argument_type;
|
typedef IntType second_argument_type;
|
||||||
public:
|
public:
|
||||||
SPROUT_CONSTEXPR result_type
|
SPROUT_CONSTEXPR IntType
|
||||||
operator()(first_argument_type const& a, second_argument_type const& b) const {
|
operator()(IntType const& a, IntType const& b) const {
|
||||||
|
return sprout::math::detail::lcm_optimal(a, b);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
class lcm_evaluator<void> {
|
||||||
|
public:
|
||||||
|
template<typename IntType>
|
||||||
|
SPROUT_CONSTEXPR IntType
|
||||||
|
operator()(IntType const& a, IntType const& b) const {
|
||||||
return sprout::math::detail::lcm_optimal(a, b);
|
return sprout::math::detail::lcm_optimal(a, b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <sprout/container/traits.hpp>
|
#include <sprout/container/traits.hpp>
|
||||||
#include <sprout/container/functions.hpp>
|
#include <sprout/container/functions.hpp>
|
||||||
#include <sprout/iterator/transform_iterator.hpp>
|
#include <sprout/iterator/transform_iterator.hpp>
|
||||||
|
#include <sprout/iterator/amplitude_spectrum_iterator.hpp>
|
||||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||||
#include <sprout/utility/forward.hpp>
|
#include <sprout/utility/forward.hpp>
|
||||||
|
@ -14,18 +15,6 @@
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace adaptors {
|
namespace adaptors {
|
||||||
namespace detail {
|
|
||||||
template<typename T>
|
|
||||||
class amplitude_spectrum_value {
|
|
||||||
public:
|
|
||||||
typedef typename T::value_type result_type;
|
|
||||||
typedef T argument_type;
|
|
||||||
public:
|
|
||||||
SPROUT_CONSTEXPR result_type operator()(T const& value) const {
|
|
||||||
return sprout::amplitude_spectrum_value(value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace detail
|
|
||||||
//
|
//
|
||||||
// amplitude_spectrum_range
|
// amplitude_spectrum_range
|
||||||
//
|
//
|
||||||
|
@ -34,7 +23,7 @@ namespace sprout {
|
||||||
: public sprout::adaptors::detail::adapted_range_default<
|
: public sprout::adaptors::detail::adapted_range_default<
|
||||||
Range,
|
Range,
|
||||||
sprout::transform_iterator<
|
sprout::transform_iterator<
|
||||||
sprout::adaptors::detail::amplitude_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
sprout::amplitude_value<typename sprout::container_traits<Range>::value_type>,
|
||||||
typename sprout::container_traits<Range>::iterator
|
typename sprout::container_traits<Range>::iterator
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
|
@ -43,7 +32,7 @@ namespace sprout {
|
||||||
typedef sprout::adaptors::detail::adapted_range_default<
|
typedef sprout::adaptors::detail::adapted_range_default<
|
||||||
Range,
|
Range,
|
||||||
sprout::transform_iterator<
|
sprout::transform_iterator<
|
||||||
sprout::adaptors::detail::amplitude_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
sprout::amplitude_value<typename sprout::container_traits<Range>::value_type>,
|
||||||
typename sprout::container_traits<Range>::iterator
|
typename sprout::container_traits<Range>::iterator
|
||||||
>
|
>
|
||||||
> base_type;
|
> base_type;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <sprout/container/traits.hpp>
|
#include <sprout/container/traits.hpp>
|
||||||
#include <sprout/container/functions.hpp>
|
#include <sprout/container/functions.hpp>
|
||||||
#include <sprout/iterator/transform_iterator.hpp>
|
#include <sprout/iterator/transform_iterator.hpp>
|
||||||
|
#include <sprout/iterator/phase_spectrum_iterator.hpp>
|
||||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||||
#include <sprout/utility/forward.hpp>
|
#include <sprout/utility/forward.hpp>
|
||||||
|
@ -14,18 +15,6 @@
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace adaptors {
|
namespace adaptors {
|
||||||
namespace detail {
|
|
||||||
template<typename T>
|
|
||||||
class phase_spectrum_value {
|
|
||||||
public:
|
|
||||||
typedef typename T::value_type result_type;
|
|
||||||
typedef T argument_type;
|
|
||||||
public:
|
|
||||||
SPROUT_CONSTEXPR result_type operator()(T const& value) const {
|
|
||||||
return sprout::phase_spectrum_value(value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace detail
|
|
||||||
//
|
//
|
||||||
// phase_spectrum_range
|
// phase_spectrum_range
|
||||||
//
|
//
|
||||||
|
@ -34,7 +23,7 @@ namespace sprout {
|
||||||
: public sprout::adaptors::detail::adapted_range_default<
|
: public sprout::adaptors::detail::adapted_range_default<
|
||||||
Range,
|
Range,
|
||||||
sprout::transform_iterator<
|
sprout::transform_iterator<
|
||||||
sprout::adaptors::detail::phase_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
sprout::phase_value<typename sprout::container_traits<Range>::value_type>,
|
||||||
typename sprout::container_traits<Range>::iterator
|
typename sprout::container_traits<Range>::iterator
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
|
@ -43,7 +32,7 @@ namespace sprout {
|
||||||
typedef sprout::adaptors::detail::adapted_range_default<
|
typedef sprout::adaptors::detail::adapted_range_default<
|
||||||
Range,
|
Range,
|
||||||
sprout::transform_iterator<
|
sprout::transform_iterator<
|
||||||
sprout::adaptors::detail::phase_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
sprout::phase_value<typename sprout::container_traits<Range>::value_type>,
|
||||||
typename sprout::container_traits<Range>::iterator
|
typename sprout::container_traits<Range>::iterator
|
||||||
>
|
>
|
||||||
> base_type;
|
> base_type;
|
||||||
|
|
Loading…
Add table
Reference in a new issue