diff --git a/sprout/cinttypes/div.hpp b/sprout/cinttypes/div.hpp index b7eeb421..407962a4 100644 --- a/sprout/cinttypes/div.hpp +++ b/sprout/cinttypes/div.hpp @@ -15,12 +15,16 @@ #endif #include #include +#include #include #include #include #include +#include +#include #include #include +#include #include namespace sprout { @@ -199,4 +203,37 @@ namespace sprout { } } // namespace sprout +namespace sprout { + // + // container_traits + // + SPROUT_DETAIL_DIV_T_CONTAINER_TRAITS_IMPL(std::intmax_t, sprout::imaxdiv_t); + + // + // container_range_traits + // + SPROUT_DETAIL_DIV_T_CONTAINER_RANGE_TRAITS_IMPL(std::intmax_t, sprout::imaxdiv_t); + + // + // container_construct_traits + // + SPROUT_DETAIL_DIV_T_CONTAINER_CONSTRUCT_TRAITS_IMPL(std::intmax_t, sprout::imaxdiv_t); + + // + // container_transform_traits + // +# define SPROUT_DETAIL_DIV_T_CONTAINER_TRANSFORM_TRAITS2_IMPL(INT_T, DIV_T) \ + template<> \ + struct container_transform_traits { \ + public: \ + template \ + struct rebind_type { \ + public: \ + typedef typename sprout::detail::div_t_traits2::type type; \ + }; \ + } + + SPROUT_DETAIL_DIV_T_CONTAINER_TRANSFORM_TRAITS2_IMPL(std::intmax_t, sprout::imaxdiv_t); +} // namespace sprout + #endif // #ifndef SPROUT_CINTTYPES_DIV_HPP diff --git a/sprout/cstdlib/ascii_to_int.hpp b/sprout/cstdlib/ascii_to_int.hpp index 3d35c40f..357c4205 100644 --- a/sprout/cstdlib/ascii_to_int.hpp +++ b/sprout/cstdlib/ascii_to_int.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/sprout/cstdlib/div.hpp b/sprout/cstdlib/div.hpp index 6d7065b3..df38f754 100644 --- a/sprout/cstdlib/div.hpp +++ b/sprout/cstdlib/div.hpp @@ -14,13 +14,22 @@ #include #include #include +#include #include #include #include +#include +#include +#include +#include #include +#include +#include #include #include #include +#include +#include namespace sprout { // @@ -330,4 +339,206 @@ namespace sprout { } } // namespace sprout +namespace sprout { + namespace detail { + template + SPROUT_CONSTEXPR typename std::remove_reference().quot)>::type& + div_at(Div& d, std::size_t i) + SPROUT_NOEXCEPT_IF_EXPR(std::declval
().quot) + { + return i == 0 ? d.quot + : i == 1 ? d.rem + : (SPROUT_ASSERT(i < 2), d.quot) + ; + } + template + SPROUT_CONSTEXPR typename std::remove_reference().quot)>::type const& + div_at(Div const& d, std::size_t i) + SPROUT_NOEXCEPT_IF_EXPR(std::declval
().quot) + { + return i == 0 ? d.quot + : i == 1 ? d.rem + : (SPROUT_ASSERT(i < 2), d.quot) + ; + } + + template + struct div_at_f; + template<> + struct div_at_f + : public sprout::transparent<> + { + public: + template + SPROUT_CONSTEXPR decltype(sprout::detail::div_at(std::declval(), std::declval())) + operator()(T&& x, U&& y) + const SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::div_at(std::declval(), std::declval())) + { + return sprout::detail::div_at(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y)); + } + }; + } // namespace detail + + // + // container_traits + // +# define SPROUT_DETAIL_DIV_T_CONTAINER_TRAITS_IMPL(INT_T, DIV_T) \ + template<> \ + struct container_traits \ + : public sprout::detail::base_static_size \ + { \ + public: \ + typedef INT_T value_type; \ + typedef sprout::index_iterator > iterator; \ + typedef sprout::index_iterator > const_iterator; \ + typedef INT_T& reference; \ + typedef INT_T const& const_reference; \ + typedef std::size_t size_type; \ + typedef std::ptrdiff_t difference_type; \ + typedef INT_T* pointer; \ + typedef INT_T const* const_pointer; \ + typedef sprout::reverse_iterator reverse_iterator; \ + typedef sprout::reverse_iterator const_reverse_iterator; \ + } + + SPROUT_DETAIL_DIV_T_CONTAINER_TRAITS_IMPL(int, sprout::div_t); + SPROUT_DETAIL_DIV_T_CONTAINER_TRAITS_IMPL(long, sprout::ldiv_t); + SPROUT_DETAIL_DIV_T_CONTAINER_TRAITS_IMPL(long long, sprout::lldiv_t); + + // + // container_range_traits + // +# define SPROUT_DETAIL_DIV_T_CONTAINER_RANGE_TRAITS_IMPL(INT_T, DIV_T) \ + template<> \ + struct container_range_traits { \ + public: \ + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator \ + range_begin(DIV_T& t) { \ + typedef typename sprout::container_traits::iterator type; \ + return type(t, 0); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator \ + range_begin(DIV_T const& t) { \ + typedef typename sprout::container_traits::iterator type; \ + return type(t, 0); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator \ + range_end(DIV_T& t) { \ + typedef typename sprout::container_traits::iterator type; \ + return type(t, 2); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator \ + range_end(DIV_T const& t) { \ + typedef typename sprout::container_traits::iterator type; \ + return type(t, 2); \ + } \ + \ + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type \ + range_size(DIV_T const&) { \ + return 2; \ + } \ + static SPROUT_CONSTEXPR bool \ + range_empty(DIV_T const&) { \ + return false; \ + } \ + \ + static SPROUT_CONSTEXPR typename sprout::container_traits::reference \ + range_front(DIV_T& t) { \ + return sprout::detail::div_at(t, 0); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::reference \ + range_front(DIV_T const& t) { \ + return sprout::detail::div_at(t, 0); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::reference \ + range_back(DIV_T& t) { \ + return sprout::detail::div_at(t, 1); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::reference \ + range_back(DIV_T const& t) { \ + return sprout::detail::div_at(t, 1); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::reference \ + range_at(DIV_T& t, typename sprout::container_traits::size_type i) { \ + return sprout::detail::div_at(t, i); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::reference \ + range_at(DIV_T const& t, typename sprout::container_traits::size_type i) { \ + return sprout::detail::div_at(t, i); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator \ + range_nth(DIV_T& t, typename sprout::container_traits::size_type i) { \ + typedef typename sprout::container_traits::iterator type; \ + return type(t, 0) + i; \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator \ + range_nth(DIV_T const& t, typename sprout::container_traits::size_type i) { \ + typedef typename sprout::container_traits::iterator type; \ + return type(t, 0) + i; \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type \ + range_index_of(DIV_T& t, typename sprout::container_traits::iterator p) { \ + typedef typename sprout::container_traits::iterator type; \ + return sprout::distance(type(t, 0), p); \ + } \ + static SPROUT_CONSTEXPR typename sprout::container_traits::size_type \ + range_index_of(DIV_T const& t, typename sprout::container_traits::iterator p) { \ + typedef typename sprout::container_traits::iterator type; \ + return sprout::distance(type(t, 0), p); \ + } \ + } + + SPROUT_DETAIL_DIV_T_CONTAINER_RANGE_TRAITS_IMPL(int, sprout::div_t); + SPROUT_DETAIL_DIV_T_CONTAINER_RANGE_TRAITS_IMPL(long, sprout::ldiv_t); + SPROUT_DETAIL_DIV_T_CONTAINER_RANGE_TRAITS_IMPL(long long, sprout::lldiv_t); + + // + // container_construct_traits + // +# define SPROUT_DETAIL_DIV_T_CONTAINER_CONSTRUCT_TRAITS_IMPL(INT_T, DIV_T) \ + template<> \ + struct container_construct_traits { \ + public: \ + typedef DIV_T copied_type; \ + public: \ + template \ + static SPROUT_CONSTEXPR copied_type \ + deep_copy(Cont&& cont) { \ + return SPROUT_FORWARD(Cont, cont); \ + } \ + template \ + static SPROUT_CONSTEXPR copied_type \ + make(Args&&... args) { \ + return sprout::detail::div_impl(SPROUT_FORWARD(Args, args)...); \ + } \ + template \ + static SPROUT_CONSTEXPR copied_type \ + remake(Cont&&, typename sprout::container_traits::difference_type size, Args&&... args) { \ + return sprout::detail::div_impl(SPROUT_FORWARD(Args, args)...); \ + } \ + } + + SPROUT_DETAIL_DIV_T_CONTAINER_CONSTRUCT_TRAITS_IMPL(int, sprout::div_t); + SPROUT_DETAIL_DIV_T_CONTAINER_CONSTRUCT_TRAITS_IMPL(long, sprout::ldiv_t); + SPROUT_DETAIL_DIV_T_CONTAINER_CONSTRUCT_TRAITS_IMPL(long long, sprout::lldiv_t); + + // + // container_transform_traits + // +# define SPROUT_DETAIL_DIV_T_CONTAINER_TRANSFORM_TRAITS_IMPL(INT_T, DIV_T) \ + template<> \ + struct container_transform_traits { \ + public: \ + template \ + struct rebind_type { \ + public: \ + typedef typename sprout::detail::div_t_traits::type type; \ + }; \ + } + + SPROUT_DETAIL_DIV_T_CONTAINER_TRANSFORM_TRAITS_IMPL(int, sprout::div_t); + SPROUT_DETAIL_DIV_T_CONTAINER_TRANSFORM_TRAITS_IMPL(long, sprout::ldiv_t); + SPROUT_DETAIL_DIV_T_CONTAINER_TRANSFORM_TRAITS_IMPL(long long, sprout::lldiv_t); +} // namespace sprout + #endif // #ifndef SPROUT_CSTDLIB_DIV_HPP diff --git a/sprout/detail/static_size.hpp b/sprout/detail/static_size.hpp new file mode 100644 index 00000000..c8a130e4 --- /dev/null +++ b/sprout/detail/static_size.hpp @@ -0,0 +1,35 @@ +/*============================================================================= + Copyright (c) 2011-2016 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DETAIL_STATIC_SIZE_HPP +#define SPROUT_DETAIL_STATIC_SIZE_HPP + +#include + +namespace sprout { + namespace detail { + template + struct base_static_size { + public: + SPROUT_STATIC_CONSTEXPR T static_size = V; + public: + static SPROUT_CONSTEXPR T + fixed_size() SPROUT_NOEXCEPT { + return static_size; + } + }; + template + SPROUT_CONSTEXPR_OR_CONST T sprout::detail::base_static_size::static_size; + + template + struct inherit_static_size + : public sprout::detail::base_static_size + {}; + } // namespace detail +} // namespace sprout + +#endif // #ifndef SPROUT_DETAIL_STATIC_SIZE_HPP diff --git a/sprout/iterator/index_iterator.hpp b/sprout/iterator/index_iterator.hpp index 53536e2a..53f22066 100644 --- a/sprout/iterator/index_iterator.hpp +++ b/sprout/iterator/index_iterator.hpp @@ -175,77 +175,77 @@ namespace sprout { } }; - template + template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_same::type, typename std::decay::type>::value, bool >::type - operator==(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { + operator==(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { return lhs.index() == rhs.index(); } - template + template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_same::type, typename std::decay::type>::value, bool >::type - operator!=(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { + operator!=(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { return !(lhs == rhs); } - template + template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_same::type, typename std::decay::type>::value, bool >::type - operator<(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { + operator<(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { return lhs.index() < rhs.index(); } - template + template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_same::type, typename std::decay::type>::value, bool >::type - operator>(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { + operator>(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { return rhs < lhs; } - template + template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_same::type, typename std::decay::type>::value, bool >::type - operator<=(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { + operator<=(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { return !(rhs < lhs); } - template + template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_same::type, typename std::decay::type>::value, bool >::type - operator>=(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { + operator>=(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { return !(lhs < rhs); } - template + template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_same::type, typename std::decay::type>::value, decltype( - std::declval >::difference_type>() - - std::declval >::difference_type>() + std::declval >::difference_type>() + - std::declval >::difference_type>() ) >::type - operator-(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { + operator-(sprout::index_iterator const& lhs, sprout::index_iterator const& rhs) { return lhs.index() - rhs.index(); } - template - inline SPROUT_CONSTEXPR sprout::index_iterator - operator+(typename sprout::index_iterator::difference_type n, sprout::index_iterator const& it) { + template + inline SPROUT_CONSTEXPR sprout::index_iterator + operator+(typename sprout::index_iterator::difference_type n, sprout::index_iterator const& it) { return it + n; } // // swap // - template + template inline SPROUT_CXX14_CONSTEXPR void - swap(sprout::index_iterator& lhs, sprout::index_iterator& rhs) + swap(sprout::index_iterator& lhs, sprout::index_iterator& rhs) SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs)) { lhs.swap(rhs); @@ -266,34 +266,34 @@ namespace sprout { struct is_index_iterator : public sprout::is_index_iterator {}; - template - struct is_index_iterator > + template + struct is_index_iterator > : public sprout::true_type {}; // // iterator_next // - template - inline SPROUT_CONSTEXPR sprout::index_iterator - iterator_next(sprout::index_iterator const& it) { + template + inline SPROUT_CONSTEXPR sprout::index_iterator + iterator_next(sprout::index_iterator const& it) { return it.next(); } // // iterator_prev // - template - inline SPROUT_CONSTEXPR sprout::index_iterator - iterator_prev(sprout::index_iterator const& it) { + template + inline SPROUT_CONSTEXPR sprout::index_iterator + iterator_prev(sprout::index_iterator const& it) { return it.prev(); } // // is_const_iterator_cast_convertible // - template - struct is_const_iterator_cast_convertible, sprout::index_iterator > + template + struct is_const_iterator_cast_convertible, sprout::index_iterator > : public std::is_same::type, typename std::decay::type> {}; // @@ -301,11 +301,11 @@ namespace sprout { // template< typename T, - typename Container, bool C, - typename sprout::enabler_if, T>::value>::type = sprout::enabler + typename Container, bool C, typename Subscript, + typename sprout::enabler_if, T>::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR T - const_iterator_conversion(sprout::index_iterator const& it) { + const_iterator_conversion(sprout::index_iterator const& it) { return T(const_cast(it.base()), it.index()); } } // namespace sprout diff --git a/sprout/math/quaternion/quaternion.hpp b/sprout/math/quaternion/quaternion.hpp index b70fb371..e17aa719 100644 --- a/sprout/math/quaternion/quaternion.hpp +++ b/sprout/math/quaternion/quaternion.hpp @@ -15,23 +15,9 @@ #include #include #include +#include namespace sprout { - namespace detail { - template - struct base_static_size { - public: - SPROUT_STATIC_CONSTEXPR T static_size = V; - }; - template - SPROUT_CONSTEXPR_OR_CONST T sprout::detail::base_static_size::static_size; - - template - struct inherit_static_size - : public sprout::detail::base_static_size - {}; - } // namespace detail - namespace math { #define SPROUT_QUATERNION_ACCESSOR_GENERATOR(type) \