diff --git a/sprout/brainfuck/brainfuck.hpp b/sprout/brainfuck/brainfuck.hpp index f5811149..8b4317c0 100644 --- a/sprout/brainfuck/brainfuck.hpp +++ b/sprout/brainfuck/brainfuck.hpp @@ -14,6 +14,7 @@ #include #include #include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT namespace sprout { namespace brainfuck { @@ -68,7 +69,12 @@ namespace sprout { { typedef typename std::iterator_traits::value_type value_type; typedef typename sprout::container_traits::value_type out_value_type; - return first == last ? sprout::fixed::copy(out_buffer.begin(), out_buffer.end(), output) + return first == last + ? sprout::fixed::copy( + sprout::begin(out_buffer), + sprout::next(sprout::begin(out_buffer), NS_SSCRISK_CEL_OR_SPROUT::min(out_pos, sprout::size(out_buffer))), + output + ) : *first == value_type('>') ? sprout::brainfuck::detail::exec_impl( sprout::next(first), last, output, in_first, in_last, diff --git a/sprout/iterator/alternate_iterator.hpp b/sprout/iterator/alternate_iterator.hpp index 25d5fd5a..3c44cb55 100644 --- a/sprout/iterator/alternate_iterator.hpp +++ b/sprout/iterator/alternate_iterator.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT namespace sprout { @@ -242,7 +242,10 @@ namespace sprout { sprout::alternate_iterator const& rhs ) { - return lhs.base() - rhs.base() + (lhs.is_in_left() ? (rhs.is_in_left() ? 0 : 1) : (rhs.is_in_left() ? 1 : 0)); + return sprout::limited::plus( + sprout::limited::multiplies(lhs.base() - rhs.base(), 2), + lhs.is_in_left() ? (rhs.is_in_left() ? 0 : 1) : (rhs.is_in_left() ? 1 : 0) + ); } template inline SPROUT_CONSTEXPR sprout::alternate_iterator operator+( diff --git a/sprout/range/adaptor/copied.hpp b/sprout/range/adaptor/copied.hpp index ac36810b..740845fc 100644 --- a/sprout/range/adaptor/copied.hpp +++ b/sprout/range/adaptor/copied.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -21,17 +21,11 @@ namespace sprout { // template class copied_range - : public sprout::range::range_container< - typename sprout::container_traits::iterator - > - , public sprout::detail::container_nosy_static_size - , public sprout::detail::container_nosy_fixed_size + : public sprout::adaptors::detail::adapted_range_default { public: - typedef Range range_type; - typedef sprout::range::range_container< - typename sprout::container_traits::iterator - > base_type; + typedef sprout::adaptors::detail::adapted_range_default base_type; + typedef typename base_type::range_type range_type; public: copied_range() = default; copied_range(copied_range const&) = default; @@ -111,28 +105,9 @@ namespace sprout { // container_construct_traits // template - struct container_construct_traits > { - public: - typedef typename sprout::container_construct_traits::copied_type copied_type; - public: - template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { - return sprout::range::fixed::copy(sprout::forward(cont), sprout::pit()); - } - template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { - return sprout::make(sprout::forward(args)...); - } - template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits >::difference_type size, - Args&&... args - ) - { - return sprout::remake(sprout::forward(cont), size, sprout::forward(args)...); - } - }; + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; } // namespace sprout #endif // #ifndef SPROUT_RANGE_ADAPTOR_COPIED_HPP diff --git a/sprout/range/adaptor/detail/adapted_range_default.hpp b/sprout/range/adaptor/detail/adapted_range_default.hpp new file mode 100644 index 00000000..dbbdc4a5 --- /dev/null +++ b/sprout/range/adaptor/detail/adapted_range_default.hpp @@ -0,0 +1,63 @@ +#ifndef SPROUT_RANGE_ADAPTOR_DETAIL_ADAPTED_RANGE_DEFAULT_HPP +#define SPROUT_RANGE_ADAPTOR_DETAIL_ADAPTED_RANGE_DEFAULT_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace adaptors { + namespace detail { + template::iterator> + class adapted_range_default + : public sprout::range::range_container + , public sprout::detail::container_nosy_static_size + , public sprout::detail::container_nosy_fixed_size + { + public: + typedef Range range_type; + typedef sprout::range::range_container base_type; + typedef typename base_type::iterator iterator; + public: + adapted_range_default() = default; + adapted_range_default(adapted_range_default const&) = default; + explicit SPROUT_CONSTEXPR adapted_range_default(iterator const& first, iterator const& last) + : base_type(first, last) + {} + }; + } // namespace detail + } // namespace adaptors + + // + // container_construct_traits + // + template + struct container_construct_traits > { + public: + typedef typename sprout::container_construct_traits::copied_type copied_type; + public: + template + static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { + return sprout::range::fixed::copy(sprout::forward(cont), sprout::pit()); + } + template + static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + return sprout::make(sprout::forward(args)...); + } + template + static SPROUT_CONSTEXPR copied_type remake( + Cont&& cont, + typename sprout::container_traits >::difference_type size, + Args&&... args + ) + { + return sprout::remake(sprout::forward(cont), size, sprout::forward(args)...); + } + }; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ADAPTOR_DETAIL_ADAPTED_RANGE_DEFAULT_HPP diff --git a/sprout/range/adaptor/dropped.hpp b/sprout/range/adaptor/dropped.hpp index 6b8dbe8d..8278d075 100644 --- a/sprout/range/adaptor/dropped.hpp +++ b/sprout/range/adaptor/dropped.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT @@ -54,15 +54,15 @@ namespace sprout { // operator| // template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::drop_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type >( sprout::next( sprout::begin(sprout::lvalue_forward(lhs)), diff --git a/sprout/range/adaptor/dropped_end.hpp b/sprout/range/adaptor/dropped_end.hpp index aa8f9d13..3bd98de8 100644 --- a/sprout/range/adaptor/dropped_end.hpp +++ b/sprout/range/adaptor/dropped_end.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT @@ -54,15 +54,15 @@ namespace sprout { // operator| // template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::drop_end_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type >( sprout::begin(sprout::lvalue_forward(lhs)), sprout::next( diff --git a/sprout/range/adaptor/offset.hpp b/sprout/range/adaptor/offset.hpp index 1646b7b0..d155cc32 100644 --- a/sprout/range/adaptor/offset.hpp +++ b/sprout/range/adaptor/offset.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -78,16 +78,16 @@ namespace sprout { // operator| // template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::offset_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator - >( + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type + >( sprout::next( sprout::begin(sprout::lvalue_forward(lhs)), NS_SSCRISK_CEL_OR_SPROUT::min(rhs.from_begin(), sprout::size(sprout::lvalue_forward(lhs))) @@ -102,15 +102,15 @@ namespace sprout { ); } template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::offset_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type >( sprout::next( sprout::begin(sprout::lvalue_forward(lhs)), diff --git a/sprout/range/adaptor/reversed.hpp b/sprout/range/adaptor/reversed.hpp index c0325c93..fcab0c49 100644 --- a/sprout/range/adaptor/reversed.hpp +++ b/sprout/range/adaptor/reversed.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -20,21 +20,17 @@ namespace sprout { // template class reversed_range - : public sprout::range::range_container< - sprout::reverse_iterator< - typename sprout::container_traits::iterator - > + : public sprout::adaptors::detail::adapted_range_default< + Range, + sprout::reverse_iterator::iterator> > - , public sprout::detail::container_nosy_static_size - , public sprout::detail::container_nosy_fixed_size { public: - typedef Range range_type; - typedef sprout::range::range_container< - sprout::reverse_iterator< - typename sprout::container_traits::iterator - > + typedef sprout::adaptors::detail::adapted_range_default< + Range, + sprout::reverse_iterator::iterator> > base_type; + typedef typename base_type::range_type range_type; typedef typename base_type::iterator iterator; public: reversed_range() = default; @@ -79,28 +75,9 @@ namespace sprout { // container_construct_traits // template - struct container_construct_traits > { - public: - typedef typename sprout::container_construct_traits::copied_type copied_type; - public: - template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { - return sprout::range::fixed::copy(sprout::forward(cont), sprout::pit()); - } - template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { - return sprout::make(sprout::forward(args)...); - } - template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits >::difference_type size, - Args&&... args - ) - { - return sprout::remake(sprout::forward(cont), size, sprout::forward(args)...); - } - }; + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; } // namespace sprout #endif // #ifndef SPROUT_RANGE_ADAPTOR_REVERSED_HPP diff --git a/sprout/range/adaptor/taken.hpp b/sprout/range/adaptor/taken.hpp index 6fbf9c4e..f578c18d 100644 --- a/sprout/range/adaptor/taken.hpp +++ b/sprout/range/adaptor/taken.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT @@ -54,15 +54,15 @@ namespace sprout { // operator| // template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::take_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type >( sprout::begin(sprout::lvalue_forward(lhs)), sprout::next( diff --git a/sprout/range/adaptor/taken_end.hpp b/sprout/range/adaptor/taken_end.hpp index ed25571a..16377f2f 100644 --- a/sprout/range/adaptor/taken_end.hpp +++ b/sprout/range/adaptor/taken_end.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT @@ -54,15 +54,15 @@ namespace sprout { // operator| // template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::take_end_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type >( sprout::next( sprout::end(sprout::lvalue_forward(lhs)), diff --git a/sprout/range/adaptor/transformed.hpp b/sprout/range/adaptor/transformed.hpp index 30a943df..fc475419 100644 --- a/sprout/range/adaptor/transformed.hpp +++ b/sprout/range/adaptor/transformed.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -21,21 +21,21 @@ namespace sprout { // template class transformed_range - : public sprout::range::range_container< + : public sprout::adaptors::detail::adapted_range_default< + LRange, sprout::transform_iterator< BinaryFunction, typename sprout::container_traits::iterator, typename sprout::container_traits::iterator > > - , public sprout::detail::container_nosy_static_size - , public sprout::detail::container_nosy_fixed_size { public: typedef BinaryFunction functor_type; - typedef LRange range_type; + typedef LRange range1_type; typedef RRange range2_type; - typedef sprout::range::range_container< + typedef sprout::adaptors::detail::adapted_range_default< + LRange, sprout::transform_iterator< BinaryFunction, typename sprout::container_traits::iterator, @@ -43,11 +43,10 @@ namespace sprout { > > base_type; typedef typename base_type::iterator iterator; - typedef typename base_type::size_type size_type; public: transformed_range() = default; transformed_range(transformed_range const&) = default; - SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range1, range2_type& range2) + SPROUT_CONSTEXPR transformed_range(functor_type func, range1_type& range1, range2_type& range2) : base_type( iterator(sprout::begin(range1), sprout::begin(range2), func), iterator(sprout::end(range1), sprout::end(range2), func) @@ -57,19 +56,19 @@ namespace sprout { template class transformed_range - : public sprout::range::range_container< + : public sprout::adaptors::detail::adapted_range_default< + Range, sprout::transform_iterator< UnaryFunction, typename sprout::container_traits::iterator > > - , public sprout::detail::container_nosy_static_size - , public sprout::detail::container_nosy_fixed_size { public: typedef UnaryFunction functor_type; - typedef Range range_type; - typedef sprout::range::range_container< + typedef Range range1_type; + typedef sprout::adaptors::detail::adapted_range_default< + Range, sprout::transform_iterator< UnaryFunction, typename sprout::container_traits::iterator @@ -79,7 +78,7 @@ namespace sprout { public: transformed_range() = default; transformed_range(transformed_range const&) = default; - SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range) + SPROUT_CONSTEXPR transformed_range(functor_type func, range1_type& range) : base_type( iterator(sprout::begin(range), func), iterator(sprout::end(range), func) @@ -202,28 +201,9 @@ namespace sprout { // container_construct_traits // template - struct container_construct_traits > { - public: - typedef typename sprout::container_construct_traits::copied_type copied_type; - public: - template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { - return sprout::range::fixed::copy(sprout::forward(cont), sprout::pit()); - } - template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { - return sprout::make(sprout::forward(args)...); - } - template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits >::difference_type size, - Args&&... args - ) - { - return sprout::remake(sprout::forward(cont), size, sprout::forward(args)...); - } - }; + struct container_construct_traits > + : public sprout::container_construct_traits::base_type> + {}; } // namespace sprout #endif // #ifndef SPROUT_RANGE_ADAPTOR_TRANSFORMD_HPP diff --git a/sprout/range/adaptor/window.hpp b/sprout/range/adaptor/window.hpp index 5ffda72c..506838b7 100644 --- a/sprout/range/adaptor/window.hpp +++ b/sprout/range/adaptor/window.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -78,15 +78,15 @@ namespace sprout { // operator| // template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::window_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type >( sprout::next( sprout::begin(sprout::lvalue_forward(lhs)), @@ -99,15 +99,15 @@ namespace sprout { ); } template - inline SPROUT_CONSTEXPR sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::window_holder const& rhs) { typedef typename sprout::container_traits< typename std::remove_reference::type>::type >::difference_type difference_type; - return sprout::range::range_container< - typename sprout::container_traits::type>::type>::iterator + return sprout::adaptors::detail::adapted_range_default< + typename std::remove_reference::type>::type >( sprout::next( sprout::begin(sprout::lvalue_forward(lhs)), diff --git a/sprout/utility/limited.hpp b/sprout/utility/limited.hpp new file mode 100644 index 00000000..8b57eb2a --- /dev/null +++ b/sprout/utility/limited.hpp @@ -0,0 +1,46 @@ +#ifndef SPROUT_INTEGER_LIMITED_HPP +#define SPROUT_INTEGER_LIMITED_HPP + +#include +#include +#include + +namespace sprout { + namespace limited { + // + // plus + // + template + inline SPROUT_CONSTEXPR typename sprout::arithmetic_promote::type + plus(T const& lhs, U const& rhs) { + typedef typename sprout::arithmetic_promote::type type; + return lhs > 0 && rhs > 0 && std::numeric_limits::max() - lhs < rhs + ? std::numeric_limits::max() + : lhs < 0 && rhs < 0 && std::numeric_limits::min() - lhs > rhs + ? std::numeric_limits::min() + : lhs + rhs + ; + } + + // + // multiplies + // + template + inline SPROUT_CONSTEXPR typename sprout::arithmetic_promote::type + multiplies(T const& lhs, U const& rhs) { + typedef typename sprout::arithmetic_promote::type type; + return lhs > 0 && rhs > 0 && std::numeric_limits::max() / lhs + (std::numeric_limits::max() % lhs ? 1 : 0) <= rhs + ? std::numeric_limits::max() + : lhs > 0 && rhs < 0 && std::numeric_limits::min() / rhs + (std::numeric_limits::min() % rhs ? 1 : 0) <= lhs + ? std::numeric_limits::min() + : lhs < 0 && rhs > 0 && std::numeric_limits::min() / lhs + (std::numeric_limits::min() % lhs ? 1 : 0) <= rhs + ? std::numeric_limits::min() + : lhs < 0 && rhs < 0 && -(std::numeric_limits::min() / rhs + (std::numeric_limits::min() % rhs ? 1 : 0)) >= lhs + ? std::numeric_limits::max() + : lhs * rhs + ; + } + } // namespace limited +} // namespace sprout + +#endif // #ifndef SPROUT_INTEGER_LIMITED_HPP diff --git a/sprout/utility/operation_ext.hpp b/sprout/utility/operation_ext.hpp index a79ca805..40bcf0fa 100644 --- a/sprout/utility/operation_ext.hpp +++ b/sprout/utility/operation_ext.hpp @@ -6,5 +6,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_UTILITY_OPERATION_EXT_HPP diff --git a/sprout/weed/parser/directive/replace.hpp b/sprout/weed/parser/directive/replace.hpp index 137a02a5..8e13ff23 100644 --- a/sprout/weed/parser/directive/replace.hpp +++ b/sprout/weed/parser/directive/replace.hpp @@ -45,7 +45,6 @@ namespace sprout { ) const { typedef typename result::type result_type; - typedef typename attribute::type attribute_type; return res.success() ? result_type(true, res.current(), value_) : result_type(false, first, value_) diff --git a/sprout/weed/traits/parser/is_parser.hpp b/sprout/weed/traits/parser/is_parser.hpp index d5d9ad8d..39205590 100644 --- a/sprout/weed/traits/parser/is_parser.hpp +++ b/sprout/weed/traits/parser/is_parser.hpp @@ -18,18 +18,6 @@ namespace sprout { template struct is_parser; template - struct is_parser< - T, - typename std::enable_if< - std::is_const::value - && !std::is_array::value - >::type - > - : public sprout::weed::traits::is_parser< - typename std::remove_const::type - > - {}; - template struct is_parser< T, typename std::enable_if< @@ -68,6 +56,18 @@ namespace sprout { > : public std::true_type {}; + template + struct is_parser< + T, + typename std::enable_if< + std::is_const::value + && !std::is_array::value + >::type + > + : public sprout::weed::traits::is_parser< + typename std::remove_const::type + > + {}; } // namespace traits } // namespace weed } // namespace sprout