diff --git a/sprout/adapt/sscrisk/cel/array.hpp b/sprout/adapt/sscrisk/cel/array.hpp index 71c0fbfa..68449eca 100644 --- a/sprout/adapt/sscrisk/cel/array.hpp +++ b/sprout/adapt/sscrisk/cel/array.hpp @@ -19,8 +19,7 @@ namespace sprout { // template struct container_traits > - : public sprout::detail::container_traits_default_types > - , public sprout::detail::container_traits_default_size > + : public sprout::detail::container_traits_default > { public: typedef sprout::index_iterator&> iterator; diff --git a/sprout/container/container_traits.hpp b/sprout/container/container_traits.hpp index 1f544731..ce78458f 100644 --- a/sprout/container/container_traits.hpp +++ b/sprout/container/container_traits.hpp @@ -3,31 +3,72 @@ #include #include +#include #include +#include +#include namespace sprout { - // - // container_traits - // template struct container_traits; namespace detail { + // + // inherit_if_value_type + // inherit_if_iterator + // inherit_if_const_iterator + // inherit_if_reference + // inherit_if_const_reference + // inherit_if_size_type + // inherit_if_difference_type + // inherit_if_pointer + // inherit_if_static_size + // + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(value_type); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(iterator); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(const_iterator); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(reference); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(const_reference); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(size_type); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(difference_type); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(pointer); + SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(const_pointer); + SPROUT_INHERIT_IF_XXX_CONSTANT_DEF_LAZY(static_size); + + // + // has_static_size + // + SPROUT_HAS_XXX_VALUE_DEF_LAZY(static_size); + + template + struct inherit_if_fixed_size {}; template - struct container_traits_default_types { + struct inherit_if_fixed_size< + Container, + typename std::enable_if::value>::type + > { public: - typedef typename Container::value_type value_type; - typedef typename Container::iterator iterator; - typedef typename Container::const_iterator const_iterator; - typedef typename Container::reference reference; - typedef typename Container::const_reference const_reference; - typedef typename Container::size_type size_type; - typedef typename Container::difference_type difference_type; - typedef typename Container::pointer pointer; - typedef typename Container::const_pointer const_pointer; + static SPROUT_CONSTEXPR decltype(Container::static_size) fixed_size() { + return Container::static_size; + } }; + + template + struct container_traits_default + : public sprout::detail::inherit_if_value_type + , public sprout::detail::inherit_if_iterator + , public sprout::detail::inherit_if_const_iterator + , public sprout::detail::inherit_if_reference + , public sprout::detail::inherit_if_const_reference + , public sprout::detail::inherit_if_size_type + , public sprout::detail::inherit_if_difference_type + , public sprout::detail::inherit_if_pointer + , public sprout::detail::inherit_if_const_pointer + , public sprout::detail::inherit_if_static_size + , public sprout::detail::inherit_if_fixed_size + {}; template - struct container_traits_default_types { + struct container_traits_default { public: typedef T value_type; typedef T* iterator; @@ -38,36 +79,21 @@ namespace sprout { typedef std::ptrdiff_t difference_type; typedef T* pointer; typedef T const* const_pointer; - }; - - template - struct container_traits_default_size { public: - SPROUT_STATIC_CONSTEXPR typename sprout::detail::container_traits_default_types::size_type static_size - = std::tuple_size::value - ; + SPROUT_STATIC_CONSTEXPR size_type static_size = N ; public: - static SPROUT_CONSTEXPR typename sprout::detail::container_traits_default_types::size_type fixed_size() { - return static_size; - } - }; - template - struct container_traits_default_size { - public: - SPROUT_STATIC_CONSTEXPR typename sprout::detail::container_traits_default_types::size_type static_size - = N - ; - public: - static SPROUT_CONSTEXPR typename sprout::detail::container_traits_default_types::size_type fixed_size() { + static SPROUT_CONSTEXPR size_type fixed_size() { return static_size; } }; } // namespace detail + // + // container_traits + // template struct container_traits - : public sprout::detail::container_traits_default_types - , public sprout::detail::container_traits_default_size + : public sprout::detail::container_traits_default {}; template struct container_traits @@ -81,8 +107,7 @@ namespace sprout { template struct container_traits - : public sprout::detail::container_traits_default_types - , public sprout::detail::container_traits_default_size + : public sprout::detail::container_traits_default {}; template struct container_traits diff --git a/sprout/iterator/index_iterator.hpp b/sprout/iterator/index_iterator.hpp index 5ae63234..594a49eb 100644 --- a/sprout/iterator/index_iterator.hpp +++ b/sprout/iterator/index_iterator.hpp @@ -238,7 +238,11 @@ namespace sprout { // template SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - distance(sprout::index_iterator first, sprout::index_iterator last) { + distance( + sprout::index_iterator first, + sprout::index_iterator last + ) + { return last - first; } } // namespace sprout diff --git a/sprout/iterator/reverse_iterator.hpp b/sprout/iterator/reverse_iterator.hpp index 8de21231..34c414d6 100644 --- a/sprout/iterator/reverse_iterator.hpp +++ b/sprout/iterator/reverse_iterator.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace sprout { // @@ -100,13 +101,19 @@ namespace sprout { SPROUT_CONSTEXPR reference operator[](difference_type n) const { return *(deref_tmp - n); } + SPROUT_CONSTEXPR reverse_iterator next() const { + return reverse_iterator(sprout::prev(current)); + } + SPROUT_CONSTEXPR reverse_iterator prev() const { + return reverse_iterator(sprout::next(current)); + } void swap(reverse_iterator& other) { using std::swap; swap(current, other.current); swap(deref_tmp, other.deref_tmp); } }; - template + template SPROUT_CONSTEXPR bool operator==( sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs @@ -114,7 +121,7 @@ namespace sprout { { return lhs.base() == rhs.base(); } - template + template SPROUT_CONSTEXPR bool operator!=( sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs @@ -122,7 +129,7 @@ namespace sprout { { return !(lhs == rhs); } - template + template SPROUT_CONSTEXPR bool operator<( sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs @@ -130,7 +137,7 @@ namespace sprout { { return lhs.base() < rhs.base(); } - template + template SPROUT_CONSTEXPR bool operator>( sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs @@ -138,7 +145,7 @@ namespace sprout { { return rhs < lhs; } - template + template SPROUT_CONSTEXPR bool operator<=( sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs @@ -146,7 +153,7 @@ namespace sprout { { return !(rhs < lhs); } - template + template SPROUT_CONSTEXPR bool operator>=( sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs @@ -154,15 +161,15 @@ namespace sprout { { return !(lhs < rhs); } - template + template SPROUT_CONSTEXPR auto operator-( sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs - ) -> decltype(lhs.current - rhs.current) + ) -> decltype(lhs.base() - rhs.base()) { - return lhs.current - rhs.current; + return lhs.base() - rhs.base(); } - template + template SPROUT_CONSTEXPR sprout::reverse_iterator operator+( typename sprout::reverse_iterator::difference_type n, sprout::reverse_iterator const& it @@ -178,7 +185,57 @@ namespace sprout { void swap(sprout::reverse_iterator& lhs, sprout::reverse_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } + + // + // next + // + template + SPROUT_CONSTEXPR sprout::reverse_iterator next( + sprout::reverse_iterator const& it + ) + { + return it.next(); + } + template + SPROUT_CONSTEXPR sprout::reverse_iterator next( + sprout::reverse_iterator const& it, + typename sprout::reverse_iterator::difference_type n + ) + { + return it + n; + } + + // + // prev + // + template + SPROUT_CONSTEXPR sprout::reverse_iterator prev( + sprout::reverse_iterator const& it + ) + { + return it.prev(); + } + template + SPROUT_CONSTEXPR sprout::reverse_iterator prev( + sprout::reverse_iterator const& it, + typename sprout::reverse_iterator::difference_type n + ) + { + return it - n; + } + + // + // distance + // + template + SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type + distance( + sprout::reverse_iterator first, + sprout::reverse_iterator last + ) + { + return last - first; + } } // namespace sprout #endif // #ifndef SPROUT_ITERATOR_REVERSE_ITERATOR_HPP - diff --git a/sprout/numeric/dft.hpp b/sprout/numeric/dft.hpp index 662e2904..7614f8a1 100644 --- a/sprout/numeric/dft.hpp +++ b/sprout/numeric/dft.hpp @@ -6,6 +6,7 @@ #include #include #include +#include +#include #endif // #ifndef SPROUT_NUMERIC_DFT_HPP - diff --git a/sprout/numeric/dft/fit/sinusoid.hpp b/sprout/numeric/dft/fit/sinusoid.hpp new file mode 100644 index 00000000..44738493 --- /dev/null +++ b/sprout/numeric/dft/fit/sinusoid.hpp @@ -0,0 +1,44 @@ +#ifndef SPROUT_NUMERIC_DFT_FIT_SINUSOID_HPP +#define SPROUT_NUMERIC_DFT_FIT_SINUSOID_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace fit { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::type sinusoid_impl( + Container const& cont, + typename sprout::container_traits::value_type const& frequency, + typename sprout::container_traits::value_type const& amplitude, + typename sprout::container_traits::difference_type offset + ) + { + return sprout::sub_copy( + sprout::get_internal(sprout::fixed::sinusoid(cont, frequency, amplitude)), + offset, + offset + sprout::size(cont) + ); + } + } // namespace detail + // + // sinusoid + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::type sinusoid( + Container const& cont, + typename sprout::container_traits::value_type const& frequency = 1, + typename sprout::container_traits::value_type const& amplitude = 1 + ) + { + return sprout::fit::detail::sinusoid_impl(cont, frequency, amplitude, sprout::internal_begin_offset(cont)); + } + } // namespace fit +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_DFT_FIT_SINUSOID_HPP diff --git a/sprout/numeric/dft/fit/spectrum.hpp b/sprout/numeric/dft/fit/spectrum.hpp new file mode 100644 index 00000000..f1933e8e --- /dev/null +++ b/sprout/numeric/dft/fit/spectrum.hpp @@ -0,0 +1,46 @@ +#ifndef SPROUT_NUMERIC_DFT_FIT_SPECTRUM_HPP +#define SPROUT_NUMERIC_DFT_FIT_SPECTRUM_HPP + +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT +#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + namespace fit { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::type spectrum_impl( + InputIterator first, + InputIterator last, + Result const& result, + typename sprout::container_traits::difference_type offset + ) + { + return sprout::sub_copy( + sprout::get_internal(sprout::fixed::spectrum(first, last, result)), + offset, + offset + NS_SSCRISK_CEL_OR_SPROUT::min(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last), sprout::size(result)) + ); + } + } // namespace detail + // + // spectrum + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::type spectrum( + InputIterator first, + InputIterator last, + Result const& result + ) + { + return sprout::fit::detail::spectrum_impl(first, last, result, sprout::internal_begin_offset(result)); + } + } // namespace fit +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_DFT_FIT_SPECTRUM_HPP diff --git a/sprout/numeric/dft/fixed/sinusoid.hpp b/sprout/numeric/dft/fixed/sinusoid.hpp new file mode 100644 index 00000000..05fee29b --- /dev/null +++ b/sprout/numeric/dft/fixed/sinusoid.hpp @@ -0,0 +1,75 @@ +#ifndef SPROUT_NUMERIC_DFT_FIXED_SINUSOID_HPP +#define SPROUT_NUMERIC_DFT_FIXED_SINUSOID_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace fixed { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + sinusoid_impl( + Container const& cont, + typename sprout::container_traits::value_type const& d, + typename sprout::container_traits::value_type const& amplitude, + sprout::index_tuple, + typename sprout::container_traits::difference_type offset, + typename sprout::container_traits::size_type size + ) + { + typedef typename sprout::container_traits::value_type value_type; + using std::sin; + return sprout::remake( + cont, + size, + (Indexes >= offset && Indexes < offset + size + ? amplitude * sin(d * value_type(Indexes)) + : *sprout::next(sprout::internal_begin(cont), Indexes) + )... + ); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + sinusoid( + Container const& cont, + typename sprout::container_traits::value_type const& frequency, + typename sprout::container_traits::value_type const& amplitude + ) + { + typedef typename sprout::container_traits::value_type value_type; + return sprout::fixed::detail::sinusoid_impl( + cont, + value_type(2) * sprout::math::pi() * frequency / value_type(sprout::size(cont)), + amplitude, + sprout::container_indexes::make(), + sprout::internal_begin_offset(cont), + sprout::size(cont) + ); + } + } // namespace detail + // + // sinusoid + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + sinusoid( + Container const& cont, + typename sprout::container_traits::value_type const& frequency = 1, + typename sprout::container_traits::value_type const& amplitude = 1 + ) + { + return sprout::fixed::detail::sinusoid(cont, frequency, amplitude); + } + } // namespace fixed + + using sprout::fixed::sinusoid; +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_DFT_FIXED_SINUSOID_HPP diff --git a/sprout/numeric/dft/fixed/spectrum.hpp b/sprout/numeric/dft/fixed/spectrum.hpp new file mode 100644 index 00000000..89c8c798 --- /dev/null +++ b/sprout/numeric/dft/fixed/spectrum.hpp @@ -0,0 +1,81 @@ +#ifndef SPROUT_NUMERIC_DFT_FIXED_SPECTRUM_HPP +#define SPROUT_NUMERIC_DFT_FIXED_SPECTRUM_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + namespace fixed { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + spectrum_impl( + InputIterator first, + InputIterator last, + Result const& result, + sprout::index_tuple, + typename sprout::container_traits::difference_type offset, + typename sprout::container_traits::size_type size, + typename sprout::container_traits::size_type input_size + ) + { + using std::sqrt; + using std::real; + using std::imag; + return sprout::remake( + result, + size, + (Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size + ? sqrt( + real(*sprout::next(first, Indexes)) * real(*sprout::next(first, Indexes)) + + imag(*sprout::next(first, Indexes)) * imag(*sprout::next(first, Indexes)) + ) + : *sprout::next(sprout::internal_begin(result), Indexes) + )... + ); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + spectrum( + InputIterator first, + InputIterator last, + Result const& result + ) + { + return sprout::fixed::detail::spectrum_impl( + first, + last, + result, + typename sprout::index_range<0, sprout::container_traits::static_size>::type(), + sprout::internal_begin_offset(result), + sprout::size(result), + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) + ); + } + } // namespace detail + // + // spectrum + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + spectrum( + InputIterator first, + InputIterator last, + Result const& result + ) + { + return sprout::fixed::detail::spectrum(first, last, result); + } + } // namespace fixed + + using sprout::fixed::spectrum; +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_DFT_FIXED_SPECTRUM_HPP diff --git a/sprout/numeric/dft/sinusoid.hpp b/sprout/numeric/dft/sinusoid.hpp new file mode 100644 index 00000000..a83603eb --- /dev/null +++ b/sprout/numeric/dft/sinusoid.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_NUMERIC_DFT_SINUSOID_HPP +#define SPROUT_NUMERIC_DFT_SINUSOID_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_NUMERIC_DFT_SINUSOID_HPP diff --git a/sprout/numeric/dft/spectrum.hpp b/sprout/numeric/dft/spectrum.hpp new file mode 100644 index 00000000..8e9f0d80 --- /dev/null +++ b/sprout/numeric/dft/spectrum.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_NUMERIC_DFT_SPECTRUM_HPP +#define SPROUT_NUMERIC_DFT_SPECTRUM_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_NUMERIC_DFT_SPECTRUM_HPP diff --git a/sprout/range/range_container.hpp b/sprout/range/range_container.hpp index 9b3fcb09..7ffb8b4e 100644 --- a/sprout/range/range_container.hpp +++ b/sprout/range/range_container.hpp @@ -137,7 +137,7 @@ namespace sprout { // template struct container_traits > - : public sprout::detail::container_traits_default_types > + : public sprout::detail::container_traits_default > {}; } // namespace sprout diff --git a/sprout/type_traits/has_xxx.hpp b/sprout/type_traits/has_xxx.hpp index 16460dcf..a944d18e 100644 --- a/sprout/type_traits/has_xxx.hpp +++ b/sprout/type_traits/has_xxx.hpp @@ -15,7 +15,7 @@ std::false_type SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_type_, TYPE), __LINE__)(long); \ template \ struct NAME \ - : decltype(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_type_, TYPE), __LINE__)( 0 ) ) \ + : decltype(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_type_, TYPE), __LINE__)(0)) \ {} // @@ -24,4 +24,23 @@ #define SPROUT_HAS_XXX_TYPE_DEF_LAZY(TYPE) \ SPROUT_HAS_XXX_TYPE_DEF(SPROUT_PP_CAT(has_, TYPE), TYPE) +// +// SPROUT_HAS_XXX_VALUE_DEF +// +#define SPROUT_HAS_XXX_VALUE_DEF(NAME, VALUE) \ + template \ + std::true_type SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_value_, VALUE), __LINE__)(int); \ + template \ + std::false_type SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_value_, VALUE), __LINE__)(long); \ + template \ + struct NAME \ + : decltype(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_value_, VALUE), __LINE__)(0)) \ + {} + +// +// SPROUT_HAS_XXX_VALUE_DEF_LAZY +// +#define SPROUT_HAS_XXX_VALUE_DEF_LAZY(VALUE) \ + SPROUT_HAS_XXX_TYPE_DEF(SPROUT_PP_CAT(has_, VALUE), VALUE) + #endif // #ifndef SPROUT_TYPE_TRAITS_HAS_XXX_HPP diff --git a/sprout/type_traits/inherit_if_xxx.hpp b/sprout/type_traits/inherit_if_xxx.hpp index 5d1fb20e..22b3a4e7 100644 --- a/sprout/type_traits/inherit_if_xxx.hpp +++ b/sprout/type_traits/inherit_if_xxx.hpp @@ -28,4 +28,26 @@ #define SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(TYPE) \ SPROUT_INHERIT_IF_XXX_TYPE_DEF(SPROUT_PP_CAT(inherit_if_, TYPE), TYPE) +// +// SPROUT_INHERIT_IF_XXX_CONSTANT_DEF +// +#define SPROUT_INHERIT_IF_XXX_CONSTANT_DEF(NAME, CONSTANT) \ + SPROUT_HAS_XXX_VALUE_DEF(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_inherit_if_xxx_constant_def_impl_has_, CONSTANT), __LINE__), CONSTANT); \ + template \ + struct NAME {}; \ + template \ + struct NAME< \ + T, \ + typename std::enable_if::value>::type \ + > { \ + public: \ + SPROUT_STATIC_CONSTEXPR decltype(T::CONSTANT) CONSTANT = T::CONSTANT; \ + } + +// +// SPROUT_INHERIT_IF_XXX_CONSTANT_DEF_LAZY +// +#define SPROUT_INHERIT_IF_XXX_CONSTANT_DEF_LAZY(CONSTANT) \ + SPROUT_INHERIT_IF_XXX_CONSTANT_DEF(SPROUT_PP_CAT(inherit_if_, CONSTANT), CONSTANT) + #endif // #ifndef SPROUT_TYPE_TRAITS_INHERIT_IF_XXX_HPP