mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +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
|
||||
//
|
||||
template<typename T>
|
||||
template<typename T = void>
|
||||
struct hash {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
|
|
|
@ -10,14 +10,23 @@ namespace sprout {
|
|||
//
|
||||
// amplitude_value
|
||||
//
|
||||
template<typename T>
|
||||
template<typename T = void>
|
||||
class amplitude_value {
|
||||
public:
|
||||
typedef typename T::value_type result_type;
|
||||
typedef T argument_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR amplitude_value() {}
|
||||
SPROUT_CONSTEXPR typename T::value_type operator()(T const& value) const {
|
||||
SPROUT_CONSTEXPR typename T::value_type
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,14 +10,23 @@ namespace sprout {
|
|||
//
|
||||
// phase_value
|
||||
//
|
||||
template<typename T>
|
||||
template<typename T = void>
|
||||
class phase_value {
|
||||
public:
|
||||
typedef typename T::value_type result_type;
|
||||
typedef T argument_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR phase_value() {}
|
||||
SPROUT_CONSTEXPR typename T::value_type operator()(T const& value) const {
|
||||
SPROUT_CONSTEXPR typename T::value_type
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,8 +19,7 @@ namespace sprout {
|
|||
T new_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR replace_value_if(Predicate pred, T const& new_value)
|
||||
: pred_(pred)
|
||||
, new_(new_value)
|
||||
: pred_(pred), new_(new_value)
|
||||
{}
|
||||
SPROUT_CONSTEXPR T operator()(T const& value) const {
|
||||
return pred_(value) ? new_ : value;
|
||||
|
|
|
@ -12,16 +12,16 @@ namespace sprout {
|
|||
class replace_value {
|
||||
public:
|
||||
typedef T result_type;
|
||||
typedef T const& argument_type;
|
||||
typedef T argument_type;
|
||||
private:
|
||||
T old_;
|
||||
T new_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR replace_value(T const& old_value, T const& new_value)
|
||||
: old_(old_value)
|
||||
, new_(new_value)
|
||||
: old_(old_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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -215,15 +215,24 @@ namespace sprout {
|
|||
//
|
||||
// gcd_evaluator
|
||||
//
|
||||
template<typename IntType>
|
||||
template<typename IntType = void>
|
||||
class gcd_evaluator {
|
||||
public:
|
||||
typedef IntType result_type;
|
||||
typedef IntType first_argument_type;
|
||||
typedef IntType second_argument_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type
|
||||
operator()(first_argument_type const& a, second_argument_type const& b) const {
|
||||
SPROUT_CONSTEXPR IntType
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -74,15 +74,24 @@ namespace sprout {
|
|||
//
|
||||
// lcm_evaluator
|
||||
//
|
||||
template<typename IntType>
|
||||
template<typename IntType = void>
|
||||
class lcm_evaluator {
|
||||
public:
|
||||
typedef IntType result_type;
|
||||
typedef IntType first_argument_type;
|
||||
typedef IntType second_argument_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type
|
||||
operator()(first_argument_type const& a, second_argument_type const& b) const {
|
||||
SPROUT_CONSTEXPR IntType
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.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/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
@ -14,18 +15,6 @@
|
|||
|
||||
namespace sprout {
|
||||
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
|
||||
//
|
||||
|
@ -34,7 +23,7 @@ namespace sprout {
|
|||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
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
|
||||
>
|
||||
>
|
||||
|
@ -43,7 +32,7 @@ namespace sprout {
|
|||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
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
|
||||
>
|
||||
> base_type;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.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/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
@ -14,18 +15,6 @@
|
|||
|
||||
namespace sprout {
|
||||
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
|
||||
//
|
||||
|
@ -34,7 +23,7 @@ namespace sprout {
|
|||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
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
|
||||
>
|
||||
>
|
||||
|
@ -43,7 +32,7 @@ namespace sprout {
|
|||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
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
|
||||
>
|
||||
> base_type;
|
||||
|
|
Loading…
Reference in a new issue