From df3023db305ccfdf2041f253b6c946a4d9b6cdc1 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 6 Oct 2012 00:58:56 +0900 Subject: [PATCH] fix coding-stype --- sprout/adapt/sscrisk/cel/array.hpp | 4 +- sprout/array/array.hpp | 9 +- sprout/array/comparison.hpp | 18 +- sprout/array/tuple.hpp | 4 +- sprout/bit/length.hpp | 12 +- sprout/bit/reverse.hpp | 12 +- sprout/cinttypes/abs.hpp | 3 +- sprout/cinttypes/div.hpp | 12 +- sprout/cinttypes/strtoimax.hpp | 12 +- sprout/cinttypes/strtoumax.hpp | 12 +- sprout/complex.hpp | 588 +------------- sprout/complex/complex.hpp | 27 +- sprout/complex/hash.hpp | 3 +- sprout/complex/nearest.hpp | 12 +- sprout/complex/operators.hpp | 132 ++-- sprout/complex/transcendentals.hpp | 217 ++++-- sprout/complex/values.hpp | 30 +- sprout/compressed_pair.hpp | 86 ++- .../container/container_construct_traits.hpp | 14 +- sprout/container/container_traits.hpp | 54 +- .../container/container_transform_traits.hpp | 28 +- sprout/container/deep_copy.hpp | 3 +- sprout/container/detail/array_like.hpp | 52 ++ sprout/container/fixed_size.hpp | 3 +- sprout/container/get_internal.hpp | 3 +- sprout/container/internal_begin.hpp | 9 +- sprout/container/internal_deep_copy.hpp | 3 +- sprout/container/internal_end.hpp | 9 +- sprout/container/make.hpp | 3 +- sprout/container/remake.hpp | 8 +- sprout/container/static_size.hpp | 2 +- sprout/cstdlib/abs.hpp | 21 +- sprout/cstdlib/ascii_to_int.hpp | 12 +- sprout/cstdlib/atof.hpp | 3 +- sprout/cstdlib/atoi.hpp | 6 +- sprout/cstdlib/atol.hpp | 6 +- sprout/cstdlib/atoll.hpp | 6 +- sprout/cstdlib/div.hpp | 21 +- sprout/cstdlib/str_to_float.hpp | 36 +- sprout/cstdlib/str_to_int.hpp | 39 +- sprout/cstdlib/strtod.hpp | 9 +- sprout/cstdlib/strtof.hpp | 9 +- sprout/cstdlib/strtol.hpp | 12 +- sprout/cstdlib/strtold.hpp | 9 +- sprout/cstdlib/strtoll.hpp | 12 +- sprout/cstdlib/strtoul.hpp | 12 +- sprout/cstdlib/strtoull.hpp | 12 +- sprout/cstring/memchr.hpp | 9 +- sprout/cstring/memcmp.hpp | 6 +- sprout/cstring/strchr.hpp | 6 +- sprout/cstring/strcmp.hpp | 3 +- sprout/cstring/strcoll.hpp | 3 +- sprout/cstring/strcspn.hpp | 6 +- sprout/cstring/strlen.hpp | 6 +- sprout/cstring/strncmp.hpp | 3 +- sprout/cstring/strpbrk.hpp | 6 +- sprout/cstring/strrchr.hpp | 6 +- sprout/cstring/strspn.hpp | 6 +- sprout/cstring/strstr.hpp | 6 +- sprout/ctype/ascii.hpp | 42 +- sprout/cwchar/wcschr.hpp | 6 +- sprout/cwchar/wcscmp.hpp | 3 +- sprout/cwchar/wcscoll.hpp | 3 +- sprout/cwchar/wcscspn.hpp | 6 +- sprout/cwchar/wcslen.hpp | 6 +- sprout/cwchar/wcsncmp.hpp | 3 +- sprout/cwchar/wcspbrk.hpp | 6 +- sprout/cwchar/wcsrchr.hpp | 6 +- sprout/cwchar/wcsspn.hpp | 6 +- sprout/cwchar/wcsstr.hpp | 6 +- sprout/cwchar/wmemchr.hpp | 13 +- sprout/cwchar/wmemcmp.hpp | 12 +- sprout/darkroom/access/access.hpp | 7 +- sprout/darkroom/cameras/simple_camera.hpp | 44 +- sprout/darkroom/colors/rgb.hpp | 40 +- sprout/darkroom/coords/vector.hpp | 52 +- sprout/darkroom/intersects/intersection.hpp | 35 +- sprout/darkroom/lights/ambient_light.hpp | 3 +- sprout/darkroom/lights/light_list.hpp | 12 +- sprout/darkroom/lights/parallel_light.hpp | 22 +- sprout/darkroom/lights/point_light.hpp | 39 +- sprout/darkroom/materials/interpolation.hpp | 3 +- sprout/darkroom/materials/material.hpp | 37 +- sprout/darkroom/materials/plaid.hpp | 38 +- sprout/darkroom/materials/texture_map.hpp | 45 +- sprout/darkroom/materials/uniform.hpp | 6 +- sprout/darkroom/objects/aa_plane.hpp | 70 +- sprout/darkroom/objects/intersect.hpp | 12 +- sprout/darkroom/objects/polygon/triangle.hpp | 65 +- sprout/darkroom/objects/sphere.hpp | 98 +-- sprout/darkroom/pixels/generate.hpp | 82 +- sprout/darkroom/rays/ray.hpp | 14 +- sprout/darkroom/renderers/infinity.hpp | 9 +- sprout/darkroom/renderers/whitted_style.hpp | 145 ++-- sprout/darkroom/textures/texture.hpp | 18 +- sprout/darkroom/tracers/raytracer.hpp | 22 +- sprout/detail/algorithm/count_n.hpp | 8 +- sprout/detail/algorithm/count_n_if.hpp | 8 +- sprout/detail/algorithm/overlap_count.hpp | 48 +- sprout/detail/algorithm/set_overlap_count.hpp | 18 +- sprout/detail/char_conversion.hpp | 12 +- sprout/detail/container_complate.hpp | 34 +- sprout/detail/container_complate_backward.hpp | 34 +- sprout/detail/integer/static_log2.hpp | 20 +- sprout/detail/math/float.hpp | 25 +- sprout/detail/math/int.hpp | 15 +- sprout/detail/param_at.hpp | 34 +- sprout/functional/bind/bind.hpp | 8 +- sprout/generator/generated_value.hpp | 8 +- sprout/generator/next_generator.hpp | 8 +- sprout/index_tuple/make_indexes.hpp | 3 +- sprout/io.hpp | 44 +- sprout/iterator/bytes_iterator.hpp | 45 +- sprout/iterator/counting_iterator.hpp | 89 +-- sprout/iterator/filter_iterator.hpp | 33 +- sprout/iterator/generator_iterator.hpp | 29 +- sprout/iterator/index_iterator.hpp | 39 +- sprout/iterator/next.hpp | 26 +- sprout/iterator/prev.hpp | 26 +- sprout/iterator/reverse_iterator.hpp | 90 +-- sprout/iterator/sawtooth_iterator.hpp | 105 +-- sprout/iterator/sinusoid_iterator.hpp | 107 +-- sprout/iterator/size_enum_iterator.hpp | 77 +- sprout/iterator/square_iterator.hpp | 107 +-- sprout/iterator/transform_iterator.hpp | 51 +- sprout/iterator/triangle_iterator.hpp | 49 +- sprout/iterator/value_iterator.hpp | 41 +- sprout/pit/comparison.hpp | 18 +- sprout/pit/container.hpp | 14 +- sprout/pit/hash.hpp | 3 +- sprout/pit/pit.hpp | 13 +- sprout/pit/tuple.hpp | 6 +- sprout/random/inversive_congruential.hpp | 4 +- sprout/random/iterator.hpp | 8 +- sprout/random/mersenne_twister.hpp | 261 +++++-- sprout/random/normal_distribution.hpp | 31 +- sprout/random/random_result.hpp | 37 +- sprout/random/uniform_int_distribution.hpp | 293 +++---- sprout/random/unique_seed.hpp | 12 +- sprout/range/algorithm/adjacent_find.hpp | 2 +- sprout/range/algorithm/equal_range.hpp | 2 +- sprout/range/algorithm/find.hpp | 2 +- sprout/range/algorithm/find_end.hpp | 2 +- sprout/range/algorithm/find_first_of.hpp | 2 +- sprout/range/algorithm/find_if.hpp | 2 +- sprout/range/algorithm/find_if_not.hpp | 2 +- sprout/range/algorithm/is_heap_until.hpp | 2 +- sprout/range/algorithm/is_sorted_until.hpp | 2 +- sprout/range/algorithm/lower_bound.hpp | 2 +- sprout/range/algorithm/max_element.hpp | 2 +- sprout/range/algorithm/min_element.hpp | 2 +- sprout/range/algorithm/minmax_element.hpp | 2 +- sprout/range/algorithm/mismatch.hpp | 2 +- sprout/range/algorithm/partition_point.hpp | 2 +- sprout/range/algorithm/search.hpp | 2 +- sprout/range/algorithm/search_n.hpp | 2 +- sprout/range/algorithm/upper_bound.hpp | 2 +- sprout/range/range_container.hpp | 13 +- sprout/range/range_return.hpp | 2 +- sprout/rational.hpp | 727 +----------------- sprout/rational/hash.hpp | 3 +- sprout/rational/rational.hpp | 8 +- sprout/string/comparison.hpp | 54 +- sprout/string/concat.hpp | 24 +- sprout/string/container.hpp | 14 +- sprout/string/float_to_string.hpp | 60 +- sprout/string/hash.hpp | 3 +- sprout/string/int_to_string.hpp | 113 +-- sprout/string/shrink.hpp | 6 +- sprout/string/string.hpp | 90 ++- sprout/string/string_to_float.hpp | 55 +- sprout/string/string_to_int.hpp | 84 +- sprout/string/tuple.hpp | 5 +- sprout/sub_array/container.hpp | 23 +- sprout/sub_array/hash.hpp | 3 +- sprout/sub_array/sub.hpp | 105 ++- sprout/sub_array/sub_array.hpp | 17 +- sprout/sub_array/tuple.hpp | 10 +- sprout/tuple/sscrisk/cel/utility.hpp | 43 +- sprout/tuple/tuple/get.hpp | 4 +- sprout/tuple/tuple/tuple.hpp | 29 +- sprout/utility/operation.hpp | 1 + sprout/utility/pack.hpp | 19 +- sprout/utility/pair.hpp | 52 +- sprout/utility/rel_ops.hpp | 12 +- sprout/utility/swap.hpp | 32 + sprout/uuid/hash.hpp | 6 +- sprout/uuid/io.hpp | 6 +- sprout/uuid/nil_generator.hpp | 9 +- sprout/uuid/string_generator.hpp | 27 +- sprout/uuid/tuple.hpp | 2 +- sprout/uuid/udl.hpp | 12 +- sprout/uuid/uuid.hpp | 58 +- sprout/variant/apply_visitor.hpp | 7 +- sprout/variant/tuple.hpp | 4 +- sprout/variant/variant.hpp | 27 +- 196 files changed, 2511 insertions(+), 3946 deletions(-) create mode 100644 sprout/container/detail/array_like.hpp create mode 100644 sprout/utility/swap.hpp diff --git a/sprout/adapt/sscrisk/cel/array.hpp b/sprout/adapt/sscrisk/cel/array.hpp index 08b53f17..97b95fdd 100644 --- a/sprout/adapt/sscrisk/cel/array.hpp +++ b/sprout/adapt/sscrisk/cel/array.hpp @@ -25,7 +25,7 @@ namespace sprout { }; } // namespace sprout -namespace sprout_adl { +namespace sprout { // // range_begin // @@ -53,7 +53,7 @@ namespace sprout_adl { range_end(sscrisk::cel::array const& cont) { return typename sprout::container_traits >::const_iterator(cont, cont.size()); } -} // namespace sprout_adl +} // namespace sprout #endif #endif // #ifndef SPROUT_ADAPT_SSCRISK_CEL_ARRAY_HPP diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp index 9aeb73ff..fea0bf7d 100644 --- a/sprout/array/array.hpp +++ b/sprout/array/array.hpp @@ -63,7 +63,9 @@ namespace sprout { SPROUT_CONSTEXPR array fill(const_reference value) const { return sprout::detail::array_fill_impl(value, sprout::index_n<0, N>::make()); } - void swap(array& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { + void swap(array& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) + { std::swap_ranges(other.begin(), other.end(), begin()); } // iterators: @@ -208,8 +210,9 @@ namespace sprout { // swap // template - inline void swap(sprout::array& lhs, sprout::array& rhs) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + inline void + swap(sprout::array& lhs, sprout::array& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } diff --git a/sprout/array/comparison.hpp b/sprout/array/comparison.hpp index cf70cfe2..2536bd2d 100644 --- a/sprout/array/comparison.hpp +++ b/sprout/array/comparison.hpp @@ -16,27 +16,33 @@ namespace sprout { // operator>= // template - inline SPROUT_CONSTEXPR bool operator==(sprout::array const& lhs, sprout::array const& rhs) { + inline SPROUT_CONSTEXPR bool + operator==(sprout::array const& lhs, sprout::array const& rhs) { return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin()); } template - inline SPROUT_CONSTEXPR bool operator!=(sprout::array const& lhs, sprout::array const& rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::array const& lhs, sprout::array const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator<(sprout::array const& lhs, sprout::array const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<(sprout::array const& lhs, sprout::array const& rhs) { return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } template - inline SPROUT_CONSTEXPR bool operator>(sprout::array const& lhs, sprout::array const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>(sprout::array const& lhs, sprout::array const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator<=(sprout::array const& lhs, sprout::array const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::array const& lhs, sprout::array const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator>=(sprout::array const& lhs, sprout::array const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::array const& lhs, sprout::array const& rhs) { return !(lhs < rhs); } } // namespace sprout diff --git a/sprout/array/tuple.hpp b/sprout/array/tuple.hpp index 96405cdb..42e0c15a 100644 --- a/sprout/array/tuple.hpp +++ b/sprout/array/tuple.hpp @@ -9,7 +9,7 @@ #include #include -namespace sprout_adl { +namespace sprout { // // tuple_get // @@ -30,7 +30,7 @@ namespace sprout_adl { tuple_get(sprout::array&& t) SPROUT_NOEXCEPT { return sprout::move(sprout::tuples::get(t)); } -} // namespace sprout_adl +} // namespace sprout namespace std { // diff --git a/sprout/bit/length.hpp b/sprout/bit/length.hpp index 52792b92..5b2c2c4e 100644 --- a/sprout/bit/length.hpp +++ b/sprout/bit/length.hpp @@ -34,7 +34,8 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT; private: template - SPROUT_CONSTEXPR IntType impl(IntType x, unsigned char i) const { + SPROUT_CONSTEXPR IntType + impl(IntType x, unsigned char i) const { return bit_len_8_table[i] ? bit_len_8_table[i] + next_size * CHAR_BIT : sprout::detail::bit_len().template operator()(x) @@ -42,7 +43,8 @@ namespace sprout { } public: template - SPROUT_CONSTEXPR IntType operator()(IntType x) const { + SPROUT_CONSTEXPR IntType + operator()(IntType x) const { return impl(x, static_cast((x >> shift_bits) & UCHAR_MAX)); } }; @@ -50,7 +52,8 @@ namespace sprout { struct bit_len<1> { public: template - SPROUT_CONSTEXPR IntType operator()(IntType x) const { + SPROUT_CONSTEXPR IntType + operator()(IntType x) const { return bit_len_8_table[static_cast(x & UCHAR_MAX)]; } }; @@ -62,7 +65,8 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< std::is_integral::value, IntType - >::type bit_length(IntType x) { + >::type + bit_length(IntType x) { return sprout::detail::bit_len().template operator()(x); } } // namespace sprout diff --git a/sprout/bit/reverse.hpp b/sprout/bit/reverse.hpp index d2332800..b6b5887a 100644 --- a/sprout/bit/reverse.hpp +++ b/sprout/bit/reverse.hpp @@ -31,7 +31,8 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT; public: template - SPROUT_CONSTEXPR IntType operator()(IntType x) const { + SPROUT_CONSTEXPR IntType + operator()(IntType x) const { return (sprout::detail::bit_rev().template operator()(x) << shift_bits) | (sprout::detail::bit_rev().template operator()(x >> shift_bits)) ; @@ -41,7 +42,8 @@ namespace sprout { struct bit_rev<1> { public: template - SPROUT_CONSTEXPR IntType operator()(IntType x) const { + SPROUT_CONSTEXPR IntType + operator()(IntType x) const { return sprout::detail::bit_rev_8_table[static_cast(x & UCHAR_MAX)]; } }; @@ -53,7 +55,8 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< std::is_integral::value, IntType - >::type bit_reverse(IntType x) { + >::type + bit_reverse(IntType x) { typedef typename std::make_unsigned::type unsigned_type; return static_cast( sprout::detail::bit_rev().template operator()(x) @@ -66,7 +69,8 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< std::is_integral::value, IntType - >::type bit_reverse_in(IntType x, std::size_t length) { + >::type + bit_reverse_in(IntType x, std::size_t length) { typedef typename std::make_unsigned::type unsigned_type; return length <= sizeof(IntType) * CHAR_BIT ? static_cast( diff --git a/sprout/cinttypes/abs.hpp b/sprout/cinttypes/abs.hpp index c635817d..c787b8cc 100644 --- a/sprout/cinttypes/abs.hpp +++ b/sprout/cinttypes/abs.hpp @@ -7,7 +7,8 @@ #include namespace sprout { - inline SPROUT_CONSTEXPR std::intmax_t imaxabs(std::intmax_t j) { + inline SPROUT_CONSTEXPR std::intmax_t + imaxabs(std::intmax_t j) { return j < 0 ? -j : j; } } // namespace sprout diff --git a/sprout/cinttypes/div.hpp b/sprout/cinttypes/div.hpp index 7a02e5b7..119d5a18 100644 --- a/sprout/cinttypes/div.hpp +++ b/sprout/cinttypes/div.hpp @@ -32,7 +32,8 @@ namespace sprout { sprout::detail::div_t_traits2::offsetof_quot == 0 >::type = sprout::enabler > - inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2::type div_impl2(T const& numer, T const& denom) { + inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2::type + div_impl2(T const& numer, T const& denom) { return {numer / denom, numer % denom}; } @@ -42,12 +43,14 @@ namespace sprout { sprout::detail::div_t_traits2::offsetof_rem == 0 >::type = sprout::enabler > - inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2::type div_impl2(T const &numer, T const& denom) { + inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits2::type + div_impl2(T const &numer, T const& denom) { return {numer % denom, numer / denom}; } } // namespace detail - SPROUT_CONSTEXPR std::imaxdiv_t imaxdiv(std::intmax_t numer, std::intmax_t denom) { + inline SPROUT_CONSTEXPR std::imaxdiv_t + imaxdiv(std::intmax_t numer, std::intmax_t denom) { return sprout::detail::div_impl2(numer, denom); } @@ -55,7 +58,8 @@ namespace sprout { typename T, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR std::imaxdiv_t div(T numer, T denom) { + inline SPROUT_CONSTEXPR std::imaxdiv_t + div(T numer, T denom) { return sprout::imaxdiv(numer, denom); } } // namespace sprout diff --git a/sprout/cinttypes/strtoimax.hpp b/sprout/cinttypes/strtoimax.hpp index aa6c9f20..3c3e58b7 100644 --- a/sprout/cinttypes/strtoimax.hpp +++ b/sprout/cinttypes/strtoimax.hpp @@ -10,19 +10,23 @@ namespace sprout { // // strtoimax // - inline SPROUT_CONSTEXPR std::intmax_t strtoimax(char const* str, char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR std::intmax_t + strtoimax(char const* str, char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR std::intmax_t strtoimax(Char const* str, Char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR std::intmax_t + strtoimax(Char const* str, Char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR std::intmax_t strtoimax(Char const* str, std::nullptr_t endptr, int base = 10){ + inline SPROUT_CONSTEXPR std::intmax_t + strtoimax(Char const* str, std::nullptr_t endptr, int base = 10) { return sprout::str_to_int(str, base); } template - inline SPROUT_CONSTEXPR std::intmax_t strtoimax(Char const* str, int base = 10){ + inline SPROUT_CONSTEXPR std::intmax_t + strtoimax(Char const* str, int base = 10) { return sprout::str_to_int(str, base); } } // namespace sprout diff --git a/sprout/cinttypes/strtoumax.hpp b/sprout/cinttypes/strtoumax.hpp index 5f25543b..45b458f8 100644 --- a/sprout/cinttypes/strtoumax.hpp +++ b/sprout/cinttypes/strtoumax.hpp @@ -10,19 +10,23 @@ namespace sprout { // // strtoumax // - inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(char const* str, char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR std::uintmax_t + strtoumax(char const* str, char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(Char const* str, Char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR std::uintmax_t + strtoumax(Char const* str, Char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(Char const* str, std::nullptr_t endptr, int base = 10){ + inline SPROUT_CONSTEXPR std::uintmax_t + strtoumax(Char const* str, std::nullptr_t endptr, int base = 10) { return sprout::str_to_int(str, base); } template - inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(Char const* str, int base = 10){ + inline SPROUT_CONSTEXPR std::uintmax_t + strtoumax(Char const* str, int base = 10) { return sprout::str_to_int(str, base); } } // namespace sprout diff --git a/sprout/complex.hpp b/sprout/complex.hpp index 34dfff14..a61c0f41 100644 --- a/sprout/complex.hpp +++ b/sprout/complex.hpp @@ -1,588 +1,12 @@ #ifndef SPROUT_COMPLEX_HPP #define SPROUT_COMPLEX_HPP -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace sprout { - template - class complex; - template - SPROUT_CONSTEXPR T norm(sprout::complex const& x); - // - // complex - // - template - class complex { - public: - typedef T value_type; - private: - T re_; - T im_; - public: - SPROUT_CONSTEXPR complex(T const& re = T(), T const& im = T()) - : re_(re) - , im_(im) - {} - SPROUT_CONSTEXPR complex(complex const&) = default; - template - SPROUT_CONSTEXPR complex(complex const& other) - : re_(other.real()) - , im_(other.imag()) - {} - SPROUT_CONSTEXPR T real() const { - return re_; - } - void real(T re) { - re_ = re; - } - SPROUT_CONSTEXPR T imag() const{ - return im_; - } - void imag(T im) { - im_ = im; - } - complex& operator=(T const& rhs) { - re_ = rhs; - im_ = T(); - return *this; - } - complex& operator+=(T const& rhs) { - re_ += rhs; - return *this; - } - complex& operator-=(T const& rhs) { - re_ -= rhs; - return *this; - } - complex& operator*=(T const& rhs) { - re_ *= rhs; - im_ *= rhs; - return *this; - } - complex& operator/=(T const& rhs) { - re_ /= rhs; - im_ /= rhs; - return *this; - } - complex& operator=(complex const&) = default; - template - complex& operator=(complex const& rhs) { - re_ = rhs.real(); - im_ = rhs.imag(); - return *this; - } - template - complex& operator+=(complex const& rhs) { - re_ += rhs.real(); - im_ += rhs.imag(); - return *this; - } - template - complex& operator-=(complex const& rhs) { - re_ -= rhs.real(); - im_ -= rhs.imag(); - return *this; - } - template - complex& operator*=(complex const& rhs) { - return *this = complex( - re_ * rhs.real() - im_ * rhs.imag(), - re_ * rhs.imag() + im_ * rhs.real() - ); - } - template - complex& operator/=(complex const& rhs) { - T n = sprout::norm(rhs); - return *this = complex( - (re_ * rhs.real() + im_ * rhs.imag()) / n, - (im_ * rhs.real() - re_ * rhs.imag()) / n - ); - } - }; - // 26.4.6, operators: - template - inline SPROUT_CONSTEXPR sprout::complex operator+(sprout::complex const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs.real() + rhs.real(), - lhs.imag() + rhs.imag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator+(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() + rhs, - lhs.imag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator+(T const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs + rhs.real(), - rhs.imag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator-(sprout::complex const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs.real() - rhs.real(), - lhs.imag() - rhs.imag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator-(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() - rhs, - lhs.imag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator-(T const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs - rhs.real(), - -rhs.imag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator*(sprout::complex const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs.real() * rhs.real() - lhs.imag() * rhs.imag(), - lhs.real() * rhs.imag() + lhs.imag() * rhs.real() - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator*(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() * rhs, - lhs.imag() * rhs - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator*(T const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs * rhs.real(), - lhs * rhs.imag() - ); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex divides_impl( - sprout::complex const& lhs, - sprout::complex const& rhs, - T const& n - ) - { - return sprout::complex( - (lhs.real() * rhs.real() + lhs.imag() * rhs.imag()) / n, - (lhs.imag() * rhs.real() - lhs.real() * rhs.imag()) / n - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex divides_impl( - T const& lhs, - sprout::complex const& rhs, - T const& n - ) - { - return sprout::complex( - lhs * rhs.real() / n, - -lhs * rhs.imag() / n - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::complex operator/(sprout::complex const& lhs, sprout::complex const& rhs) { - return sprout::detail::divides_impl(lhs, rhs, sprout::norm(rhs)); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator/(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() / rhs, - lhs.imag() / rhs - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator/(T const& lhs, sprout::complex const& rhs) { - return sprout::detail::divides_impl(lhs, rhs, sprout::norm(rhs)); - } - template - inline SPROUT_CONSTEXPR sprout::complex operator+(sprout::complex const& x) { - return x; - } - template - inline SPROUT_CONSTEXPR sprout::complex operator-(sprout::complex const& x) { - return sprout::complex(-x.real(), -x.imag()); - } - template - inline SPROUT_CONSTEXPR bool operator==(sprout::complex const& lhs, sprout::complex const& rhs) { - return lhs.real() == rhs.real() && lhs.imag() == rhs.imag(); - } - template - inline SPROUT_CONSTEXPR bool operator==(sprout::complex const& lhs, T const& rhs) { - return lhs.real() == rhs && lhs.imag() == T(); - } - template - inline SPROUT_CONSTEXPR bool operator==(T const& lhs, sprout::complex const& rhs) { - return lhs == rhs.real() && T() == rhs.imag(); - } - template - inline SPROUT_CONSTEXPR bool operator!=(sprout::complex const& lhs, sprout::complex const& rhs) { - return !(lhs == rhs); - } - template - inline SPROUT_CONSTEXPR bool operator!=(sprout::complex const& lhs, T const& rhs) { - return !(lhs == rhs); - } - template - inline SPROUT_CONSTEXPR bool operator!=(T const& lhs, sprout::complex const& rhs) { - return !(lhs == rhs); - } - template - std::basic_istream& operator>>(std::basic_istream& lhs, sprout::complex& rhs) { - T re, im; - Char ch; - lhs >> ch; - if (ch == '(') { - lhs >> re >> ch; - if (ch == ',') { - lhs >> im >> ch; - if (ch == ')') { - rhs = sprout::complex(re, im); - } else { - lhs.setstate(std::ios_base::failbit); - } - } else if (ch == ')') { - rhs = re; - } else { - lhs.setstate(std::ios_base::failbit); - } - } else { - lhs.putback(ch); - lhs >> re; - rhs = re; - } - return lhs; - } - template - std::basic_ostream& operator<<(std::basic_ostream& lhs, sprout::complex const& rhs) { - return lhs << '(' << rhs.real() << ',' << rhs.imag() << ')'; - } - // 26.4.7, values: - template - inline SPROUT_CONSTEXPR T real(sprout::complex const& x) { - return x.real(); - } - template - inline SPROUT_CONSTEXPR T imag(sprout::complex const& x) { - return x.imag(); - } - template - inline SPROUT_CONSTEXPR T abs(sprout::complex const& x) { - return sprout::sqrt(sprout::norm(x)); - } - template - inline SPROUT_CONSTEXPR T arg(sprout::complex const& x) { - return sprout::atan2(x.imag(), x.real()); - } - template - inline SPROUT_CONSTEXPR T norm(sprout::complex const& x) { - return x.real() * x.real() + x.imag() * x.imag(); - } - template - inline SPROUT_CONSTEXPR sprout::complex conj(sprout::complex const& x) { - return sprout::complex(x.real(), -x.imag()); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex proj_impl(sprout::complex const& x, T const& den) { - return sprout::complex( - T(2) * x.real() / den, - T(2) * x.imag() / den - ); - } - } // detail - template - inline SPROUT_CONSTEXPR sprout::complex proj(sprout::complex const& x) { - return sprout::detail::proj_impl( - x, - sprout::norm(x) + T(1) - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex polar(T const& rho, T const& theta = 0) { - return sprout::complex(rho * sprout::cos(theta), rho * sprout::sin(theta)); - } - // 26.4.8, transcendentals: - template - SPROUT_CONSTEXPR sprout::complex acos(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex asin(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex atan(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex acosh(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex asinh(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex atanh(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex cos(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex cosh(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex exp(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex log(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex log10(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, T const& y); - template - SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, sprout::complex const& y); - template - SPROUT_CONSTEXPR sprout::complex pow(T const& x, sprout::complex const& y); - template - SPROUT_CONSTEXPR sprout::complex sin(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex sinh(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex sqrt(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex tan(sprout::complex const& x); - template - SPROUT_CONSTEXPR sprout::complex tanh(sprout::complex const& x); - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex acos_impl(sprout::complex const& t) { - return sprout::complex(sprout::math::half_pi() - t.real(), -t.imag()); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::complex acos(sprout::complex const& x) { - return sprout::detail::acos_impl(sprout::asin(x)); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex asin_impl(sprout::complex const& t) { - return sprout::complex(t.imag(), -t.real()); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::complex asin(sprout::complex const& x) { - return sprout::detail::asin_impl(sprout::asinh(sprout::complex(-x.imag(), x.real()))); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex atan_impl_1( - sprout::complex const& x, - T const& r2, - T const& z, - T const& num, - T const& den - ) - { - return sprout::complex( - T(0.5) * sprout::atan2(T(2) * x.real(), z), - T(0.25) * sprout::log((r2 + num * num) / (r2 + den * den)) - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex atan_impl( - sprout::complex const& x, - T const& r2 - ) - { - return sprout::detail::atan_impl_1( - x, - r2, - T(1) - r2 - x.imag() * x.imag(), - x.imag() + T(1), - x.imag() - T(1) - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::complex atan(sprout::complex const& x) { - return sprout::detail::atan_impl(x, x.real() * x.real()); - } - template - inline SPROUT_CONSTEXPR sprout::complex acosh(sprout::complex const& x) { - return T(2) * sprout::log(sprout::sqrt(T(0.5) * (x + T(1))) + sprout::sqrt(T(0.5) * (x - T(1)))); - } - template - inline SPROUT_CONSTEXPR sprout::complex asinh(sprout::complex const& x) { - return sprout::log( - sprout::sqrt( - sprout::complex( - (x.real() - x.imag()) * (x.real() + x.imag()) + T(1), - T(2) * x.real() * x.imag() - ) - ) - + x - ); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex atanh_impl_1( - sprout::complex const& x, - T const& i2, - T const& z, - T const& num, - T const& den - ) - { - return sprout::complex( - T(0.25) * (sprout::log(i2 + num * num) - sprout::log(i2 + den * den)), - T(0.5) * sprout::atan2(T(2) * x.imag(), z) - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex atanh_impl( - sprout::complex const& x, - T const& i2 - ) - { - return sprout::detail::atanh_impl_1( - x, - i2, - T(1) - i2 - x.real() * x.real(), - T(1) + x.imag(), - T(1) - x.imag() - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::complex atanh(sprout::complex const& x) { - return sprout::detail::atanh_impl(x, x.imag() * x.imag()); - } - template - inline SPROUT_CONSTEXPR sprout::complex cos(sprout::complex const& x) { - return sprout::complex( - sprout::cos(x.real()) * sprout::cosh(x.imag()), - -(sprout::sin(x.real()) * sprout::sinh(x.imag())) - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex cosh(sprout::complex const& x) { - return sprout::complex( - sprout::cosh(x.real()) * sprout::cos(x.imag()), - sprout::sinh(x.real()) * sprout::sin(x.imag()) - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex exp(sprout::complex const& x) { - return sprout::polar(sprout::exp(x.real()), x.imag()); - } - template - inline SPROUT_CONSTEXPR sprout::complex log(sprout::complex const& x) { - return sprout::complex(sprout::log(sprout::abs(x)), sprout::arg(x)); - } - template - inline SPROUT_CONSTEXPR sprout::complex log10(sprout::complex const& x) { - return sprout::log(x) / sprout::log(T(10)); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex pow_impl(sprout::complex const& t, T const& y) { - return sprout::polar(sprout::exp(y * t.real()), y * t.imag()); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, T const& y) { - return x == T() ? T() - : x.imag() == T() && x.real() > T() ? sprout::pow(x.real(), y) - : sprout::detail::pow_impl(sprout::log(x), y) - ; - } - template - inline SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, sprout::complex const& y) { - return x == T() ? T() - : sprout::exp(y * sprout::log(x)) - ; - } - template - inline SPROUT_CONSTEXPR sprout::complex pow(T const& x, sprout::complex const& y) { - return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * sprout::log(x)) - : sprout::pow(sprout::complex(x), y) - ; - } - template - inline SPROUT_CONSTEXPR sprout::complex sin(sprout::complex const& x) { - return sprout::complex( - sprout::sin(x.real()) * sprout::cosh(x.imag()), - sprout::cos(x.real()) * sprout::sinh(x.imag()) - ); - } - template - inline SPROUT_CONSTEXPR sprout::complex sinh(sprout::complex const& x) { - return sprout::complex( - sprout::sinh(x.real()) * sprout::cos(x.imag()), - sprout::cosh(x.real()) * sprout::sin(x.imag()) - ); - } - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::complex sqrt_impl_1(sprout::complex const& x, T const& t) { - return sprout::complex(t, x.imag() < T() ? -t : t); - } - template - inline SPROUT_CONSTEXPR sprout::complex sqrt_impl_2_1(sprout::complex const& x, T const& t, T const& u) { - return x.real() > T() ? sprout::complex(u, x.imag() / t) - : sprout::complex(sprout::abs(x.imag()) / t, x.imag() < T() ? -u : u) - ; - } - template - inline SPROUT_CONSTEXPR sprout::complex sqrt_impl_2(sprout::complex const& x, T const& t) { - return sprout::detail::sqrt_impl_2_1(x, t, t / 2); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::complex sqrt(sprout::complex const& x) { - return x.real() == T() ? sprout::detail::sqrt_impl_1(x, sprout::sqrt(abs(x.imag()) / 2)) - : sprout::detail::sqrt_impl_2(x, sprout::sqrt(2 * (sprout::abs(x) + sprout::abs(x.real())))) - ; - } - template - inline SPROUT_CONSTEXPR sprout::complex tan(sprout::complex const& x) { - return sprout::sin(x) / sprout::cos(x); - } - template - inline SPROUT_CONSTEXPR sprout::complex tanh(sprout::complex const& x) { - return sprout::sinh(x) / sprout::cosh(x); - } - - template - inline SPROUT_CONSTEXPR sprout::complex ceil(sprout::complex const& x) { - return sprout::complex(sprout::ceil(x.real()), sprout::ceil(x.imag())); - } - template - inline SPROUT_CONSTEXPR sprout::complex floor(sprout::complex const& x) { - return sprout::complex(sprout::floor(x.real()), sprout::floor(x.imag())); - } - template - inline SPROUT_CONSTEXPR sprout::complex trunc(sprout::complex const& x) { - return sprout::complex(sprout::trunc(x.real()), sprout::trunc(x.imag())); - } - template - inline SPROUT_CONSTEXPR sprout::complex round(sprout::complex const& x) { - return sprout::complex(sprout::round(x.real()), sprout::round(x.imag())); - } -} // namespace sprout +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_COMPLEX_HPP diff --git a/sprout/complex/complex.hpp b/sprout/complex/complex.hpp index d443b5f0..5065a32b 100644 --- a/sprout/complex/complex.hpp +++ b/sprout/complex/complex.hpp @@ -9,7 +9,8 @@ namespace sprout { namespace detail { template - inline SPROUT_CONSTEXPR T complex_norm(sprout::complex const& x) { + inline SPROUT_CONSTEXPR T + complex_norm(sprout::complex const& x) { return x.real() * x.real() + x.imag() * x.imag(); } } // namespace detail @@ -47,59 +48,59 @@ namespace sprout { void imag(T im) { im_ = im; } - complex& operator=(T const& rhs) { + complex& operator=(T const& rhs) { re_ = rhs; im_ = T(); return *this; } - complex& operator+=(T const& rhs) { + complex& operator+=(T const& rhs) { re_ += rhs; return *this; } - complex& operator-=(T const& rhs) { + complex& operator-=(T const& rhs) { re_ -= rhs; return *this; } - complex& operator*=(T const& rhs) { + complex& operator*=(T const& rhs) { re_ *= rhs; im_ *= rhs; return *this; } - complex& operator/=(T const& rhs) { + complex& operator/=(T const& rhs) { re_ /= rhs; im_ /= rhs; return *this; } complex& operator=(complex const&) = default; template - complex& operator=(complex const& rhs) { + complex& operator=(complex const& rhs) { re_ = rhs.real(); im_ = rhs.imag(); return *this; } template - complex& operator+=(complex const& rhs) { + complex& operator+=(complex const& rhs) { re_ += rhs.real(); im_ += rhs.imag(); return *this; } template - complex& operator-=(complex const& rhs) { + complex& operator-=(complex const& rhs) { re_ -= rhs.real(); im_ -= rhs.imag(); return *this; } template - complex& operator*=(complex const& rhs) { - return *this = complex( + complex& operator*=(complex const& rhs) { + return *this = complex( re_ * rhs.real() - im_ * rhs.imag(), re_ * rhs.imag() + im_ * rhs.real() ); } template - complex& operator/=(complex const& rhs) { + complex& operator/=(complex const& rhs) { T n = sprout::detail::complex_norm(rhs); - return *this = complex( + return *this = complex( (re_ * rhs.real() + im_ * rhs.imag()) / n, (im_ * rhs.real() - re_ * rhs.imag()) / n ); diff --git a/sprout/complex/hash.hpp b/sprout/complex/hash.hpp index d4ef00da..dd93a7a4 100644 --- a/sprout/complex/hash.hpp +++ b/sprout/complex/hash.hpp @@ -11,7 +11,8 @@ namespace sprout { // hash_value // template - inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::complex const& v) { + inline SPROUT_CONSTEXPR std::size_t + hash_value(sprout::complex const& v) { return sprout::hash_values(v.real(), v.imag()); } } // namespace sprout diff --git a/sprout/complex/nearest.hpp b/sprout/complex/nearest.hpp index ebfdfa9b..7f715113 100644 --- a/sprout/complex/nearest.hpp +++ b/sprout/complex/nearest.hpp @@ -10,19 +10,23 @@ namespace sprout { template - inline SPROUT_CONSTEXPR sprout::complex ceil(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + ceil(sprout::complex const& x) { return sprout::complex(sprout::ceil(x.real()), sprout::ceil(x.imag())); } template - inline SPROUT_CONSTEXPR sprout::complex floor(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + floor(sprout::complex const& x) { return sprout::complex(sprout::floor(x.real()), sprout::floor(x.imag())); } template - inline SPROUT_CONSTEXPR sprout::complex trunc(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + trunc(sprout::complex const& x) { return sprout::complex(sprout::trunc(x.real()), sprout::trunc(x.imag())); } template - inline SPROUT_CONSTEXPR sprout::complex round(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + round(sprout::complex const& x) { return sprout::complex(sprout::round(x.real()), sprout::round(x.imag())); } } // namespace sprout diff --git a/sprout/complex/operators.hpp b/sprout/complex/operators.hpp index 92776dba..5c7cfbe6 100644 --- a/sprout/complex/operators.hpp +++ b/sprout/complex/operators.hpp @@ -9,143 +9,126 @@ namespace sprout { // 26.4.6, operators: template - inline SPROUT_CONSTEXPR sprout::complex operator+(sprout::complex const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs.real() + rhs.real(), - lhs.imag() + rhs.imag() - ); + inline SPROUT_CONSTEXPR sprout::complex + operator+(sprout::complex const& lhs, sprout::complex const& rhs) { + return sprout::complex(lhs.real() + rhs.real(), lhs.imag() + rhs.imag()); } template - inline SPROUT_CONSTEXPR sprout::complex operator+(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() + rhs, - lhs.imag() - ); + inline SPROUT_CONSTEXPR sprout::complex + operator+(sprout::complex const& lhs, T const& rhs) { + return sprout::complex(lhs.real() + rhs, lhs.imag()); } template - inline SPROUT_CONSTEXPR sprout::complex operator+(T const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs + rhs.real(), - rhs.imag() - ); + inline SPROUT_CONSTEXPR sprout::complex + operator+(T const& lhs, sprout::complex const& rhs) { + return sprout::complex(lhs + rhs.real(), rhs.imag()); } template - inline SPROUT_CONSTEXPR sprout::complex operator-(sprout::complex const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs.real() - rhs.real(), - lhs.imag() - rhs.imag() - ); + inline SPROUT_CONSTEXPR sprout::complex + operator-(sprout::complex const& lhs, sprout::complex const& rhs) { + return sprout::complex(lhs.real() - rhs.real(), lhs.imag() - rhs.imag()); } template - inline SPROUT_CONSTEXPR sprout::complex operator-(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() - rhs, - lhs.imag() - ); + inline SPROUT_CONSTEXPR sprout::complex + operator-(sprout::complex const& lhs, T const& rhs) { + return sprout::complex(lhs.real() - rhs, lhs.imag()); } template - inline SPROUT_CONSTEXPR sprout::complex operator-(T const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs - rhs.real(), - -rhs.imag() - ); + inline SPROUT_CONSTEXPR sprout::complex + operator-(T const& lhs, sprout::complex const& rhs) { + return sprout::complex(lhs - rhs.real(), -rhs.imag()); } template - inline SPROUT_CONSTEXPR sprout::complex operator*(sprout::complex const& lhs, sprout::complex const& rhs) { + inline SPROUT_CONSTEXPR sprout::complex + operator*(sprout::complex const& lhs, sprout::complex const& rhs) { return sprout::complex( lhs.real() * rhs.real() - lhs.imag() * rhs.imag(), lhs.real() * rhs.imag() + lhs.imag() * rhs.real() ); } template - inline SPROUT_CONSTEXPR sprout::complex operator*(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() * rhs, - lhs.imag() * rhs - ); + inline SPROUT_CONSTEXPR sprout::complex + operator*(sprout::complex const& lhs, T const& rhs) { + return sprout::complex(lhs.real() * rhs, lhs.imag() * rhs); } template - inline SPROUT_CONSTEXPR sprout::complex operator*(T const& lhs, sprout::complex const& rhs) { - return sprout::complex( - lhs * rhs.real(), - lhs * rhs.imag() - ); + inline SPROUT_CONSTEXPR sprout::complex + operator*(T const& lhs, sprout::complex const& rhs) { + return sprout::complex(lhs * rhs.real(), lhs * rhs.imag()); } namespace detail { template - inline SPROUT_CONSTEXPR sprout::complex divides_impl( - sprout::complex const& lhs, - sprout::complex const& rhs, - T const& n - ) - { + inline SPROUT_CONSTEXPR sprout::complex + divides_impl(sprout::complex const& lhs, sprout::complex const& rhs, T const& n) { return sprout::complex( (lhs.real() * rhs.real() + lhs.imag() * rhs.imag()) / n, (lhs.imag() * rhs.real() - lhs.real() * rhs.imag()) / n ); } template - inline SPROUT_CONSTEXPR sprout::complex divides_impl( - T const& lhs, - sprout::complex const& rhs, - T const& n - ) - { - return sprout::complex( - lhs * rhs.real() / n, - -lhs * rhs.imag() / n - ); + inline SPROUT_CONSTEXPR sprout::complex + divides_impl(T const& lhs, sprout::complex const& rhs, T const& n) { + return sprout::complex(lhs * rhs.real() / n, -lhs * rhs.imag() / n); } } // namespace detail template - inline SPROUT_CONSTEXPR sprout::complex operator/(sprout::complex const& lhs, sprout::complex const& rhs) { + inline SPROUT_CONSTEXPR sprout::complex + operator/(sprout::complex const& lhs, sprout::complex const& rhs) { return sprout::detail::divides_impl(lhs, rhs, sprout::detail::complex_norm(rhs)); } template - inline SPROUT_CONSTEXPR sprout::complex operator/(sprout::complex const& lhs, T const& rhs) { - return sprout::complex( - lhs.real() / rhs, - lhs.imag() / rhs - ); + inline SPROUT_CONSTEXPR sprout::complex + operator/(sprout::complex const& lhs, T const& rhs) { + return sprout::complex(lhs.real() / rhs, lhs.imag() / rhs); } template - inline SPROUT_CONSTEXPR sprout::complex operator/(T const& lhs, sprout::complex const& rhs) { + inline SPROUT_CONSTEXPR sprout::complex + operator/(T const& lhs, sprout::complex const& rhs) { return sprout::detail::divides_impl(lhs, rhs, sprout::detail::complex_norm(rhs)); } template - inline SPROUT_CONSTEXPR sprout::complex operator+(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + operator+(sprout::complex const& x) { return x; } template - inline SPROUT_CONSTEXPR sprout::complex operator-(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + operator-(sprout::complex const& x) { return sprout::complex(-x.real(), -x.imag()); } template - inline SPROUT_CONSTEXPR bool operator==(sprout::complex const& lhs, sprout::complex const& rhs) { + inline SPROUT_CONSTEXPR bool + operator==(sprout::complex const& lhs, sprout::complex const& rhs) { return lhs.real() == rhs.real() && lhs.imag() == rhs.imag(); } template - inline SPROUT_CONSTEXPR bool operator==(sprout::complex const& lhs, T const& rhs) { + inline SPROUT_CONSTEXPR bool + operator==(sprout::complex const& lhs, T const& rhs) { return lhs.real() == rhs && lhs.imag() == T(); } template - inline SPROUT_CONSTEXPR bool operator==(T const& lhs, sprout::complex const& rhs) { + inline SPROUT_CONSTEXPR bool + operator==(T const& lhs, sprout::complex const& rhs) { return lhs == rhs.real() && T() == rhs.imag(); } template - inline SPROUT_CONSTEXPR bool operator!=(sprout::complex const& lhs, sprout::complex const& rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::complex const& lhs, sprout::complex const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator!=(sprout::complex const& lhs, T const& rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::complex const& lhs, T const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator!=(T const& lhs, sprout::complex const& rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(T const& lhs, sprout::complex const& rhs) { return !(lhs == rhs); } template - std::basic_istream& operator>>(std::basic_istream& lhs, sprout::complex& rhs) { + std::basic_istream& + operator>>(std::basic_istream& lhs, sprout::complex& rhs) { T re, im; Char ch; lhs >> ch; @@ -171,7 +154,8 @@ namespace sprout { return lhs; } template - std::basic_ostream& operator<<(std::basic_ostream& lhs, sprout::complex const& rhs) { + std::basic_ostream& + operator<<(std::basic_ostream& lhs, sprout::complex const& rhs) { return lhs << '(' << rhs.real() << ',' << rhs.imag() << ')'; } } // namespace sprout diff --git a/sprout/complex/transcendentals.hpp b/sprout/complex/transcendentals.hpp index 81f3e085..c18474e0 100644 --- a/sprout/complex/transcendentals.hpp +++ b/sprout/complex/transcendentals.hpp @@ -20,103 +20,130 @@ namespace sprout { // 26.4.8, transcendentals: template - SPROUT_CONSTEXPR sprout::complex acos(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + acos(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex asin(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + asin(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex atan(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + atan(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex acosh(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + acosh(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex asinh(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + asinh(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex atanh(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + atanh(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex cos(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + cos(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex cosh(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + cosh(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex exp(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + exp(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex log(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + log(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex log10(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + log10(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, T const& y); + SPROUT_CONSTEXPR sprout::complex + pow(sprout::complex const& x, T const& y); template - SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, sprout::complex const& y); + SPROUT_CONSTEXPR sprout::complex + pow(sprout::complex const& x, sprout::complex const& y); template - SPROUT_CONSTEXPR sprout::complex pow(T const& x, sprout::complex const& y); + SPROUT_CONSTEXPR sprout::complex + pow(T const& x, sprout::complex const& y); template - SPROUT_CONSTEXPR sprout::complex sin(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + sin(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex sinh(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + sinh(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex sqrt(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + sqrt(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex tan(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + tan(sprout::complex const& x); template - SPROUT_CONSTEXPR sprout::complex tanh(sprout::complex const& x); + SPROUT_CONSTEXPR sprout::complex + tanh(sprout::complex const& x); + + // + // acos + // asin + // atan + // namespace detail { template - inline SPROUT_CONSTEXPR sprout::complex acos_impl(sprout::complex const& t) { + inline SPROUT_CONSTEXPR sprout::complex + acos_impl(sprout::complex const& t) { return sprout::complex(sprout::math::half_pi() - t.real(), -t.imag()); } } // namespace detail template - inline SPROUT_CONSTEXPR sprout::complex acos(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + acos(sprout::complex const& x) { return sprout::detail::acos_impl(sprout::asin(x)); } namespace detail { template - inline SPROUT_CONSTEXPR sprout::complex asin_impl(sprout::complex const& t) { + inline SPROUT_CONSTEXPR sprout::complex + asin_impl(sprout::complex const& t) { return sprout::complex(t.imag(), -t.real()); } } // namespace detail template - inline SPROUT_CONSTEXPR sprout::complex asin(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + asin(sprout::complex const& x) { return sprout::detail::asin_impl(sprout::asinh(sprout::complex(-x.imag(), x.real()))); } namespace detail { template - inline SPROUT_CONSTEXPR sprout::complex atan_impl_1( - sprout::complex const& x, - T const& r2, - T const& z, - T const& num, - T const& den - ) - { + inline SPROUT_CONSTEXPR sprout::complex + atan_impl_1(sprout::complex const& x, T const& r2, T const& z, T const& num, T const& den) { return sprout::complex( T(0.5) * sprout::atan2(T(2) * x.real(), z), T(0.25) * sprout::log((r2 + num * num) / (r2 + den * den)) ); } template - inline SPROUT_CONSTEXPR sprout::complex atan_impl( - sprout::complex const& x, - T const& r2 - ) - { + inline SPROUT_CONSTEXPR sprout::complex + atan_impl(sprout::complex const& x, T const& r2) { return sprout::detail::atan_impl_1( - x, - r2, + x, r2, T(1) - r2 - x.imag() * x.imag(), - x.imag() + T(1), - x.imag() - T(1) + x.imag() + T(1), x.imag() - T(1) ); } } // namespace detail template - inline SPROUT_CONSTEXPR sprout::complex atan(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + atan(sprout::complex const& x) { return sprout::detail::atan_impl(x, x.real() * x.real()); } - template - inline SPROUT_CONSTEXPR sprout::complex acosh(sprout::complex const& x) { + + // + // acosh + // asinh + // atanh + // + template + inline SPROUT_CONSTEXPR sprout::complex + acosh(sprout::complex const& x) { return T(2) * sprout::log(sprout::sqrt(T(0.5) * (x + T(1))) + sprout::sqrt(T(0.5) * (x - T(1)))); } template - inline SPROUT_CONSTEXPR sprout::complex asinh(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + asinh(sprout::complex const& x) { return sprout::log( sprout::sqrt( sprout::complex( @@ -129,58 +156,63 @@ namespace sprout { } namespace detail { template - inline SPROUT_CONSTEXPR sprout::complex atanh_impl_1( - sprout::complex const& x, - T const& i2, - T const& z, - T const& num, - T const& den - ) - { + inline SPROUT_CONSTEXPR sprout::complex + atanh_impl_1(sprout::complex const& x, T const& i2, T const& z, T const& num, T const& den) { return sprout::complex( T(0.25) * (sprout::log(i2 + num * num) - sprout::log(i2 + den * den)), T(0.5) * sprout::atan2(T(2) * x.imag(), z) ); } template - inline SPROUT_CONSTEXPR sprout::complex atanh_impl( - sprout::complex const& x, - T const& i2 - ) - { + inline SPROUT_CONSTEXPR sprout::complex + atanh_impl(sprout::complex const& x, T const& i2) { return sprout::detail::atanh_impl_1( - x, - i2, + x, i2, T(1) - i2 - x.real() * x.real(), - T(1) + x.imag(), - T(1) - x.imag() + T(1) + x.imag(), T(1) - x.imag() ); } } // namespace detail template - inline SPROUT_CONSTEXPR sprout::complex atanh(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + atanh(sprout::complex const& x) { return sprout::detail::atanh_impl(x, x.imag() * x.imag()); } + + // + // cos + // cosh + // template - inline SPROUT_CONSTEXPR sprout::complex cos(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + cos(sprout::complex const& x) { return sprout::complex( sprout::cos(x.real()) * sprout::cosh(x.imag()), -(sprout::sin(x.real()) * sprout::sinh(x.imag())) ); } template - inline SPROUT_CONSTEXPR sprout::complex cosh(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + cosh(sprout::complex const& x) { return sprout::complex( sprout::cosh(x.real()) * sprout::cos(x.imag()), sprout::sinh(x.real()) * sprout::sin(x.imag()) ); } - template - inline SPROUT_CONSTEXPR sprout::complex exp(sprout::complex const& x) { + + // + // exp + // log + // log10 + // + template + inline SPROUT_CONSTEXPR sprout::complex + exp(sprout::complex const& x) { return sprout::polar(sprout::exp(x.real()), x.imag()); } template - inline SPROUT_CONSTEXPR sprout::complex log(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + log(sprout::complex const& x) { return sprout::complex(sprout::log(sprout::abs(x)), sprout::arg(x)); } template @@ -193,67 +225,96 @@ namespace sprout { return sprout::polar(sprout::exp(y * t.real()), y * t.imag()); } } // namespace detail + + // + // pow + // template - inline SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, T const& y) { + inline SPROUT_CONSTEXPR sprout::complex + pow(sprout::complex const& x, T const& y) { return x == T() ? T() : x.imag() == T() && x.real() > T() ? sprout::pow(x.real(), y) : sprout::detail::pow_impl(sprout::log(x), y) ; } template - inline SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, sprout::complex const& y) { + inline SPROUT_CONSTEXPR sprout::complex + pow(sprout::complex const& x, sprout::complex const& y) { return x == T() ? T() : sprout::exp(y * sprout::log(x)) ; } template - inline SPROUT_CONSTEXPR sprout::complex pow(T const& x, sprout::complex const& y) { + inline SPROUT_CONSTEXPR sprout::complex + pow(T const& x, sprout::complex const& y) { return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * sprout::log(x)) : sprout::pow(sprout::complex(x), y) ; } + + // + // sin + // sinh + // template - inline SPROUT_CONSTEXPR sprout::complex sin(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + sin(sprout::complex const& x) { return sprout::complex( sprout::sin(x.real()) * sprout::cosh(x.imag()), sprout::cos(x.real()) * sprout::sinh(x.imag()) ); } template - inline SPROUT_CONSTEXPR sprout::complex sinh(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + sinh(sprout::complex const& x) { return sprout::complex( sprout::sinh(x.real()) * sprout::cos(x.imag()), sprout::cosh(x.real()) * sprout::sin(x.imag()) ); } + + // + // sqrt + // namespace detail { template - inline SPROUT_CONSTEXPR sprout::complex sqrt_impl_1(sprout::complex const& x, T const& t) { + inline SPROUT_CONSTEXPR sprout::complex + sqrt_impl_1(sprout::complex const& x, T const& t) { return sprout::complex(t, x.imag() < T() ? -t : t); } template - inline SPROUT_CONSTEXPR sprout::complex sqrt_impl_2_1(sprout::complex const& x, T const& t, T const& u) { + inline SPROUT_CONSTEXPR sprout::complex + sqrt_impl_2_1(sprout::complex const& x, T const& t, T const& u) { return x.real() > T() ? sprout::complex(u, x.imag() / t) : sprout::complex(sprout::abs(x.imag()) / t, x.imag() < T() ? -u : u) ; } template - inline SPROUT_CONSTEXPR sprout::complex sqrt_impl_2(sprout::complex const& x, T const& t) { + inline SPROUT_CONSTEXPR sprout::complex + sqrt_impl_2(sprout::complex const& x, T const& t) { return sprout::detail::sqrt_impl_2_1(x, t, t / 2); } } // namespace detail + + // + // tan + // tanh + // template - inline SPROUT_CONSTEXPR sprout::complex sqrt(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + sqrt(sprout::complex const& x) { return x.real() == T() ? sprout::detail::sqrt_impl_1(x, sprout::sqrt(abs(x.imag()) / 2)) : sprout::detail::sqrt_impl_2(x, sprout::sqrt(2 * (sprout::abs(x) + sprout::abs(x.real())))) ; } template - inline SPROUT_CONSTEXPR sprout::complex tan(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + tan(sprout::complex const& x) { return sprout::sin(x) / sprout::cos(x); } template - inline SPROUT_CONSTEXPR sprout::complex tanh(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + tanh(sprout::complex const& x) { return sprout::sinh(x) / sprout::cosh(x); } } // namespace sprout diff --git a/sprout/complex/values.hpp b/sprout/complex/values.hpp index ed715886..a29afc21 100644 --- a/sprout/complex/values.hpp +++ b/sprout/complex/values.hpp @@ -11,36 +11,44 @@ namespace sprout { template - SPROUT_CONSTEXPR T norm(sprout::complex const& x); + SPROUT_CONSTEXPR T + norm(sprout::complex const& x); // 26.4.7, values: template - inline SPROUT_CONSTEXPR T real(sprout::complex const& x) { + inline SPROUT_CONSTEXPR T + real(sprout::complex const& x) { return x.real(); } template - inline SPROUT_CONSTEXPR T imag(sprout::complex const& x) { + inline SPROUT_CONSTEXPR T + imag(sprout::complex const& x) { return x.imag(); } template - inline SPROUT_CONSTEXPR T abs(sprout::complex const& x) { + inline SPROUT_CONSTEXPR T + abs(sprout::complex const& x) { return sprout::sqrt(sprout::norm(x)); } template - inline SPROUT_CONSTEXPR T arg(sprout::complex const& x) { + inline SPROUT_CONSTEXPR T + arg(sprout::complex const& x) { return sprout::atan2(x.imag(), x.real()); } template - inline SPROUT_CONSTEXPR T norm(sprout::complex const& x) { + inline SPROUT_CONSTEXPR T + norm(sprout::complex const& x) { return x.real() * x.real() + x.imag() * x.imag(); } template - inline SPROUT_CONSTEXPR sprout::complex conj(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + conj(sprout::complex const& x) { return sprout::complex(x.real(), -x.imag()); } namespace detail { template - inline SPROUT_CONSTEXPR sprout::complex proj_impl(sprout::complex const& x, T const& den) { + inline SPROUT_CONSTEXPR sprout::complex + proj_impl(sprout::complex const& x, T const& den) { return sprout::complex( T(2) * x.real() / den, T(2) * x.imag() / den @@ -48,14 +56,16 @@ namespace sprout { } } // detail template - inline SPROUT_CONSTEXPR sprout::complex proj(sprout::complex const& x) { + inline SPROUT_CONSTEXPR sprout::complex + proj(sprout::complex const& x) { return sprout::detail::proj_impl( x, sprout::norm(x) + T(1) ); } template - inline SPROUT_CONSTEXPR sprout::complex polar(T const& rho, T const& theta = 0) { + inline SPROUT_CONSTEXPR sprout::complex + polar(T const& rho, T const& theta = 0) { return sprout::complex(rho * sprout::cos(theta), rho * sprout::sin(theta)); } } // namespace sprout diff --git a/sprout/compressed_pair.hpp b/sprout/compressed_pair.hpp index 90be8bc5..05b2ec88 100644 --- a/sprout/compressed_pair.hpp +++ b/sprout/compressed_pair.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace sprout { @@ -37,8 +38,7 @@ namespace sprout { template class compressed_pair_impl; template - class compressed_pair_impl - { + class compressed_pair_impl { public: typedef T1 first_type; typedef T2 second_type; @@ -75,10 +75,14 @@ namespace sprout { SPROUT_CONSTEXPR second_const_reference second() const { return second_; } - void swap(compressed_pair_impl& other) { - using std::swap; - swap(first_, other.first_); - swap(second_, other.second_); + void swap(compressed_pair_impl& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(second_, other.second_)) + ) + { + sprout::swap(first_, other.first_); + sprout::swap(second_, other.second_); } }; template @@ -120,9 +124,10 @@ namespace sprout { SPROUT_CONSTEXPR second_const_reference second() const { return second_; } - void swap(compressed_pair_impl& other) { - using std::swap; - swap(second_, other.second_); + void swap(compressed_pair_impl& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(second_, other.second_))) + { + sprout::swap(second_, other.second_); } }; template @@ -164,9 +169,10 @@ namespace sprout { SPROUT_CONSTEXPR second_const_reference second() const { return *this; } - void swap(compressed_pair_impl& other) { - using std::swap; - swap(first_, other.first_); + void swap(compressed_pair_impl& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_))) + { + sprout::swap(first_, other.first_); } }; template @@ -285,10 +291,14 @@ namespace sprout { SPROUT_CONSTEXPR second_const_reference second() const { return second_; } - void swap(compressed_pair_impl& other) { - using std::swap; - swap(first_, other.first_); - swap(second_, other.second_); + void swap(compressed_pair_impl& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(second_, other.second_)) + ) + { + sprout::swap(first_, other.first_); + sprout::swap(second_, other.second_); } }; } // namespace detail @@ -299,27 +309,21 @@ namespace sprout { template class compressed_pair : private sprout::detail::compressed_pair_impl< - T1, - T2, + T1, T2, sprout::detail::compressed_pair_switch< - T1, - T2, + T1, T2, std::is_same::type, typename std::remove_cv::type>::value, - std::is_empty::value, - std::is_empty::value + std::is_empty::value, std::is_empty::value >::value > { private: typedef sprout::detail::compressed_pair_impl< - T1, - T2, + T1, T2, sprout::detail::compressed_pair_switch< - T1, - T2, + T1, T2, std::is_same::type, typename std::remove_cv::type>::value, - std::is_empty::value, - std::is_empty::value + std::is_empty::value, std::is_empty::value >::value > base_type; public: @@ -363,27 +367,21 @@ namespace sprout { template class compressed_pair : private sprout::detail::compressed_pair_impl< - T, - T, + T, T, sprout::detail::compressed_pair_switch< - T, - T, + T, T, std::is_same::type, typename std::remove_cv::type>::value, - std::is_empty::value, - std::is_empty::value + std::is_empty::value, std::is_empty::value >::value > { private: typedef sprout::detail::compressed_pair_impl< - T, - T, + T, T, sprout::detail::compressed_pair_switch< - T, - T, + T, T, std::is_same::type, typename std::remove_cv::type>::value, - std::is_empty::value, - std::is_empty::value + std::is_empty::value, std::is_empty::value >::value > base_type; public: @@ -421,8 +419,14 @@ namespace sprout { base_type::swap(other); } }; + // + // swap + // template - inline void swap(sprout::compressed_pair& lhs, sprout::compressed_pair& rhs) { + inline void + swap(sprout::compressed_pair& lhs, sprout::compressed_pair& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } } // namespace sprout diff --git a/sprout/container/container_construct_traits.hpp b/sprout/container/container_construct_traits.hpp index 3d7bda57..6e5b3a33 100644 --- a/sprout/container/container_construct_traits.hpp +++ b/sprout/container/container_construct_traits.hpp @@ -27,20 +27,18 @@ namespace sprout { typedef Container copied_type; public: template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { + static SPROUT_CONSTEXPR copied_type + deep_copy(Cont&& cont) { return sprout::forward(cont); } template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + static SPROUT_CONSTEXPR copied_type + make(Args&&... args) { return sprout::detail::default_make_container(sprout::forward(args)...); } template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits::difference_type size, - Args&&... args - ) - { + static SPROUT_CONSTEXPR copied_type + remake(Cont&& cont, typename sprout::container_traits::difference_type size, Args&&... args) { return make(sprout::forward(args)...); } }; diff --git a/sprout/container/container_traits.hpp b/sprout/container/container_traits.hpp index c682b94c..c01ee016 100644 --- a/sprout/container/container_traits.hpp +++ b/sprout/container/container_traits.hpp @@ -8,57 +8,13 @@ #include #include #include +#include namespace sprout { template struct container_traits; namespace detail { - // - // is_array_like - // - template - struct is_array_like - : public std::false_type - {}; - template class Array, typename T, std::size_t N> - struct is_array_like > - : public std::true_type - {}; - template - struct is_array_like - : public sprout::detail::is_array_like - {}; - template - struct is_array_like - : public sprout::detail::is_array_like - {}; - template - struct is_array_like - : public sprout::detail::is_array_like - {}; - // - // array_like_static_size - // - template - struct array_like_static_size {}; - template class Array, typename T, std::size_t N> - struct array_like_static_size > - : public std::integral_constant - {}; - template - struct array_like_static_size - : public sprout::detail::array_like_static_size - {}; - template - struct array_like_static_size - : public sprout::detail::array_like_static_size - {}; - template - struct array_like_static_size - : public sprout::detail::array_like_static_size - {}; - // // has_value_type // has_iterator @@ -438,7 +394,8 @@ namespace sprout { template struct container_nosy_fixed_size_impl { public: - static SPROUT_CONSTEXPR decltype(sprout::detail::container_nosy_static_size::static_size) fixed_size() { + static SPROUT_CONSTEXPR decltype(sprout::detail::container_nosy_static_size::static_size) + fixed_size() { return sprout::detail::container_nosy_static_size::static_size; } }; @@ -447,7 +404,7 @@ namespace sprout { : public sprout::detail::container_nosy_fixed_size_impl< Container, sprout::detail::has_container_nosy_static_size::value - > + > {}; // @@ -482,7 +439,8 @@ namespace sprout { public: SPROUT_STATIC_CONSTEXPR size_type static_size = N ; public: - static SPROUT_CONSTEXPR size_type fixed_size() { + static SPROUT_CONSTEXPR size_type + fixed_size() { return static_size; } }; diff --git a/sprout/container/container_transform_traits.hpp b/sprout/container/container_transform_traits.hpp index 326976dd..0b0b44d8 100644 --- a/sprout/container/container_transform_traits.hpp +++ b/sprout/container/container_transform_traits.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace sprout { // @@ -14,31 +15,6 @@ namespace sprout { struct container_transform_traits; namespace detail { - template - struct is_like_array_class - : public std::false_type - {}; - template< - template class Array, - typename T, - std::size_t N - > - struct is_like_array_class > - : public std::true_type - {}; - template - struct is_like_array_class - : public sprout::detail::is_like_array_class - {}; - template - struct is_like_array_class - : public sprout::detail::is_like_array_class - {}; - template - struct is_like_array_class - : public sprout::detail::is_like_array_class - {}; - template::size_type Size> struct default_array_rebind_size; template< @@ -57,7 +33,7 @@ namespace sprout { template struct inherit_default_rebind_size< Container, - typename std::enable_if::value>::type + typename std::enable_if::value>::type > { public: template::size_type Size> diff --git a/sprout/container/deep_copy.hpp b/sprout/container/deep_copy.hpp index 84280824..e7eb402f 100644 --- a/sprout/container/deep_copy.hpp +++ b/sprout/container/deep_copy.hpp @@ -13,7 +13,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR typename sprout::container_construct_traits< typename std::remove_reference::type - >::copied_type deep_copy(Container&& cont) { + >::copied_type + deep_copy(Container&& cont) { typedef typename std::remove_reference::type container_type; return sprout::container_construct_traits::deep_copy(sprout::forward(cont)); } diff --git a/sprout/container/detail/array_like.hpp b/sprout/container/detail/array_like.hpp new file mode 100644 index 00000000..14ebbc63 --- /dev/null +++ b/sprout/container/detail/array_like.hpp @@ -0,0 +1,52 @@ +#ifndef SPROUT_CONTAINER_DETAIL_ARRAY_LIKE_HPP +#define SPROUT_CONTAINER_DETAIL_ARRAY_LIKE_HPP + +#include +#include +#include + +namespace sprout { + namespace detail { + template + struct is_array_like + : public std::false_type + {}; + template class Array, typename T, std::size_t N> + struct is_array_like > + : public std::true_type + {}; + template + struct is_array_like + : public sprout::detail::is_array_like + {}; + template + struct is_array_like + : public sprout::detail::is_array_like + {}; + template + struct is_array_like + : public sprout::detail::is_array_like + {}; + + template + struct array_like_static_size {}; + template class Array, typename T, std::size_t N> + struct array_like_static_size > + : public std::integral_constant + {}; + template + struct array_like_static_size + : public sprout::detail::array_like_static_size + {}; + template + struct array_like_static_size + : public sprout::detail::array_like_static_size + {}; + template + struct array_like_static_size + : public sprout::detail::array_like_static_size + {}; + } // namespace detail +} // namespace sprout + +#endif // #ifndef SPROUT_CONTAINER_DETAIL_ARRAY_LIKE_HPP diff --git a/sprout/container/fixed_size.hpp b/sprout/container/fixed_size.hpp index 20c88682..3f0542f6 100644 --- a/sprout/container/fixed_size.hpp +++ b/sprout/container/fixed_size.hpp @@ -9,7 +9,8 @@ namespace sprout { // fixed_size // template - inline SPROUT_CONSTEXPR typename sprout::container_traits::size_type fixed_size() { + inline SPROUT_CONSTEXPR typename sprout::container_traits::size_type + fixed_size() { return sprout::container_traits::fixed_size(); } } // namespace sprout diff --git a/sprout/container/get_internal.hpp b/sprout/container/get_internal.hpp index f168d010..5b3838e8 100644 --- a/sprout/container/get_internal.hpp +++ b/sprout/container/get_internal.hpp @@ -12,7 +12,8 @@ namespace sprout { // get_internal // template - inline SPROUT_CONSTEXPR typename sprout::containers::internal::type get_internal(Container&& cont) { + inline SPROUT_CONSTEXPR typename sprout::containers::internal::type + get_internal(Container&& cont) { typedef typename std::remove_reference::type container_type; return sprout::sub_container_traits::get_internal(sprout::forward(cont)); } diff --git a/sprout/container/internal_begin.hpp b/sprout/container/internal_begin.hpp index a2c3673d..0d529c85 100644 --- a/sprout/container/internal_begin.hpp +++ b/sprout/container/internal_begin.hpp @@ -18,7 +18,8 @@ namespace sprout { typename std::remove_reference< typename sprout::containers::internal::type >::type - >::iterator internal_begin(Container& cont) { + >::iterator + internal_begin(Container& cont) { return sprout::begin(sprout::get_internal(cont)); } template @@ -26,7 +27,8 @@ namespace sprout { typename std::remove_reference< typename sprout::containers::internal::type >::type - >::const_iterator internal_begin(Container const& cont) { + >::const_iterator + internal_begin(Container const& cont) { return sprout::begin(sprout::get_internal(cont)); } @@ -38,7 +40,8 @@ namespace sprout { typename std::remove_reference< typename sprout::containers::internal::type >::type - >::const_iterator internal_cbegin(Container const& cont) { + >::const_iterator + internal_cbegin(Container const& cont) { return sprout::begin(sprout::get_internal(cont)); } } // namespace sprout diff --git a/sprout/container/internal_deep_copy.hpp b/sprout/container/internal_deep_copy.hpp index 5e3abf3d..511633b3 100644 --- a/sprout/container/internal_deep_copy.hpp +++ b/sprout/container/internal_deep_copy.hpp @@ -19,7 +19,8 @@ namespace sprout { typename std::remove_reference< typename sprout::containers::internal::type >::type - >::copied_type internal_deep_copy(Container&& cont) { + >::copied_type + internal_deep_copy(Container&& cont) { return sprout::deep_copy( sprout::get_internal(sprout::forward(cont)) ); diff --git a/sprout/container/internal_end.hpp b/sprout/container/internal_end.hpp index f77b5195..7050e4f5 100644 --- a/sprout/container/internal_end.hpp +++ b/sprout/container/internal_end.hpp @@ -18,7 +18,8 @@ namespace sprout { typename std::remove_reference< typename sprout::containers::internal::type >::type - >::iterator internal_end(Container& cont) { + >::iterator + internal_end(Container& cont) { return sprout::end(sprout::get_internal(cont)); } template @@ -26,7 +27,8 @@ namespace sprout { typename std::remove_reference< typename sprout::containers::internal::type >::type - >::const_iterator internal_end(Container const& cont) { + >::const_iterator + internal_end(Container const& cont) { return sprout::end(sprout::get_internal(cont)); } @@ -38,7 +40,8 @@ namespace sprout { typename std::remove_reference< typename sprout::containers::internal::type >::type - >::const_iterator internal_cend(Container const& cont) { + >::const_iterator + internal_cend(Container const& cont) { return sprout::end(sprout::get_internal(cont)); } } // namespace sprout diff --git a/sprout/container/make.hpp b/sprout/container/make.hpp index 2f2d678c..50365959 100644 --- a/sprout/container/make.hpp +++ b/sprout/container/make.hpp @@ -10,7 +10,8 @@ namespace sprout { // make // template - inline SPROUT_CONSTEXPR typename sprout::container_construct_traits::copied_type make(Args&&... args) { + inline SPROUT_CONSTEXPR typename sprout::container_construct_traits::copied_type + make(Args&&... args) { return sprout::container_construct_traits::make(sprout::forward(args)...); } } // namespace sprout diff --git a/sprout/container/remake.hpp b/sprout/container/remake.hpp index e00350ef..60f5d5fe 100644 --- a/sprout/container/remake.hpp +++ b/sprout/container/remake.hpp @@ -12,12 +12,8 @@ namespace sprout { // remake // template - inline SPROUT_CONSTEXPR typename sprout::container_construct_traits::copied_type remake( - Cont&& cont, - typename sprout::container_traits::difference_type size, - Args&&... args - ) - { + inline SPROUT_CONSTEXPR typename sprout::container_construct_traits::copied_type + remake(Cont&& cont, typename sprout::container_traits::difference_type size, Args&&... args) { return sprout::container_construct_traits::remake( sprout::forward(cont), size, diff --git a/sprout/container/static_size.hpp b/sprout/container/static_size.hpp index 4dfeef31..1cc714ae 100644 --- a/sprout/container/static_size.hpp +++ b/sprout/container/static_size.hpp @@ -15,7 +15,7 @@ namespace sprout { : public std::integral_constant< typename sprout::container_traits::size_type, sprout::container_traits::static_size - > + > {}; } // namespace containers } // namespace sprout diff --git a/sprout/cstdlib/abs.hpp b/sprout/cstdlib/abs.hpp index 879fcfd3..46f5323f 100644 --- a/sprout/cstdlib/abs.hpp +++ b/sprout/cstdlib/abs.hpp @@ -9,23 +9,28 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.20.6.1 absClabsC‹y‚Ñ llabs ŠÖ” - inline SPROUT_CONSTEXPR int abs(int j) { + inline SPROUT_CONSTEXPR int + abs(int j) { return j < 0 ? -j : j; } - inline SPROUT_CONSTEXPR long labs(long j) { + inline SPROUT_CONSTEXPR long + labs(long j) { return j < 0 ? -j : j; } - inline SPROUT_CONSTEXPR long long llabs(long long j) { + inline SPROUT_CONSTEXPR long long + llabs(long long j) { return j < 0 ? -j : j; } - inline SPROUT_CONSTEXPR long abs(long j) { + inline SPROUT_CONSTEXPR long + abs(long j) { return sprout::labs(j); } - inline SPROUT_CONSTEXPR long long abs(long long j) { + inline SPROUT_CONSTEXPR long long + abs(long long j) { return sprout::llabs(j); } @@ -36,7 +41,8 @@ namespace sprout { std::is_integral::value && std::is_signed::value >::type = sprout::enabler > - inline SPROUT_CONSTEXPR IntType abs(IntType j) { + inline SPROUT_CONSTEXPR IntType + abs(IntType j) { return j < 0 ? -j : j; } template< @@ -45,7 +51,8 @@ namespace sprout { std::is_integral::value && std::is_unsigned::value >::type = sprout::enabler > - inline SPROUT_CONSTEXPR IntType abs(IntType j) { + inline SPROUT_CONSTEXPR IntType + abs(IntType j) { return j; } } // anonymous-namespace diff --git a/sprout/cstdlib/ascii_to_int.hpp b/sprout/cstdlib/ascii_to_int.hpp index 4f69e7a5..2507265a 100644 --- a/sprout/cstdlib/ascii_to_int.hpp +++ b/sprout/cstdlib/ascii_to_int.hpp @@ -14,7 +14,8 @@ namespace sprout { // Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/ template - inline SPROUT_CONSTEXPR IntType ascii_to_int_impl(CStrIterator str, IntType val, bool negative) { + inline SPROUT_CONSTEXPR IntType + ascii_to_int_impl(CStrIterator str, IntType val, bool negative) { return !sprout::ascii::isdigit(*str) ? negative ? -val : val : val > (std::numeric_limits::max() - (*str - static_cast::value_type>('0')) - (negative ? 1 : 0)) / 10 @@ -27,7 +28,8 @@ namespace sprout { ; } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) { + inline SPROUT_CONSTEXPR IntType + ascii_to_int(CStrIterator str) { return sprout::ascii::isspace(*str) ? sprout::detail::ascii_to_int(sprout::next(str)) : *str == static_cast::value_type>('+') @@ -36,7 +38,8 @@ namespace sprout { ; } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) { + inline SPROUT_CONSTEXPR IntType + ascii_to_int(CStrIterator str) { return sprout::ascii::isspace(*str) ? sprout::detail::ascii_to_int(sprout::next(str)) : *str == static_cast::value_type>('-') @@ -52,7 +55,8 @@ namespace sprout { // ascii_to_int // template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType ascii_to_int(Char const* str) { + inline SPROUT_CONSTEXPR IntType + ascii_to_int(Char const* str) { return sprout::detail::ascii_to_int(str); } } // namespace sprout diff --git a/sprout/cstdlib/atof.hpp b/sprout/cstdlib/atof.hpp index a2e7b9fa..c5e52df3 100644 --- a/sprout/cstdlib/atof.hpp +++ b/sprout/cstdlib/atof.hpp @@ -9,7 +9,8 @@ namespace sprout { // atof // template - inline SPROUT_CONSTEXPR double atof(Char const* str){ + inline SPROUT_CONSTEXPR double + atof(Char const* str) { return sprout::str_to_float(str); } } // namespace sprout diff --git a/sprout/cstdlib/atoi.hpp b/sprout/cstdlib/atoi.hpp index f0906d11..ff31b039 100644 --- a/sprout/cstdlib/atoi.hpp +++ b/sprout/cstdlib/atoi.hpp @@ -8,11 +8,13 @@ namespace sprout { // // atoi // - inline SPROUT_CONSTEXPR int atoi(char const* str) { + inline SPROUT_CONSTEXPR int + atoi(char const* str) { return sprout::ascii_to_int(str); } template - inline SPROUT_CONSTEXPR int atoi(Char const* str) { + inline SPROUT_CONSTEXPR int + atoi(Char const* str) { return sprout::ascii_to_int(str); } } // namespace sprout diff --git a/sprout/cstdlib/atol.hpp b/sprout/cstdlib/atol.hpp index 8210ed0c..0ea30ea0 100644 --- a/sprout/cstdlib/atol.hpp +++ b/sprout/cstdlib/atol.hpp @@ -8,11 +8,13 @@ namespace sprout { // // atol // - inline SPROUT_CONSTEXPR long atol(char const* str) { + inline SPROUT_CONSTEXPR long + atol(char const* str) { return sprout::ascii_to_int(str); } template - inline SPROUT_CONSTEXPR long atol(Char const* str) { + inline SPROUT_CONSTEXPR long + atol(Char const* str) { return sprout::ascii_to_int(str); } } // namespace sprout diff --git a/sprout/cstdlib/atoll.hpp b/sprout/cstdlib/atoll.hpp index a54dcdbc..73bd3d1b 100644 --- a/sprout/cstdlib/atoll.hpp +++ b/sprout/cstdlib/atoll.hpp @@ -8,11 +8,13 @@ namespace sprout { // // atoll // - inline SPROUT_CONSTEXPR long long atoll(char const* str) { + inline SPROUT_CONSTEXPR long long + atoll(char const* str) { return sprout::ascii_to_int(str); } template - inline SPROUT_CONSTEXPR long long atoll(Char const* str) { + inline SPROUT_CONSTEXPR long long + atoll(Char const* str) { return sprout::ascii_to_int(str); } } // namespace sprout diff --git a/sprout/cstdlib/div.hpp b/sprout/cstdlib/div.hpp index 1e209b86..b41851d5 100644 --- a/sprout/cstdlib/div.hpp +++ b/sprout/cstdlib/div.hpp @@ -34,7 +34,8 @@ namespace sprout { sprout::detail::div_t_traits::offsetof_quot == 0 >::type = sprout::enabler > - inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits::type div_impl(T const& numer, T const& denom) { + inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits::type + div_impl(T const& numer, T const& denom) { return {numer / denom, numer % denom}; } @@ -44,29 +45,35 @@ namespace sprout { sprout::detail::div_t_traits::offsetof_rem == 0 >::type = sprout::enabler > - inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits::type div_impl(T const &numer, T const& denom) { + inline SPROUT_CONSTEXPR typename sprout::detail::div_t_traits::type + div_impl(T const &numer, T const& denom) { return {numer % denom, numer / denom}; } } // namespace detail // 7.20.6.2 divCldivC‹y‚Ñ lldiv ŠÖ” - inline SPROUT_CONSTEXPR std::div_t div(int numer, int denom) { + inline SPROUT_CONSTEXPR std::div_t + div(int numer, int denom) { return sprout::detail::div_impl(numer, denom); } - inline SPROUT_CONSTEXPR std::ldiv_t ldiv(long numer, long denom) { + inline SPROUT_CONSTEXPR std::ldiv_t + ldiv(long numer, long denom) { return sprout::detail::div_impl(numer, denom); } - inline SPROUT_CONSTEXPR std::lldiv_t lldiv(long long numer, long long denom) { + inline SPROUT_CONSTEXPR std::lldiv_t + lldiv(long long numer, long long denom) { return sprout::detail::div_impl(numer, denom); } - inline SPROUT_CONSTEXPR std::ldiv_t div(long numer, long denom) { + inline SPROUT_CONSTEXPR std::ldiv_t + div(long numer, long denom) { return sprout::ldiv(numer, denom); } - inline SPROUT_CONSTEXPR std::lldiv_t div(long long numer, long long denom) { + inline SPROUT_CONSTEXPR std::lldiv_t + div(long long numer, long long denom) { return sprout::lldiv(numer, denom); } } // namespace sprout diff --git a/sprout/cstdlib/str_to_float.hpp b/sprout/cstdlib/str_to_float.hpp index 29c91e7c..901179b0 100644 --- a/sprout/cstdlib/str_to_float.hpp +++ b/sprout/cstdlib/str_to_float.hpp @@ -13,7 +13,8 @@ namespace sprout { namespace detail { template - inline SPROUT_CONSTEXPR FloatType str_to_float_impl_scale( + inline SPROUT_CONSTEXPR FloatType + str_to_float_impl_scale( CStrIterator str, bool negative, FloatType number = FloatType(), @@ -38,7 +39,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR FloatType str_to_float_impl_exponent_2( + inline SPROUT_CONSTEXPR FloatType + str_to_float_impl_exponent_2( CStrIterator str, bool negative, FloatType number = FloatType(), @@ -63,7 +65,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR FloatType str_to_float_impl_exponent_1( + inline SPROUT_CONSTEXPR FloatType + str_to_float_impl_exponent_1( CStrIterator str, bool negative, FloatType number = FloatType(), @@ -95,7 +98,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR FloatType str_to_float_impl_exponent( + inline SPROUT_CONSTEXPR FloatType + str_to_float_impl_exponent( CStrIterator str, bool negative, FloatType number = FloatType(), @@ -134,7 +138,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR FloatType str_to_float_impl_decimal_1( + inline SPROUT_CONSTEXPR FloatType + str_to_float_impl_decimal_1( CStrIterator str, bool negative, FloatType number = FloatType(), @@ -155,7 +160,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR FloatType str_to_float_impl_decimal( + inline SPROUT_CONSTEXPR FloatType + str_to_float_impl_decimal( CStrIterator str, bool negative, FloatType number = FloatType(), @@ -185,7 +191,8 @@ namespace sprout { } template - inline SPROUT_CONSTEXPR FloatType str_to_float_impl( + inline SPROUT_CONSTEXPR FloatType + str_to_float_impl( CStrIterator str, bool negative, FloatType number = FloatType(), @@ -214,7 +221,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR FloatType str_to_float(CStrIterator str) { + inline SPROUT_CONSTEXPR FloatType + str_to_float(CStrIterator str) { return sprout::ascii::isspace(*str) ? sprout::detail::str_to_float(sprout::next(str)) : *str == static_cast::value_type>('-') @@ -225,7 +233,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR FloatType str_to_float(CStrIterator str, CharPtr* endptr) { + inline SPROUT_CONSTEXPR FloatType + str_to_float(CStrIterator str, CharPtr* endptr) { return !endptr ? sprout::detail::str_to_float(str) : std::is_same::type, float>::value ? std::strtof(&*str, endptr) : std::is_same::type, double>::value ? std::strtod(&*str, endptr) @@ -238,15 +247,18 @@ namespace sprout { // str_to_float // template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR FloatType str_to_float(Char const* str, Char** endptr) { + inline SPROUT_CONSTEXPR FloatType + str_to_float(Char const* str, Char** endptr) { return sprout::detail::str_to_float(str, endptr); } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR FloatType str_to_float(Char const* str, std::nullptr_t endptr) { + inline SPROUT_CONSTEXPR FloatType + str_to_float(Char const* str, std::nullptr_t endptr) { return sprout::detail::str_to_float(str); } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR FloatType str_to_float(Char const* str) { + inline SPROUT_CONSTEXPR FloatType + str_to_float(Char const* str) { return sprout::detail::str_to_float(str); } } // namespace sprout diff --git a/sprout/cstdlib/str_to_int.hpp b/sprout/cstdlib/str_to_int.hpp index 677c9871..44539471 100644 --- a/sprout/cstdlib/str_to_int.hpp +++ b/sprout/cstdlib/str_to_int.hpp @@ -17,11 +17,11 @@ namespace sprout { // Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/ template - inline SPROUT_CONSTEXPR IntType str_to_int_impl_1(CStrIterator str, int base, IntType val, IntType x, bool negative) { - return x == static_cast(-1) - ? (negative ? -val : val) + inline SPROUT_CONSTEXPR IntType + str_to_int_impl_1(CStrIterator str, int base, IntType val, IntType x, bool negative) { + return x == static_cast(-1) ? (negative ? -val : val) : val > (std::numeric_limits::max() - x - (negative ? 1 : 0)) / base - ? (negative ? std::numeric_limits::min() : std::numeric_limits::max()) + ? (negative ? std::numeric_limits::min() : std::numeric_limits::max()) : sprout::detail::str_to_int_impl_1( sprout::next(str), base, @@ -32,7 +32,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR IntType str_to_int_impl(CStrIterator str, int base, bool negative) { + inline SPROUT_CONSTEXPR IntType + str_to_int_impl(CStrIterator str, int base, bool negative) { return *str == static_cast::value_type>('0') ? *sprout::next(str) == static_cast::value_type>('x') || *sprout::next(str) == static_cast::value_type>('X') @@ -60,27 +61,30 @@ namespace sprout { ; } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) { + inline SPROUT_CONSTEXPR IntType + str_to_int(CStrIterator str, int base) { return sprout::ascii::isspace(*str) - ? sprout::detail::str_to_int(sprout::next(str), base) + ? sprout::detail::str_to_int(sprout::next(str), base) : *str == static_cast::value_type>('+') - ? sprout::detail::str_to_int_impl(sprout::next(str), base, false) + ? sprout::detail::str_to_int_impl(sprout::next(str), base, false) : sprout::detail::str_to_int_impl(str, base, false) ; } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) { + inline SPROUT_CONSTEXPR IntType + str_to_int(CStrIterator str, int base) { return sprout::ascii::isspace(*str) - ? sprout::detail::str_to_int(sprout::next(str), base) + ? sprout::detail::str_to_int(sprout::next(str), base) : *str == static_cast::value_type>('-') - ? sprout::detail::str_to_int_impl(sprout::next(str), base, true) + ? sprout::detail::str_to_int_impl(sprout::next(str), base, true) : *str == static_cast::value_type>('+') - ? sprout::detail::str_to_int_impl(sprout::next(str), base, false) + ? sprout::detail::str_to_int_impl(sprout::next(str), base, false) : sprout::detail::str_to_int_impl(str, base, false) ; } template - inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, CharPtr* endptr, int base) { + inline SPROUT_CONSTEXPR IntType + str_to_int(CStrIterator str, CharPtr* endptr, int base) { return !endptr ? sprout::detail::str_to_int(str, base) : std::is_signed::value ? sizeof(IntType) <= sizeof(long) ? static_cast(std::strtol(&*str, endptr, base)) @@ -97,15 +101,18 @@ namespace sprout { // str_to_int // template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType str_to_int(Char const* str, Char** endptr, int base = 10) { + inline SPROUT_CONSTEXPR IntType + str_to_int(Char const* str, Char** endptr, int base = 10) { return sprout::detail::str_to_int(str, endptr, base); } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType str_to_int(Char const* str, std::nullptr_t endptr, int base = 10) { + inline SPROUT_CONSTEXPR IntType + str_to_int(Char const* str, std::nullptr_t endptr, int base = 10) { return sprout::detail::str_to_int(str, base); } template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType str_to_int(Char const* str, int base = 10) { + inline SPROUT_CONSTEXPR IntType + str_to_int(Char const* str, int base = 10) { return sprout::detail::str_to_int(str, base); } } // namespace sprout diff --git a/sprout/cstdlib/strtod.hpp b/sprout/cstdlib/strtod.hpp index 23926cc1..49383220 100644 --- a/sprout/cstdlib/strtod.hpp +++ b/sprout/cstdlib/strtod.hpp @@ -10,15 +10,18 @@ namespace sprout { // strtod // template - inline SPROUT_CONSTEXPR double strtod(Char const* str, Char** endptr){ + inline SPROUT_CONSTEXPR double + strtod(Char const* str, Char** endptr) { return sprout::str_to_float(str, endptr); } template - inline SPROUT_CONSTEXPR double strtod(Char const* str, std::nullptr_t endptr){ + inline SPROUT_CONSTEXPR double + strtod(Char const* str, std::nullptr_t endptr) { return sprout::str_to_float(str); } template - inline SPROUT_CONSTEXPR double strtod(Char const* str){ + inline SPROUT_CONSTEXPR double + strtod(Char const* str) { return sprout::str_to_float(str); } } // namespace sprout diff --git a/sprout/cstdlib/strtof.hpp b/sprout/cstdlib/strtof.hpp index 257e059a..9089453e 100644 --- a/sprout/cstdlib/strtof.hpp +++ b/sprout/cstdlib/strtof.hpp @@ -10,15 +10,18 @@ namespace sprout { // strtof // template - inline SPROUT_CONSTEXPR float strtof(Char const* str, Char** endptr){ + inline SPROUT_CONSTEXPR float + strtof(Char const* str, Char** endptr) { return sprout::str_to_float(str, endptr); } template - inline SPROUT_CONSTEXPR float strtof(Char const* str, std::nullptr_t endptr){ + inline SPROUT_CONSTEXPR float + strtof(Char const* str, std::nullptr_t endptr) { return sprout::str_to_float(str); } template - inline SPROUT_CONSTEXPR float strtof(Char const* str){ + inline SPROUT_CONSTEXPR float + strtof(Char const* str) { return sprout::str_to_float(str); } } // namespace sprout diff --git a/sprout/cstdlib/strtol.hpp b/sprout/cstdlib/strtol.hpp index 3ac23064..f9d41abb 100644 --- a/sprout/cstdlib/strtol.hpp +++ b/sprout/cstdlib/strtol.hpp @@ -9,19 +9,23 @@ namespace sprout { // // strtol // - inline SPROUT_CONSTEXPR long strtol(char const* str, char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR long + strtol(char const* str, char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR long strtol(Char const* str, Char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR long + strtol(Char const* str, Char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR long strtol(Char const* str, std::nullptr_t endptr, int base = 10){ + inline SPROUT_CONSTEXPR long + strtol(Char const* str, std::nullptr_t endptr, int base = 10) { return sprout::str_to_int(str, base); } template - inline SPROUT_CONSTEXPR long strtol(Char const* str, int base = 10){ + inline SPROUT_CONSTEXPR long + strtol(Char const* str, int base = 10) { return sprout::str_to_int(str, base); } } // namespace sprout diff --git a/sprout/cstdlib/strtold.hpp b/sprout/cstdlib/strtold.hpp index 809ed27a..6afd0d59 100644 --- a/sprout/cstdlib/strtold.hpp +++ b/sprout/cstdlib/strtold.hpp @@ -10,15 +10,18 @@ namespace sprout { // strtold // template - inline SPROUT_CONSTEXPR long double strtold(Char const* str, Char** endptr){ + inline SPROUT_CONSTEXPR long double + strtold(Char const* str, Char** endptr) { return sprout::str_to_float(str, endptr); } template - inline SPROUT_CONSTEXPR long double strtold(Char const* str, std::nullptr_t endptr){ + inline SPROUT_CONSTEXPR long double + strtold(Char const* str, std::nullptr_t endptr) { return sprout::str_to_float(str); } template - inline SPROUT_CONSTEXPR long double strtold(Char const* str){ + inline SPROUT_CONSTEXPR long double + strtold(Char const* str) { return sprout::str_to_float(str); } } // namespace sprout diff --git a/sprout/cstdlib/strtoll.hpp b/sprout/cstdlib/strtoll.hpp index 32782f03..e8ceec98 100644 --- a/sprout/cstdlib/strtoll.hpp +++ b/sprout/cstdlib/strtoll.hpp @@ -9,19 +9,23 @@ namespace sprout { // // strtol // - inline SPROUT_CONSTEXPR long long strtoll(char const* str, char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR long long + strtoll(char const* str, char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR long long strtoll(Char const* str, Char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR long long + strtoll(Char const* str, Char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR long long strtoll(Char const* str, std::nullptr_t endptr, int base = 10){ + inline SPROUT_CONSTEXPR long long + strtoll(Char const* str, std::nullptr_t endptr, int base = 10) { return sprout::str_to_int(str, base); } template - inline SPROUT_CONSTEXPR long long strtoll(Char const* str, int base = 10){ + inline SPROUT_CONSTEXPR long long + strtoll(Char const* str, int base = 10) { return sprout::str_to_int(str, base); } } // namespace sprout diff --git a/sprout/cstdlib/strtoul.hpp b/sprout/cstdlib/strtoul.hpp index b1e6990f..f0b6a564 100644 --- a/sprout/cstdlib/strtoul.hpp +++ b/sprout/cstdlib/strtoul.hpp @@ -9,19 +9,23 @@ namespace sprout { // // strtoul // - inline SPROUT_CONSTEXPR unsigned long strtoul(char const* str, char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long + strtoul(char const* str, char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, Char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long + strtoul(Char const* str, Char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, std::nullptr_t endptr, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long + strtoul(Char const* str, std::nullptr_t endptr, int base = 10) { return sprout::str_to_int(str, base); } template - inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long + strtoul(Char const* str, int base = 10) { return sprout::str_to_int(str, base); } } // namespace sprout diff --git a/sprout/cstdlib/strtoull.hpp b/sprout/cstdlib/strtoull.hpp index f0c78f20..52850316 100644 --- a/sprout/cstdlib/strtoull.hpp +++ b/sprout/cstdlib/strtoull.hpp @@ -9,19 +9,23 @@ namespace sprout { // // strtoul // - inline SPROUT_CONSTEXPR unsigned long long strtoull(char const* str, char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long long + strtoull(char const* str, char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, Char** endptr, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long long + strtoull(Char const* str, Char** endptr, int base = 10) { return sprout::str_to_int(str, endptr, base); } template - inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, std::nullptr_t endptr, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long long + strtoull(Char const* str, std::nullptr_t endptr, int base = 10) { return sprout::str_to_int(str, base); } template - inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, int base = 10){ + inline SPROUT_CONSTEXPR unsigned long long + strtoull(Char const* str, int base = 10) { return sprout::str_to_int(str, base); } } // namespace sprout diff --git a/sprout/cstring/memchr.hpp b/sprout/cstring/memchr.hpp index 1abff2d8..b93abc89 100644 --- a/sprout/cstring/memchr.hpp +++ b/sprout/cstring/memchr.hpp @@ -8,7 +8,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR void const* memchr_impl(unsigned char const* s, unsigned char c, std::size_t n) { + inline SPROUT_CONSTEXPR void const* + memchr_impl(unsigned char const* s, unsigned char c, std::size_t n) { return !n ? 0 : *s == c ? s : sprout::detail::memchr_impl(s + 1, c, n - 1) @@ -17,11 +18,13 @@ namespace sprout { } // namespace detail // 7.21.5.1 memchr ŠÖ” - inline SPROUT_CONSTEXPR void const* memchr(void const* s, int c, size_t n) { + inline SPROUT_CONSTEXPR void const* + memchr(void const* s, int c, size_t n) { return sprout::detail::memchr_impl(static_cast(s), static_cast(c), n); } - inline SPROUT_CONSTEXPR void* memchr(void* s, int c, size_t n) { + inline SPROUT_CONSTEXPR void* + memchr(void* s, int c, size_t n) { return const_cast( sprout::detail::memchr_impl(static_cast(s), static_cast(c), n) ); diff --git a/sprout/cstring/memcmp.hpp b/sprout/cstring/memcmp.hpp index 766ba1dc..5370b38d 100644 --- a/sprout/cstring/memcmp.hpp +++ b/sprout/cstring/memcmp.hpp @@ -8,7 +8,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR int memcmp_impl(unsigned char const* s1, unsigned char const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR int + memcmp_impl(unsigned char const* s1, unsigned char const* s2, std::size_t n) { return !n ? 0 : *s1 == *s2 ? sprout::detail::memcmp_impl(s1 + 1, s2 + 1, n - 1) : *s1 - *s2 @@ -17,7 +18,8 @@ namespace sprout { } // namespace detail // 7.21.4.1 memcmp ŠÖ” - inline SPROUT_CONSTEXPR int memcmp(void const* s1, void const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR int + memcmp(void const* s1, void const* s2, std::size_t n) { return sprout::detail::memcmp_impl( static_cast(s1), static_cast(s2), diff --git a/sprout/cstring/strchr.hpp b/sprout/cstring/strchr.hpp index 27a9d151..b243877f 100644 --- a/sprout/cstring/strchr.hpp +++ b/sprout/cstring/strchr.hpp @@ -8,14 +8,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.21.5.2 strchr ŠÖ” - inline SPROUT_CONSTEXPR char const* strchr(char const* s, int c) { + inline SPROUT_CONSTEXPR char const* + strchr(char const* s, int c) { return *s == static_cast(c) ? s : !*s ? nullptr : sprout::strchr(s + 1, c) ; } - inline SPROUT_CONSTEXPR char* strchr(char* s, int c) { + inline SPROUT_CONSTEXPR char* + strchr(char* s, int c) { return const_cast(sprout::strchr(const_cast(s), c)); } } // namespace sprout diff --git a/sprout/cstring/strcmp.hpp b/sprout/cstring/strcmp.hpp index 95b6de8d..6c248fdc 100644 --- a/sprout/cstring/strcmp.hpp +++ b/sprout/cstring/strcmp.hpp @@ -7,7 +7,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.21.4.2 strcmp ŠÖ” - inline SPROUT_CONSTEXPR int strcmp(char const* s1, char const* s2) { + inline SPROUT_CONSTEXPR int + strcmp(char const* s1, char const* s2) { return !*s1 && !*s2 ? 0 : !*s1 ? -1 : !*s2 ? 1 diff --git a/sprout/cstring/strcoll.hpp b/sprout/cstring/strcoll.hpp index f87632a7..eeb20e6d 100644 --- a/sprout/cstring/strcoll.hpp +++ b/sprout/cstring/strcoll.hpp @@ -8,7 +8,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.21.4.3 strcoll ŠÖ” - inline SPROUT_CONSTEXPR int strcoll(char const* s1, char const* s2) { + inline SPROUT_CONSTEXPR int + strcoll(char const* s1, char const* s2) { return sprout::strcmp(s1, s2); } } // namespace sprout diff --git a/sprout/cstring/strcspn.hpp b/sprout/cstring/strcspn.hpp index fa32fa33..49d5e2e8 100644 --- a/sprout/cstring/strcspn.hpp +++ b/sprout/cstring/strcspn.hpp @@ -9,7 +9,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR std::size_t strcspn_impl(char const* s1, char const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR std::size_t + strcspn_impl(char const* s1, char const* s2, std::size_t n) { return !*s1 || sprout::strchr(s2, *s1) ? n : sprout::detail::strcspn_impl(s1 + 1, s2, n + 1) ; @@ -17,7 +18,8 @@ namespace sprout { } // amespace detail // 7.21.5.3 strcspn ŠÖ” - inline SPROUT_CONSTEXPR std::size_t strcspn(char const* s1, char const* s2) { + inline SPROUT_CONSTEXPR std::size_t + strcspn(char const* s1, char const* s2) { return sprout::detail::strcspn_impl(s1, s2, 0); } } // namespace sprout diff --git a/sprout/cstring/strlen.hpp b/sprout/cstring/strlen.hpp index 58c67bfd..61d8d5c3 100644 --- a/sprout/cstring/strlen.hpp +++ b/sprout/cstring/strlen.hpp @@ -8,7 +8,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR std::size_t strlen_impl(char const* s, std::size_t n) { + inline SPROUT_CONSTEXPR std::size_t + strlen_impl(char const* s, std::size_t n) { return !*s ? n : sprout::detail::strlen_impl(s + 1, n + 1) ; @@ -16,7 +17,8 @@ namespace sprout { } // namespace detail // 7.21.6.3 strlen ŠÖ” - inline SPROUT_CONSTEXPR std::size_t strlen(char const* s) { + inline SPROUT_CONSTEXPR std::size_t + strlen(char const* s) { return sprout::detail::strlen_impl(s, 0); } } // namespace sprout diff --git a/sprout/cstring/strncmp.hpp b/sprout/cstring/strncmp.hpp index 78fadd2d..d0db0c9d 100644 --- a/sprout/cstring/strncmp.hpp +++ b/sprout/cstring/strncmp.hpp @@ -8,7 +8,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.21.4.4 strncmp ŠÖ” - inline SPROUT_CONSTEXPR int strncmp(char const* s1, char const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR int + strncmp(char const* s1, char const* s2, std::size_t n) { return !n || (!*s1 && !*s2) ? 0 : !*s1 ? -1 : !*s2 ? 1 diff --git a/sprout/cstring/strpbrk.hpp b/sprout/cstring/strpbrk.hpp index 9bb98689..d51592ac 100644 --- a/sprout/cstring/strpbrk.hpp +++ b/sprout/cstring/strpbrk.hpp @@ -9,14 +9,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.21.5.4 strpbrk ŠÖ” - inline SPROUT_CONSTEXPR char const* strpbrk(char const* s1, char const* s2) { + inline SPROUT_CONSTEXPR char const* + strpbrk(char const* s1, char const* s2) { return !*s1 ? nullptr : sprout::strchr(s2, *s1) ? s1 : sprout::strpbrk(s1 + 1, s2) ; } - inline SPROUT_CONSTEXPR char* strpbrk(char* s1, char const* s2) { + inline SPROUT_CONSTEXPR char* + strpbrk(char* s1, char const* s2) { return const_cast(sprout::strpbrk(const_cast(s1), s2)); } } // namespace sprout diff --git a/sprout/cstring/strrchr.hpp b/sprout/cstring/strrchr.hpp index 55c17c26..54c58601 100644 --- a/sprout/cstring/strrchr.hpp +++ b/sprout/cstring/strrchr.hpp @@ -8,14 +8,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.21.5.5 strrchr ŠÖ” - inline SPROUT_CONSTEXPR char const* strrchr(char const* s, int c) { + inline SPROUT_CONSTEXPR char const* + strrchr(char const* s, int c) { return *s == static_cast(c) && (!*s || !sprout::strrchr(s + 1, c))? s : !*s ? nullptr : sprout::strrchr(s + 1, c) ; } - inline SPROUT_CONSTEXPR char* strrchr(char* s, int c) { + inline SPROUT_CONSTEXPR char* + strrchr(char* s, int c) { return const_cast(sprout::strrchr(const_cast(s), c)); } } // namespace sprout diff --git a/sprout/cstring/strspn.hpp b/sprout/cstring/strspn.hpp index f11a7484..0ffb2cdb 100644 --- a/sprout/cstring/strspn.hpp +++ b/sprout/cstring/strspn.hpp @@ -9,7 +9,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR std::size_t strspn_impl(char const* s1, char const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR std::size_t + strspn_impl(char const* s1, char const* s2, std::size_t n) { return !*s1 || !sprout::strchr(s2, *s1) ? n : sprout::detail::strspn_impl(s1 + 1, s2, n + 1) ; @@ -17,7 +18,8 @@ namespace sprout { } // namespace detail // 7.21.5.6 strspn ŠÖ” - inline SPROUT_CONSTEXPR std::size_t strspn(char const* s1, char const* s2) { + inline SPROUT_CONSTEXPR std::size_t + strspn(char const* s1, char const* s2) { return sprout::detail::strspn_impl(s1, s2, 0); } } // namespace sprout diff --git a/sprout/cstring/strstr.hpp b/sprout/cstring/strstr.hpp index 3338f2f1..1e91ea04 100644 --- a/sprout/cstring/strstr.hpp +++ b/sprout/cstring/strstr.hpp @@ -7,7 +7,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 7.21.5.7 strstr ŠÖ” - inline SPROUT_CONSTEXPR char const* strstr(char const* s1, char const* s2) { + inline SPROUT_CONSTEXPR char const* + strstr(char const* s1, char const* s2) { return !*s2 ? s1 : !*s1 ? nullptr : *s1 == *s2 && sprout::strstr(s1 + 1, s2 + 1) ? s1 @@ -15,7 +16,8 @@ namespace sprout { ; } - inline SPROUT_CONSTEXPR char* strstr(char* s1, char const* s2) { + inline SPROUT_CONSTEXPR char* + strstr(char* s1, char const* s2) { return const_cast(sprout::strstr(const_cast(s1), s2)); } } // namespace sprout diff --git a/sprout/ctype/ascii.hpp b/sprout/ctype/ascii.hpp index f2feed31..66f36b89 100644 --- a/sprout/ctype/ascii.hpp +++ b/sprout/ctype/ascii.hpp @@ -180,46 +180,60 @@ namespace sprout { } // namespace detail #define SPROUT_CTYPE_ASCII_DECL(CHAR_TYPE, PREFIX) \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alnum))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alnum))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & (sprout::ascii::detail::alpha | sprout::ascii::detail::digit); \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alpha))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alpha))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::alpha; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, blank))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, blank))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::blank; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, cntrl))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, cntrl))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::cntrl; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, digit))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, digit))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::digit; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, graph))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, graph))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::graph; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::lower; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, print))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, print))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::print; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, punct))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, punct))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::punct; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, space))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, space))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::space; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper; \ } \ - inline SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, xdigit))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR bool \ + SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, xdigit))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::xdigit; \ } \ - inline SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR CHAR_TYPE \ + SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::lower ? c + (0x61 - 0x41) : c; \ } \ - inline SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \ + inline SPROUT_CONSTEXPR CHAR_TYPE \ + SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper ? c - (0x61 - 0x41) : c; \ } diff --git a/sprout/cwchar/wcschr.hpp b/sprout/cwchar/wcschr.hpp index 9d5192c9..118c556e 100644 --- a/sprout/cwchar/wcschr.hpp +++ b/sprout/cwchar/wcschr.hpp @@ -7,14 +7,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) - inline SPROUT_CONSTEXPR wchar_t const* wcschr(wchar_t const* s, int c) { + inline SPROUT_CONSTEXPR wchar_t const* + wcschr(wchar_t const* s, int c) { return *s == static_cast(c) ? s : !*s ? nullptr : sprout::wcschr(s + 1, c) ; } - inline SPROUT_CONSTEXPR wchar_t* wcschr(wchar_t* s, int c) { + inline SPROUT_CONSTEXPR wchar_t* + wcschr(wchar_t* s, int c) { return const_cast(sprout::wcschr(const_cast(s), c)); } } // namespace sprout diff --git a/sprout/cwchar/wcscmp.hpp b/sprout/cwchar/wcscmp.hpp index 3208a7cb..0f6b5521 100644 --- a/sprout/cwchar/wcscmp.hpp +++ b/sprout/cwchar/wcscmp.hpp @@ -6,7 +6,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) - inline SPROUT_CONSTEXPR int wcscmp(wchar_t const* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR int + wcscmp(wchar_t const* s1, wchar_t const* s2) { return !*s1 && !*s2 ? 0 : !*s1 ? -1 : !*s2 ? 1 diff --git a/sprout/cwchar/wcscoll.hpp b/sprout/cwchar/wcscoll.hpp index 7cb45bb5..03ce6821 100644 --- a/sprout/cwchar/wcscoll.hpp +++ b/sprout/cwchar/wcscoll.hpp @@ -7,7 +7,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) - inline SPROUT_CONSTEXPR int wcscoll(wchar_t const* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR int + wcscoll(wchar_t const* s1, wchar_t const* s2) { return sprout::wcscmp(s1, s2); } } // namespace sprout diff --git a/sprout/cwchar/wcscspn.hpp b/sprout/cwchar/wcscspn.hpp index fe5ab9e9..f2a4a0ba 100644 --- a/sprout/cwchar/wcscspn.hpp +++ b/sprout/cwchar/wcscspn.hpp @@ -9,14 +9,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR std::size_t wcscspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR std::size_t + wcscspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { return !*s1 || sprout::wcschr(s2, *s1) ? n : sprout::detail::wcscspn_impl(s1 + 1, s2, n + 1) ; } } // amespace detail - inline SPROUT_CONSTEXPR std::size_t wcscspn(wchar_t const* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR std::size_t + wcscspn(wchar_t const* s1, wchar_t const* s2) { return sprout::detail::wcscspn_impl(s1, s2, 0); } } // namespace sprout diff --git a/sprout/cwchar/wcslen.hpp b/sprout/cwchar/wcslen.hpp index e44cf245..1a68ba4a 100644 --- a/sprout/cwchar/wcslen.hpp +++ b/sprout/cwchar/wcslen.hpp @@ -8,14 +8,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR std::size_t wcslen_impl(wchar_t const* s, std::size_t n) { + inline SPROUT_CONSTEXPR std::size_t + wcslen_impl(wchar_t const* s, std::size_t n) { return !*s ? n : sprout::detail::wcslen_impl(s + 1, n + 1) ; } } // namespace detail - inline SPROUT_CONSTEXPR std::size_t wcslen(wchar_t const* s) { + inline SPROUT_CONSTEXPR std::size_t + wcslen(wchar_t const* s) { return sprout::detail::wcslen_impl(s, 0); } } // namespace sprout diff --git a/sprout/cwchar/wcsncmp.hpp b/sprout/cwchar/wcsncmp.hpp index b2d2f193..77b0c44e 100644 --- a/sprout/cwchar/wcsncmp.hpp +++ b/sprout/cwchar/wcsncmp.hpp @@ -7,7 +7,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) - inline SPROUT_CONSTEXPR int wcsncmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR int + wcsncmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) { return !n || (!*s1 && !*s2) ? 0 : !*s1 ? -1 : !*s2 ? 1 diff --git a/sprout/cwchar/wcspbrk.hpp b/sprout/cwchar/wcspbrk.hpp index f082b398..1921fa77 100644 --- a/sprout/cwchar/wcspbrk.hpp +++ b/sprout/cwchar/wcspbrk.hpp @@ -8,14 +8,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) - inline SPROUT_CONSTEXPR wchar_t const* wcspbrk(wchar_t const* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR wchar_t const* + wcspbrk(wchar_t const* s1, wchar_t const* s2) { return !*s1 ? nullptr : sprout::wcschr(s2, *s1) ? s1 : sprout::wcspbrk(s1 + 1, s2) ; } - inline SPROUT_CONSTEXPR wchar_t* wcspbrk(wchar_t* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR wchar_t* + wcspbrk(wchar_t* s1, wchar_t const* s2) { return const_cast(sprout::wcspbrk(const_cast(s1), s2)); } } // namespace sprout diff --git a/sprout/cwchar/wcsrchr.hpp b/sprout/cwchar/wcsrchr.hpp index ab069e95..d750af79 100644 --- a/sprout/cwchar/wcsrchr.hpp +++ b/sprout/cwchar/wcsrchr.hpp @@ -7,14 +7,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) - inline SPROUT_CONSTEXPR wchar_t const* wcsrchr(wchar_t const* s, int c) { + inline SPROUT_CONSTEXPR wchar_t const* + wcsrchr(wchar_t const* s, int c) { return *s == static_cast(c) && (!*s || !sprout::wcsrchr(s + 1, c))? s : !*s ? nullptr : sprout::wcsrchr(s + 1, c) ; } - inline SPROUT_CONSTEXPR wchar_t* wcsrchr(wchar_t* s, int c) { + inline SPROUT_CONSTEXPR wchar_t* + wcsrchr(wchar_t* s, int c) { return const_cast(sprout::wcsrchr(const_cast(s), c)); } } // namespace sprout diff --git a/sprout/cwchar/wcsspn.hpp b/sprout/cwchar/wcsspn.hpp index fbab327d..f43bf342 100644 --- a/sprout/cwchar/wcsspn.hpp +++ b/sprout/cwchar/wcsspn.hpp @@ -9,14 +9,16 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR std::size_t wcsspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR std::size_t + wcsspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { return !*s1 || !sprout::wcschr(s2, *s1) ? n : sprout::detail::wcsspn_impl(s1 + 1, s2, n + 1) ; } } // namespace detail - inline SPROUT_CONSTEXPR std::size_t wcsspn(wchar_t const* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR std::size_t + wcsspn(wchar_t const* s1, wchar_t const* s2) { return sprout::detail::wcsspn_impl(s1, s2, 0); } } // namespace sprout diff --git a/sprout/cwchar/wcsstr.hpp b/sprout/cwchar/wcsstr.hpp index 6f55241b..add4f69c 100644 --- a/sprout/cwchar/wcsstr.hpp +++ b/sprout/cwchar/wcsstr.hpp @@ -6,7 +6,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) - inline SPROUT_CONSTEXPR wchar_t const* wcsstr(wchar_t const* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR wchar_t const* + wcsstr(wchar_t const* s1, wchar_t const* s2) { return !*s2 ? s1 : !*s1 ? nullptr : *s1 == *s2 && sprout::wcsstr(s1 + 1, s2 + 1) ? s1 @@ -14,7 +15,8 @@ namespace sprout { ; } - inline SPROUT_CONSTEXPR wchar_t* wcsstr(wchar_t* s1, wchar_t const* s2) { + inline SPROUT_CONSTEXPR wchar_t* + wcsstr(wchar_t* s1, wchar_t const* s2) { return const_cast(sprout::wcsstr(const_cast(s1), s2)); } } // namespace sprout diff --git a/sprout/cwchar/wmemchr.hpp b/sprout/cwchar/wmemchr.hpp index 85aad0ae..e4b92b00 100644 --- a/sprout/cwchar/wmemchr.hpp +++ b/sprout/cwchar/wmemchr.hpp @@ -8,7 +8,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR wchar_t const* wmemchr_impl(wchar_t const* s, wchar_t c, std::size_t n) { + inline SPROUT_CONSTEXPR wchar_t const* + wmemchr_impl(wchar_t const* s, wchar_t c, std::size_t n) { return !n ? 0 : *s == c ? s : sprout::detail::wmemchr_impl(s + 1, c, n - 1) @@ -16,14 +17,14 @@ namespace sprout { } } // namespace detail - inline SPROUT_CONSTEXPR wchar_t const* wmemchr(wchar_t const* s, wchar_t c, size_t n) { + inline SPROUT_CONSTEXPR wchar_t const* + wmemchr(wchar_t const* s, wchar_t c, size_t n) { return sprout::detail::wmemchr_impl(s, c, n); } - inline SPROUT_CONSTEXPR wchar_t* wmemchr(wchar_t* s, wchar_t c, size_t n) { - return const_cast( - sprout::detail::wmemchr_impl(s, c, n) - ); + inline SPROUT_CONSTEXPR wchar_t* + wmemchr(wchar_t* s, wchar_t c, size_t n) { + return const_cast(sprout::detail::wmemchr_impl(s, c, n)); } } // namespace sprout diff --git a/sprout/cwchar/wmemcmp.hpp b/sprout/cwchar/wmemcmp.hpp index b34679b7..003061f8 100644 --- a/sprout/cwchar/wmemcmp.hpp +++ b/sprout/cwchar/wmemcmp.hpp @@ -8,7 +8,8 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR int wmemcmp_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + inline SPROUT_CONSTEXPR int + wmemcmp_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { return !n ? 0 : *s1 == *s2 ? sprout::detail::wmemcmp_impl(s1 + 1, s2 + 1, n - 1) : *s1 - *s2 @@ -16,12 +17,9 @@ namespace sprout { } } // namespace detail - inline SPROUT_CONSTEXPR int wmemcmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) { - return sprout::detail::wmemcmp_impl( - s1, - s2, - n - ); + inline SPROUT_CONSTEXPR int + wmemcmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + return sprout::detail::wmemcmp_impl(s1, s2, n); } } // namespace sprout diff --git a/sprout/darkroom/access/access.hpp b/sprout/darkroom/access/access.hpp index 72252416..ce8e1d34 100644 --- a/sprout/darkroom/access/access.hpp +++ b/sprout/darkroom/access/access.hpp @@ -34,9 +34,10 @@ namespace sprout { // get // template - inline SPROUT_CONSTEXPR auto get(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get(sprout::forward(t)))) - -> decltype(sprout::tuples::get(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + get(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get(sprout::forward(t)))) + -> decltype(sprout::tuples::get(sprout::forward(t))) { return sprout::tuples::get(sprout::forward(t)); } diff --git a/sprout/darkroom/cameras/simple_camera.hpp b/sprout/darkroom/cameras/simple_camera.hpp index a556a1cf..b09d00d9 100644 --- a/sprout/darkroom/cameras/simple_camera.hpp +++ b/sprout/darkroom/cameras/simple_camera.hpp @@ -29,13 +29,8 @@ namespace sprout { position_type fixation_point_; unit_type rotate_; private: - SPROUT_CONSTEXPR position_type transform_1( - position_type const& c, - unit_type const& u, - unit_type const& v, - unit_type const& l - ) const - { + SPROUT_CONSTEXPR position_type + transform_1(position_type const& c, unit_type const& u, unit_type const& v, unit_type const& l) const { return sprout::darkroom::coords::add( c, position_type( @@ -45,12 +40,8 @@ namespace sprout { ) ); } - SPROUT_CONSTEXPR position_type transform( - position_type const& c, - unit_type const& u, - unit_type const& v - ) const - { + SPROUT_CONSTEXPR position_type + transform(position_type const& c, unit_type const& u, unit_type const& v) const { return transform_1( c, u * sprout::cos(rotate_) - v * sprout::sin(rotate_), @@ -62,11 +53,10 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR position_type reference_width( - Unit2D const& x, - Unit2D const& y, - Unit2D const& width, - Unit2D const& height, + SPROUT_CONSTEXPR position_type + reference_width( + Unit2D const& x, Unit2D const& y, + Unit2D const& width, Unit2D const& height, unit_type const& rate ) const { @@ -80,11 +70,10 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR position_type reference_height( - Unit2D const& x, - Unit2D const& y, - Unit2D const& width, - Unit2D const& height, + SPROUT_CONSTEXPR position_type + reference_height( + Unit2D const& x, Unit2D const& y, + Unit2D const& width, Unit2D const& height, unit_type const& rate ) const { @@ -112,13 +101,8 @@ namespace sprout { , rotate_(rotate) {} template - SPROUT_CONSTEXPR ray_type operator()( - Unit2D const& x, - Unit2D const& y, - Unit2D const& width, - Unit2D const& height - ) const - { + SPROUT_CONSTEXPR ray_type + operator()(Unit2D const& x, Unit2D const& y, Unit2D const& width, Unit2D const& height) const { return ray_type( position_, sprout::darkroom::coords::normalize( diff --git a/sprout/darkroom/colors/rgb.hpp b/sprout/darkroom/colors/rgb.hpp index bfe0e1e8..989d9cca 100644 --- a/sprout/darkroom/colors/rgb.hpp +++ b/sprout/darkroom/colors/rgb.hpp @@ -19,30 +19,34 @@ namespace sprout { // a // template - inline SPROUT_CONSTEXPR auto r(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + r(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) { return sprout::darkroom::access::get<0>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto g(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + g(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) { return sprout::darkroom::access::get<1>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto b(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + b(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) { return sprout::darkroom::access::get<2>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto a(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<3>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + a(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<3>(sprout::forward(t))) { return sprout::darkroom::access::get<3>(sprout::forward(t)); } @@ -58,7 +62,8 @@ namespace sprout { // mul // template - inline SPROUT_CONSTEXPR Color mul(Color const& lhs, Fac const& rhs) { + inline SPROUT_CONSTEXPR Color + mul(Color const& lhs, Fac const& rhs) { return sprout::tuples::remake( lhs, sprout::darkroom::colors::r(lhs) * rhs, @@ -70,7 +75,8 @@ namespace sprout { // add // template - inline SPROUT_CONSTEXPR Color1 add(Color1 const& lhs, Color2 const& rhs) { + inline SPROUT_CONSTEXPR Color1 + add(Color1 const& lhs, Color2 const& rhs) { return sprout::tuples::remake( lhs, sprout::darkroom::colors::r(lhs) + sprout::darkroom::colors::r(rhs), @@ -82,7 +88,8 @@ namespace sprout { // filter // template - inline SPROUT_CONSTEXPR Color1 filter(Color1 const& lhs, Color2 const& rhs) { + inline SPROUT_CONSTEXPR Color1 + filter(Color1 const& lhs, Color2 const& rhs) { return sprout::tuples::remake( lhs, sprout::darkroom::colors::r(lhs) * sprout::darkroom::colors::r(rhs), @@ -95,7 +102,8 @@ namespace sprout { // rgb_f_to_rgb // template - inline SPROUT_CONSTEXPR RGB rgb_f_to_rgb(RGB_F const& col) { + inline SPROUT_CONSTEXPR RGB + rgb_f_to_rgb(RGB_F const& col) { typedef typename sprout::darkroom::access::unit::type unit_type; return sprout::tuples::make( sprout::darkroom::colors::r(col) < 0 ? std::numeric_limits::min() diff --git a/sprout/darkroom/coords/vector.hpp b/sprout/darkroom/coords/vector.hpp index 16edd2dd..ccd55f01 100644 --- a/sprout/darkroom/coords/vector.hpp +++ b/sprout/darkroom/coords/vector.hpp @@ -17,23 +17,26 @@ namespace sprout { // z // template - inline SPROUT_CONSTEXPR auto x(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + x(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) { return sprout::darkroom::access::get<0>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto y(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + y(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) { return sprout::darkroom::access::get<1>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto z(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + z(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) { return sprout::darkroom::access::get<2>(sprout::forward(t)); } @@ -66,7 +69,8 @@ namespace sprout { // add // template - inline SPROUT_CONSTEXPR Vector1 add(Vector1 const& lhs, Vector2 const& rhs) { + inline SPROUT_CONSTEXPR Vector1 + add(Vector1 const& lhs, Vector2 const& rhs) { return sprout::tuples::remake( lhs, sprout::darkroom::coords::x(lhs) + sprout::darkroom::coords::x(rhs), @@ -78,7 +82,8 @@ namespace sprout { // sub // template - inline SPROUT_CONSTEXPR Vector1 sub(Vector1 const& lhs, Vector2 const& rhs) { + inline SPROUT_CONSTEXPR Vector1 + sub(Vector1 const& lhs, Vector2 const& rhs) { return sprout::tuples::remake( lhs, sprout::darkroom::coords::x(lhs) - sprout::darkroom::coords::x(rhs), @@ -90,7 +95,8 @@ namespace sprout { // scale // template - inline SPROUT_CONSTEXPR Vector scale(Vector const& lhs, Fac const& rhs) { + inline SPROUT_CONSTEXPR Vector + scale(Vector const& lhs, Fac const& rhs) { return sprout::tuples::remake( lhs, sprout::darkroom::coords::x(lhs) * rhs, @@ -102,7 +108,8 @@ namespace sprout { // negate // template - inline SPROUT_CONSTEXPR Vector negate(Vector const& vec) { + inline SPROUT_CONSTEXPR Vector + negate(Vector const& vec) { return sprout::tuples::remake( vec, -sprout::darkroom::coords::x(vec), @@ -125,7 +132,8 @@ namespace sprout { // cross // template - inline SPROUT_CONSTEXPR Vector1 cross(Vector1 const& lhs, Vector2 const& rhs) { + inline SPROUT_CONSTEXPR Vector1 + cross(Vector1 const& lhs, Vector2 const& rhs) { return sprout::tuples::remake( lhs, sprout::darkroom::coords::y(lhs) * sprout::darkroom::coords::z(rhs) @@ -143,11 +151,8 @@ namespace sprout { // namespace detail { template - inline SPROUT_CONSTEXPR Vector normalize_impl( - Vector const& vec, - typename sprout::darkroom::access::unit::type const& len - ) - { + inline SPROUT_CONSTEXPR Vector + normalize_impl(Vector const& vec, typename sprout::darkroom::access::unit::type const& len) { return sprout::tuples::remake( vec, sprout::darkroom::coords::x(vec) / len, @@ -157,7 +162,8 @@ namespace sprout { } } // namespace detail template - inline SPROUT_CONSTEXPR Vector normalize(Vector const& vec) { + inline SPROUT_CONSTEXPR Vector + normalize(Vector const& vec) { return sprout::darkroom::coords::detail::normalize_impl( vec, sprout::darkroom::coords::length(vec) @@ -167,7 +173,8 @@ namespace sprout { // resize // template - inline SPROUT_CONSTEXPR Vector resize(Vector const& lhs, Fac const& rhs) { + inline SPROUT_CONSTEXPR Vector + resize(Vector const& lhs, Fac const& rhs) { return sprout::darkroom::coords::detail::normalize_impl( lhs, sprout::darkroom::coords::length(lhs) / rhs @@ -177,7 +184,8 @@ namespace sprout { // reflect // template - inline SPROUT_CONSTEXPR Incident reflect(Incident const& incid, Normal const& nor) { + inline SPROUT_CONSTEXPR Incident + reflect(Incident const& incid, Normal const& nor) { return sprout::darkroom::coords::sub( incid, sprout::darkroom::coords::scale(nor, sprout::darkroom::coords::dot(incid, nor) * 2) diff --git a/sprout/darkroom/intersects/intersection.hpp b/sprout/darkroom/intersects/intersection.hpp index af02dbb4..66087f2e 100644 --- a/sprout/darkroom/intersects/intersection.hpp +++ b/sprout/darkroom/intersects/intersection.hpp @@ -19,37 +19,42 @@ namespace sprout { // material // template - inline SPROUT_CONSTEXPR auto does_intersect(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + does_intersect(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) { return sprout::darkroom::access::get<0>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto distance(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + distance(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) { return sprout::darkroom::access::get<1>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto point_of_intersection(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + point_of_intersection(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) { return sprout::darkroom::access::get<2>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto normal(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<3>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + normal(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<3>(sprout::forward(t))) { return sprout::darkroom::access::get<3>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto material(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<4>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<4>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + material(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<4>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<4>(sprout::forward(t))) { return sprout::darkroom::access::get<4>(sprout::forward(t)); } diff --git a/sprout/darkroom/lights/ambient_light.hpp b/sprout/darkroom/lights/ambient_light.hpp index df0df8d5..d0722db6 100644 --- a/sprout/darkroom/lights/ambient_light.hpp +++ b/sprout/darkroom/lights/ambient_light.hpp @@ -26,7 +26,8 @@ namespace sprout { : col_(col) {} template - SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const&) const { + SPROUT_CONSTEXPR color_type + operator()(Intersection const& inter, Objects const&) const { return sprout::darkroom::colors::filter( col_, sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter)) diff --git a/sprout/darkroom/lights/light_list.hpp b/sprout/darkroom/lights/light_list.hpp index 126a8a2a..8673f76a 100644 --- a/sprout/darkroom/lights/light_list.hpp +++ b/sprout/darkroom/lights/light_list.hpp @@ -23,18 +23,21 @@ namespace sprout { lights_type lights_; private: template - SPROUT_CONSTEXPR color_type shade_2(Color const& col) const { + SPROUT_CONSTEXPR color_type + shade_2(Color const& col) const { return col; } template - SPROUT_CONSTEXPR color_type shade_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) const { + SPROUT_CONSTEXPR color_type + shade_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) const { return shade_2( sprout::darkroom::colors::add(col1, col2), tail... ); } template - SPROUT_CONSTEXPR color_type shade_1( + SPROUT_CONSTEXPR color_type + shade_1( Intersection const& inter, Objects const& objs, sprout::index_tuple ) const @@ -46,7 +49,8 @@ namespace sprout { : lights_(lights...) {} template - SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const { + SPROUT_CONSTEXPR color_type + operator()(Intersection const& inter, Objects const& objs) const { return shade_1(inter, objs, sprout::index_range<0, sizeof...(Lights)>::make()); } }; diff --git a/sprout/darkroom/lights/parallel_light.hpp b/sprout/darkroom/lights/parallel_light.hpp index 05048516..c14856d1 100644 --- a/sprout/darkroom/lights/parallel_light.hpp +++ b/sprout/darkroom/lights/parallel_light.hpp @@ -32,11 +32,8 @@ namespace sprout { color_type col_; private: template - SPROUT_CONSTEXPR color_type shade_2( - Intersection const& inter, - unit_type const& intensity - ) const - { + SPROUT_CONSTEXPR color_type + shade_2(Intersection const& inter, unit_type const& intensity) const { return sprout::darkroom::colors::mul( sprout::darkroom::colors::filter( col_, @@ -46,11 +43,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR color_type shade_1( - Intersection const& inter, - LightRayIntersection const& light_ray_inter - ) const - { + SPROUT_CONSTEXPR color_type + shade_1(Intersection const& inter, LightRayIntersection const& light_ray_inter) const { return shade_2( inter, !sprout::darkroom::intersects::does_intersect(light_ray_inter) @@ -67,15 +61,13 @@ namespace sprout { ); } public: - SPROUT_CONSTEXPR basic_parallel_light( - position_type const& dir, - color_type const& col - ) + SPROUT_CONSTEXPR basic_parallel_light(position_type const& dir, color_type const& col) : dir_(sprout::darkroom::coords::normalize(dir)) , col_(col) {} template - SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const { + SPROUT_CONSTEXPR color_type + operator()(Intersection const& inter, Objects const& objs) const { return shade_1( inter, sprout::darkroom::objects::intersect_list( diff --git a/sprout/darkroom/lights/point_light.hpp b/sprout/darkroom/lights/point_light.hpp index 60dabb85..a6824ddb 100644 --- a/sprout/darkroom/lights/point_light.hpp +++ b/sprout/darkroom/lights/point_light.hpp @@ -32,11 +32,8 @@ namespace sprout { color_type col_; private: template - SPROUT_CONSTEXPR color_type shade_4( - Intersection const& inter, - unit_type const& intensity - ) const - { + SPROUT_CONSTEXPR color_type + shade_4(Intersection const& inter, unit_type const& intensity) const { return sprout::darkroom::colors::mul( sprout::darkroom::colors::filter( col_, @@ -46,10 +43,9 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR color_type shade_3( - Intersection const& inter, - position_type const& diff, - position_type const& direction, + SPROUT_CONSTEXPR color_type + shade_3( + Intersection const& inter, position_type const& diff, position_type const& direction, LightRayIntersection const& light_ray_inter ) const { @@ -72,13 +68,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR color_type shade_2( - Intersection const& inter, - Objects const& objs, - position_type const& diff, - position_type const& direction - ) const - { + SPROUT_CONSTEXPR color_type + shade_2(Intersection const& inter, Objects const& objs, position_type const& diff, position_type const& direction) const { return shade_3( inter, diff, @@ -99,12 +90,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR color_type shade_1( - Intersection const& inter, - Objects const& objs, - position_type const& diff - ) const - { + SPROUT_CONSTEXPR color_type + shade_1(Intersection const& inter, Objects const& objs, position_type const& diff) const { return shade_2( inter, objs, @@ -113,15 +100,13 @@ namespace sprout { ); } public: - SPROUT_CONSTEXPR basic_point_light( - position_type const& pos, - color_type const& col - ) + SPROUT_CONSTEXPR basic_point_light(position_type const& pos, color_type const& col) : pos_(pos) , col_(col) {} template - SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const { + SPROUT_CONSTEXPR color_type + operator()(Intersection const& inter, Objects const& objs) const { return shade_1( inter, objs, diff --git a/sprout/darkroom/materials/interpolation.hpp b/sprout/darkroom/materials/interpolation.hpp index 81715bcf..e70d34dd 100644 --- a/sprout/darkroom/materials/interpolation.hpp +++ b/sprout/darkroom/materials/interpolation.hpp @@ -24,7 +24,8 @@ namespace sprout { // bilinear_interpolate // template - inline SPROUT_CONSTEXPR Color bilinear_interpolate( + inline SPROUT_CONSTEXPR Color + bilinear_interpolate( Color const& c00, Color const& c01, Color const& c10, Color const& c11, Unit const& u, Unit const& v ) diff --git a/sprout/darkroom/materials/material.hpp b/sprout/darkroom/materials/material.hpp index f9080936..fc3f0b14 100644 --- a/sprout/darkroom/materials/material.hpp +++ b/sprout/darkroom/materials/material.hpp @@ -15,16 +15,18 @@ namespace sprout { // reflection // template - inline SPROUT_CONSTEXPR auto color(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + color(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) { return sprout::darkroom::access::get<0>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto reflection(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + reflection(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) { return sprout::darkroom::access::get<1>(sprout::forward(t)); } @@ -34,14 +36,18 @@ namespace sprout { // calc_reflection // template - inline SPROUT_CONSTEXPR auto calc_color(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT - -> decltype(sprout::forward(t).template operator()(u, v)) + inline SPROUT_CONSTEXPR auto + calc_color(Image&& t, Unit const& u, Unit const& v) + SPROUT_NOEXCEPT + -> decltype(sprout::forward(t).template operator()(u, v)) { return sprout::forward(t).template operator()(u, v); } template - inline SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT - -> decltype(sprout::forward(t).template operator()(u, v)) + inline SPROUT_CONSTEXPR auto + calc_reflection(Image&& t, Unit const& u, Unit const& v) + SPROUT_NOEXCEPT + -> decltype(sprout::forward(t).template operator()(u, v)) { return sprout::forward(t).template operator()(u, v); } @@ -50,11 +56,12 @@ namespace sprout { // calc_material // template - inline SPROUT_CONSTEXPR auto calc_material(Material const& mat, Unit const& u, Unit const& v) - -> decltype(sprout::tuples::make_tuple( - sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v), - sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v) - )) + inline SPROUT_CONSTEXPR auto + calc_material(Material const& mat, Unit const& u, Unit const& v) + -> decltype(sprout::tuples::make_tuple( + sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v), + sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v) + )) { return sprout::tuples::make_tuple( sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v), diff --git a/sprout/darkroom/materials/plaid.hpp b/sprout/darkroom/materials/plaid.hpp index 208c490e..754cbfdd 100644 --- a/sprout/darkroom/materials/plaid.hpp +++ b/sprout/darkroom/materials/plaid.hpp @@ -17,7 +17,8 @@ namespace sprout { typedef Element result_type; typedef Scale unit_type; private: - static SPROUT_CONSTEXPR unit_type fmod(unit_type const& n, unit_type const& d) { + static SPROUT_CONSTEXPR unit_type + fmod(unit_type const& n, unit_type const& d) { return n - std::intmax_t(n / d) * d; } private: @@ -26,24 +27,19 @@ namespace sprout { unit_type scale_; private: template - SPROUT_CONSTEXPR result_type calc_1(Unit const& u, Unit const& v) const { - return (u >= 0 && v >= 0) || (u < 0 && v < 0) - ? elem1_ - : elem2_ - ; + SPROUT_CONSTEXPR result_type + calc_1(Unit const& u, Unit const& v) const { + return (u >= 0 && v >= 0) || (u < 0 && v < 0) ? elem1_ : elem2_; } public: - SPROUT_CONSTEXPR plaid_element( - result_type const& elem1, - result_type const& elem2, - unit_type const& scale = 1 - ) + SPROUT_CONSTEXPR plaid_element(result_type const& elem1, result_type const& elem2, unit_type const& scale = 1) : elem1_(elem1) , elem2_(elem2) , scale_(scale) {} template - SPROUT_CONSTEXPR result_type operator()(Unit const& u, Unit const& v) const { + SPROUT_CONSTEXPR result_type + operator()(Unit const& u, Unit const& v) const { return calc_1( (u < 0 ? scale_ + fmod(u, scale_) @@ -79,11 +75,10 @@ namespace sprout { inline SPROUT_CONSTEXPR sprout::tuples::tuple< sprout::darkroom::materials::plaid_element, sprout::darkroom::materials::plaid_element - > make_plaid_material_image( - Color const& col1, - Color const& col2, - Reflection const& ref1, - Reflection const& ref2 + > + make_plaid_material_image( + Color const& col1, Color const& col2, + Reflection const& ref1, Reflection const& ref2 ) { return sprout::tuples::make_tuple( @@ -95,11 +90,10 @@ namespace sprout { inline SPROUT_CONSTEXPR sprout::tuples::tuple< sprout::darkroom::materials::plaid_element, sprout::darkroom::materials::plaid_element - > make_plaid_material_image( - Color const& col1, - Color const& col2, - Reflection const& ref1, - Reflection const& ref2, + > + make_plaid_material_image( + Color const& col1, Color const& col2, + Reflection const& ref1, Reflection const& ref2, Unit const& scale ) { diff --git a/sprout/darkroom/materials/texture_map.hpp b/sprout/darkroom/materials/texture_map.hpp index 342e27c4..6c4088a8 100644 --- a/sprout/darkroom/materials/texture_map.hpp +++ b/sprout/darkroom/materials/texture_map.hpp @@ -45,22 +45,28 @@ namespace sprout { interpolation_type::values interpolation_value_; texture_map_placement::values placement_value_; private: - SPROUT_CONSTEXPR bool is_nearest() const { + SPROUT_CONSTEXPR bool + is_nearest() const { return interpolation_value_ == interpolation_type::nearest_neighbor; } - SPROUT_CONSTEXPR bool is_bilinear() const { + SPROUT_CONSTEXPR bool + is_bilinear() const { return interpolation_value_ == interpolation_type::bilinear; } - SPROUT_CONSTEXPR bool is_bicubic() const { + SPROUT_CONSTEXPR bool + is_bicubic() const { return interpolation_value_ == interpolation_type::bicubic; } - SPROUT_CONSTEXPR bool is_tile() const { + SPROUT_CONSTEXPR bool + is_tile() const { return placement_value_ == texture_map_placement::tile; } - SPROUT_CONSTEXPR bool is_once() const { + SPROUT_CONSTEXPR bool + is_once() const { return placement_value_ == texture_map_placement::once; } - SPROUT_CONSTEXPR result_type get_color(unit_type const& x, unit_type const& y) const { + SPROUT_CONSTEXPR result_type + get_color(unit_type const& x, unit_type const& y) const { return is_tile() ? texture_.get()( x < 0 @@ -78,11 +84,13 @@ namespace sprout { ; } template - SPROUT_CONSTEXPR result_type calc_nearest(Unit const& x, Unit const& y) const { + SPROUT_CONSTEXPR result_type + calc_nearest(Unit const& x, Unit const& y) const { return get_color(x, y); } template - SPROUT_CONSTEXPR result_type calc_bilinear_1( + SPROUT_CONSTEXPR result_type + calc_bilinear_1( Unit const& x, Unit const& x0, Unit const& y, Unit const& y0 ) const @@ -94,24 +102,24 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR result_type calc_bilinear(Unit const& x, Unit const& y) const { + SPROUT_CONSTEXPR result_type + calc_bilinear(Unit const& x, Unit const& y) const { return calc_bilinear_1( x, sprout::floor(x), y, sprout::floor(y) ); } template - SPROUT_CONSTEXPR result_type calc(Unit const& x, Unit const& y) const { + SPROUT_CONSTEXPR result_type + calc(Unit const& x, Unit const& y) const { return is_nearest() ? calc_nearest(x, y) : calc_bilinear(x, y) ; } public: explicit SPROUT_CONSTEXPR texture_map( - texture_type const& texture, - unit_type const& scale = 1, - unit_type const& offset_u = 0, - unit_type const& offset_v = 0, + texture_type const& texture, unit_type const& scale = 1, + unit_type const& offset_u = 0, unit_type const& offset_v = 0, result_type const& default_color = result_type(), interpolation_type::values interpolation_value = interpolation_type::nearest_neighbor, texture_map_placement::values placement_value = texture_map_placement::tile @@ -125,7 +133,8 @@ namespace sprout { , placement_value_(placement_value) {} template - SPROUT_CONSTEXPR result_type operator()(Unit const& u, Unit const& v) const { + SPROUT_CONSTEXPR result_type + operator()(Unit const& u, Unit const& v) const { return calc( (u - offset_u_ + scale_ / 2) / scale_ * texture_.get().width(), (-(v - offset_v_) + scale_ / 2) / scale_ * texture_.get().height() @@ -143,10 +152,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::darkroom::materials::texture_map make_texture_map( - Texture const& texture, - Unit const& scale, - Unit const& offset_u = 0, - Unit const& offset_v = 0, + Texture const& texture, Unit const& scale, + Unit const& offset_u = 0, Unit const& offset_v = 0, typename sprout::darkroom::materials::texture_map::result_type const& default_color = typename sprout::darkroom::materials::texture_map::result_typ() , diff --git a/sprout/darkroom/materials/uniform.hpp b/sprout/darkroom/materials/uniform.hpp index b9dfc2b5..58248b5b 100644 --- a/sprout/darkroom/materials/uniform.hpp +++ b/sprout/darkroom/materials/uniform.hpp @@ -21,7 +21,8 @@ namespace sprout { : elem_(elem) {} template - SPROUT_CONSTEXPR result_type operator()(Unit const&, Unit const&) const { + SPROUT_CONSTEXPR result_type + operator()(Unit const&, Unit const&) const { return elem_; } }; @@ -40,7 +41,8 @@ namespace sprout { inline SPROUT_CONSTEXPR sprout::tuples::tuple< sprout::darkroom::materials::uniform_element, sprout::darkroom::materials::uniform_element - > make_uniform_material_image(Color const& col, Reflection const& ref) { + > + make_uniform_material_image(Color const& col, Reflection const& ref) { return sprout::tuples::make_tuple( sprout::darkroom::materials::make_uniform(col), sprout::darkroom::materials::make_uniform(ref) diff --git a/sprout/darkroom/objects/aa_plane.hpp b/sprout/darkroom/objects/aa_plane.hpp index cece39ae..d2d7dbb5 100644 --- a/sprout/darkroom/objects/aa_plane.hpp +++ b/sprout/darkroom/objects/aa_plane.hpp @@ -54,23 +54,21 @@ namespace sprout { unit_type val_; material_type mat_; private: - SPROUT_CONSTEXPR bool is_x() const { + SPROUT_CONSTEXPR bool + is_x() const { return direction_value_ == aa_plane_direction::x; } - SPROUT_CONSTEXPR bool is_y() const { + SPROUT_CONSTEXPR bool + is_y() const { return direction_value_ == aa_plane_direction::y; } - SPROUT_CONSTEXPR bool is_z() const { + SPROUT_CONSTEXPR bool + is_z() const { return direction_value_ == aa_plane_direction::z; } template - SPROUT_CONSTEXPR typename intersection::type intersect_5( - int hit_side, - bool does_intersect, - unit_type distance, - position_type const& point_of_intersection - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_5(int hit_side, bool does_intersect, unit_type distance, position_type const& point_of_intersection) const { return typename intersection::type( does_intersect, distance, @@ -97,13 +95,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_4( - Ray const& ray, - int hit_side, - bool does_intersect, - unit_type distance - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_4(Ray const& ray, int hit_side, bool does_intersect, unit_type distance) const { return intersect_5( hit_side, does_intersect, @@ -114,14 +107,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_3( - Ray const& ray, - unit_type pos_v, - unit_type dir_v, - int hit_side, - bool does_intersect - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_3(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side, bool does_intersect) const { return intersect_4( ray, hit_side, @@ -132,13 +119,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_2( - Ray const& ray, - unit_type pos_v, - unit_type dir_v, - int hit_side - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_2(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side) const { return intersect_3( ray, pos_v, @@ -148,12 +130,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_1( - Ray const& ray, - unit_type pos_v, - unit_type dir_v - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_1(Ray const& ray, unit_type pos_v, unit_type dir_v) const { return intersect_2( ray, pos_v, @@ -162,17 +140,14 @@ namespace sprout { ); } public: - SPROUT_CONSTEXPR basic_aa_plane( - aa_plane_direction::values direction_value, - unit_type val, - material_type const& mat - ) + SPROUT_CONSTEXPR basic_aa_plane(aa_plane_direction::values direction_value, unit_type val, material_type const& mat) : direction_value_(direction_value) , val_(val) , mat_(mat) {} template - SPROUT_CONSTEXPR typename intersection::type intersect(Ray const& ray) const { + SPROUT_CONSTEXPR typename intersection::type + intersect(Ray const& ray) const { return intersect_1( ray, (is_x() ? sprout::darkroom::coords::x(sprout::darkroom::rays::position(ray)) @@ -191,12 +166,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR sprout::darkroom::objects::basic_aa_plane - make_aa_plane( - sprout::darkroom::objects::aa_plane_direction::values dir_val, - Unit const& val, - Material const& mat - ) - { + make_aa_plane(sprout::darkroom::objects::aa_plane_direction::values dir_val, Unit const& val, Material const& mat) { return sprout::darkroom::objects::basic_aa_plane(dir_val, val, mat); } } // namespace objects diff --git a/sprout/darkroom/objects/intersect.hpp b/sprout/darkroom/objects/intersect.hpp index 781d3144..4be87283 100644 --- a/sprout/darkroom/objects/intersect.hpp +++ b/sprout/darkroom/objects/intersect.hpp @@ -26,8 +26,7 @@ namespace sprout { struct intersect_list_impl { private: template - SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type - ::template intersection::type + SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type comp(A const& a, B const& b) const { return sprout::darkroom::intersects::does_intersect(a) && sprout::darkroom::intersects::does_intersect(b) @@ -41,8 +40,7 @@ namespace sprout { } public: template - SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type - ::template intersection::type + SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type ::template intersection::type operator()(Objects const& objs, Ray const& ray) const { return comp( sprout::darkroom::objects::intersect(sprout::darkroom::access::get(objs), ray), @@ -54,16 +52,14 @@ namespace sprout { struct intersect_list_impl<0> { public: template - SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type - ::template intersection::type + SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type operator()(Objects const& objs, Ray const& ray) const { return sprout::darkroom::objects::intersect(sprout::darkroom::access::get<0>(objs), ray); } }; } // namespace detail template - inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type - ::template intersection::type + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type intersect_list(Objects const& objs, Ray const& ray) { return sprout::darkroom::objects::detail::intersect_list_impl< sprout::darkroom::access::size::value - 1 diff --git a/sprout/darkroom/objects/polygon/triangle.hpp b/sprout/darkroom/objects/polygon/triangle.hpp index 30645add..b0990a76 100644 --- a/sprout/darkroom/objects/polygon/triangle.hpp +++ b/sprout/darkroom/objects/polygon/triangle.hpp @@ -45,7 +45,8 @@ namespace sprout { position_type normal_; private: template - SPROUT_CONSTEXPR bool within_test(Vector const& d0, Vector const& d1) { + SPROUT_CONSTEXPR bool + within_test(Vector const& d0, Vector const& d1) { return sprout::darkroom::coords::dot( sprout::darkroom::coords::cross(d0, d1), normal_ @@ -54,13 +55,8 @@ namespace sprout { ; } template - SPROUT_CONSTEXPR typename intersection::type intersect_5( - Ray const& ray, - int hit_side, - bool does_intersect, - unit_type distance - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_5(Ray const& ray, int hit_side, bool does_intersect, unit_type distance) const { return typename intersection::type( does_intersect, distance, @@ -73,13 +69,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_4( - Ray const& ray, - position_type const& v, - int hit_side, - bool does_intersect - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_4(Ray const& ray, position_type const& v, int hit_side, bool does_intersect) const { return intersect_5( ray, hit_side, @@ -90,14 +81,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_3( - Ray const& ray, - position_type const& v, - position_type const& p, - int hit_side, - bool exist_forward - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_3(Ray const& ray, position_type const& v, position_type const& p, int hit_side, bool exist_forward) const { return intersect_4( ray, v, @@ -118,12 +103,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_2( - Ray const& ray, - unit_type const& t, - int hit_side - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_2(Ray const& ray, unit_type const& t, int hit_side) const { return intersect_3( ray, sprout::darkroom::coords::scale(sprout::darkroom::rays::direction(ray), t), @@ -138,12 +119,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_1( - Ray const& ray, - unit_type const& xpn, - unit_type const& vn - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_1(Ray const& ray, unit_type const& xpn, unit_type const& vn) const { return intersect_2( ray, xpn / vn, @@ -151,12 +128,7 @@ namespace sprout { ); } public: - SPROUT_CONSTEXPR basic_triangle( - material_type const& mat, - position_type const& v0, - position_type const& v1, - position_type const& v2 - ) + SPROUT_CONSTEXPR basic_triangle(material_type const& mat, position_type const& v0, position_type const& v1, position_type const& v2) : mat_(mat) , vertices_{{v0, v1, v2}} , normal_( @@ -169,7 +141,8 @@ namespace sprout { ) {} template - SPROUT_CONSTEXPR typename intersection::type intersect(Ray const& ray) const { + SPROUT_CONSTEXPR typename intersection::type + intersect(Ray const& ray) const { return intersect_1( ray, sprout::darkroom::coords::dot( @@ -188,13 +161,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR sprout::darkroom::objects::basic_triangle - make_triangle( - Material const& mat, - Vertex const& v0, - Vertex const& v1, - Vertex const& v2 - ) - { + make_triangle(Material const& mat, Vertex const& v0, Vertex const& v1, Vertex const& v2) { return sprout::darkroom::objects::basic_triangle(mat, v0, v1, v2); } } // namespace objects diff --git a/sprout/darkroom/objects/sphere.hpp b/sprout/darkroom/objects/sphere.hpp index 8f9d148c..c1c38d6b 100644 --- a/sprout/darkroom/objects/sphere.hpp +++ b/sprout/darkroom/objects/sphere.hpp @@ -60,14 +60,8 @@ namespace sprout { material_type mat_; private: template - SPROUT_CONSTEXPR zwo_type zweitens_2( - Ray const& ray, - unit_type const& i1, - unit_type const& i2, - int hit_side, - bool does_intersect - ) const - { + SPROUT_CONSTEXPR zwo_type + zweitens_2(Ray const& ray, unit_type const& i1, unit_type const& i2, int hit_side, bool does_intersect) const { return zwo_type( hit_side, does_intersect, @@ -77,12 +71,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR zwo_type zweitens_1( - Ray const& ray, - unit_type const& i1, - unit_type const& i2 - ) const - { + SPROUT_CONSTEXPR zwo_type + zweitens_1(Ray const& ray, unit_type const& i1, unit_type const& i2) const { return zweitens_2( ray, i1, @@ -95,24 +85,16 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR zwo_type zweitens( - Ray const& ray, - bool neg, - unit_type const& b, - unit_type const& det - ) const - { + SPROUT_CONSTEXPR zwo_type + zweitens(Ray const& ray, bool neg, unit_type const& b, unit_type const& det) const { return neg ? zweitens_1(ray, b - det, b + det) : zwo_type(0, false, -1) ; } template - SPROUT_CONSTEXPR drei_type drittens_1( - Ray const& ray, - typename sprout::darkroom::access::unit::type point_of_intersection - ) const - { + SPROUT_CONSTEXPR drei_type + drittens_1(Ray const& ray, typename sprout::darkroom::access::unit::type point_of_intersection) const { return drei_type( point_of_intersection, sprout::darkroom::coords::normalize( @@ -121,12 +103,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR drei_type drittens( - Ray const& ray, - bool neg, - unit_type const& distance - ) const - { + SPROUT_CONSTEXPR drei_type + drittens(Ray const& ray, bool neg, unit_type const& distance) const { return neg ? drittens_1(ray, sprout::darkroom::rays::point_of_intersection(ray, distance)) : drei_type( @@ -136,13 +114,8 @@ namespace sprout { ; } template - SPROUT_CONSTEXPR typename intersection::type intersect_6( - Ray const& ray, - zwo_type const& zwo, - drei_type const& drei, - Vec const& normal - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_6(Ray const& ray, zwo_type const& zwo, drei_type const& drei, Vec const& normal) const { return typename intersection::type( sprout::tuples::get(zwo), sprout::tuples::get(zwo), @@ -168,12 +141,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_5( - Ray const& ray, - zwo_type const& zwo, - drei_type const& drei - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_5(Ray const& ray, zwo_type const& zwo, drei_type const& drei) const { return intersect_6( ray, zwo, @@ -182,11 +151,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_4( - Ray const& ray, - zwo_type const& zwo - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_4(Ray const& ray, zwo_type const& zwo) const { return intersect_5( ray, zwo, @@ -198,12 +164,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_3( - Ray const& ray, - unit_type const& b, - unit_type const& det_sq - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_3(Ray const& ray, unit_type const& b, unit_type const& det_sq) const { return intersect_4( ray, zweitens( @@ -215,12 +177,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_2( - Ray const& ray, - position_type const& v, - unit_type const& b - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_2(Ray const& ray, position_type const& v, unit_type const& b) const { return intersect_3( ray, b, @@ -228,11 +186,8 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR typename intersection::type intersect_1( - Ray const& ray, - position_type const& v - ) const - { + SPROUT_CONSTEXPR typename intersection::type + intersect_1(Ray const& ray, position_type const& v) const { return intersect_2( ray, v, @@ -240,17 +195,14 @@ namespace sprout { ); } public: - SPROUT_CONSTEXPR basic_sphere( - position_type const& pos, - radius_type rad, - material_type const& mat - ) + SPROUT_CONSTEXPR basic_sphere(position_type const& pos, radius_type rad, material_type const& mat) : pos_(pos) , rad_(rad) , mat_(mat) {} template - SPROUT_CONSTEXPR typename intersection::type intersect(Ray const& ray) const { + SPROUT_CONSTEXPR typename intersection::type + intersect(Ray const& ray) const { return intersect_1( ray, sprout::darkroom::coords::sub(sprout::darkroom::rays::position(ray), pos_) diff --git a/sprout/darkroom/pixels/generate.hpp b/sprout/darkroom/pixels/generate.hpp index d264a0f1..be0960d6 100644 --- a/sprout/darkroom/pixels/generate.hpp +++ b/sprout/darkroom/pixels/generate.hpp @@ -18,20 +18,14 @@ namespace sprout { namespace detail { template< typename Pixels, - typename RayTracer, - typename Renderer, - typename Camera, - typename Objects, - typename Lights, + typename RayTracer, typename Renderer, typename Camera, + typename Objects, typename Lights, sprout::index_t... XIndexes > inline SPROUT_CONSTEXPR typename sprout::container_traits::value_type generate_impl_line( - RayTracer const& raytracer, - Renderer const& renderer, - Camera const& camera, - Objects const& objs, - Lights const& lights, + RayTracer const& raytracer, Renderer const& renderer, Camera const& camera, + Objects const& objs, Lights const& lights, typename sprout::container_traits< typename sprout::container_traits::value_type >::size_type x @@ -51,35 +45,22 @@ namespace sprout { return sprout::make( sprout::darkroom::colors::rgb_f_to_rgb( raytracer.template operator()( - renderer, - camera, - objs, - lights, - x + XIndexes, - y, - width, - height, - depth_max + renderer, camera, objs, lights, + x + XIndexes, y, width, height, depth_max ) )... ); } template< typename Pixels, - typename RayTracer, - typename Renderer, - typename Camera, - typename Objects, - typename Lights, + typename RayTracer, typename Renderer, typename Camera, + typename Objects, typename Lights, sprout::index_t... YIndexes > inline SPROUT_CONSTEXPR Pixels generate_impl( - RayTracer const& raytracer, - Renderer const& renderer, - Camera const& camera, - Objects const& objs, - Lights const& lights, + RayTracer const& raytracer, Renderer const& renderer, Camera const& camera, + Objects const& objs, Lights const& lights, typename sprout::container_traits< typename sprout::container_traits::value_type >::size_type x @@ -96,16 +77,8 @@ namespace sprout { { return sprout::make( sprout::darkroom::pixels::detail::generate_impl_line( - raytracer, - renderer, - camera, - objs, - lights, - x, - y + YIndexes, - width, - height, - depth_max, + raytracer, renderer, camera, objs, lights, + x, y + YIndexes, width, height, depth_max, sprout::index_range< 0, sprout::container_traits< @@ -118,18 +91,12 @@ namespace sprout { } // namespace detail template< typename Pixels, - typename RayTracer, - typename Renderer, - typename Camera, - typename Objects, - typename Lights + typename RayTracer, typename Renderer, typename Camera, + typename Objects, typename Lights > inline SPROUT_CONSTEXPR Pixels generate( - RayTracer const& raytracer, - Renderer const& renderer, - Camera const& camera, - Objects const& objs, - Lights const& lights, + RayTracer const& raytracer, Renderer const& renderer, Camera const& camera, + Objects const& objs, Lights const& lights, typename sprout::container_traits< typename sprout::container_traits::value_type >::size_type x @@ -152,16 +119,8 @@ namespace sprout { ) { return sprout::darkroom::pixels::detail::generate_impl( - raytracer, - renderer, - camera, - objs, - lights, - x, - y, - width, - height, - depth_max, + raytracer, renderer, camera, objs, lights, + x, y, width, height, depth_max, sprout::index_range< 0, sprout::container_traits::static_size @@ -175,10 +134,7 @@ namespace sprout { template struct color_pixels { public: - typedef sprout::array< - sprout::array, - Height - > type; + typedef sprout::array, Height> type; }; } // namespace pixels } // namespace darkroom diff --git a/sprout/darkroom/rays/ray.hpp b/sprout/darkroom/rays/ray.hpp index ad7f0956..a48c803a 100644 --- a/sprout/darkroom/rays/ray.hpp +++ b/sprout/darkroom/rays/ray.hpp @@ -15,16 +15,18 @@ namespace sprout { // direction // template - inline SPROUT_CONSTEXPR auto position(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + position(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) { return sprout::darkroom::access::get<0>(sprout::forward(t)); } template - inline SPROUT_CONSTEXPR auto direction(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) - -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + inline SPROUT_CONSTEXPR auto + direction(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) { return sprout::darkroom::access::get<1>(sprout::forward(t)); } diff --git a/sprout/darkroom/renderers/infinity.hpp b/sprout/darkroom/renderers/infinity.hpp index fc6ce33e..4ae087e6 100644 --- a/sprout/darkroom/renderers/infinity.hpp +++ b/sprout/darkroom/renderers/infinity.hpp @@ -13,7 +13,8 @@ namespace sprout { // normal_to_color // template - inline SPROUT_CONSTEXPR Color normal_to_color(Normal const& nor) { + inline SPROUT_CONSTEXPR Color + normal_to_color(Normal const& nor) { return sprout::tuples::make( 0.5 + sprout::darkroom::coords::x(nor) * 0.5, 0.5 + sprout::darkroom::coords::y(nor) * 0.5, @@ -27,7 +28,8 @@ namespace sprout { class direction_gradation { public: template - SPROUT_CONSTEXPR TargetColor operator()(Vector const& dir) const { + SPROUT_CONSTEXPR TargetColor + operator()(Vector const& dir) const { return sprout::darkroom::renderers::normal_to_color(dir); } }; @@ -57,7 +59,8 @@ namespace sprout { : color_(color) {} template - SPROUT_CONSTEXPR TargetColor operator()(Vector const&) const { + SPROUT_CONSTEXPR TargetColor + operator()(Vector const&) const { return color_; } }; diff --git a/sprout/darkroom/renderers/whitted_style.hpp b/sprout/darkroom/renderers/whitted_style.hpp index 5c0b2836..9cf748b9 100644 --- a/sprout/darkroom/renderers/whitted_style.hpp +++ b/sprout/darkroom/renderers/whitted_style.hpp @@ -25,29 +25,20 @@ namespace sprout { private: template< typename Color, - typename Camera, - typename Objects, - typename Lights, - typename Ray, - typename Intersection, - typename Tracer, + typename Camera, typename Objects, typename Lights, + typename Ray, typename Intersection, typename Tracer, typename Direction > - SPROUT_CONSTEXPR Color color_1( - Camera const& camera, - Objects const& objs, - Lights const& lights, - Ray const& ray, - Intersection const& inter, - Tracer const& tracer, + SPROUT_CONSTEXPR Color + color_1( + Camera const& camera, Objects const& objs, Lights const& lights, + Ray const& ray, Intersection const& inter, Tracer const& tracer, std::size_t depth_max, Direction const& reflect_dir ) const { return tracer.template operator()( - camera, - objs, - lights, + camera, objs, lights, sprout::tuples::remake( ray, sprout::darkroom::coords::add( @@ -70,20 +61,13 @@ namespace sprout { public: template< typename Color, - typename Camera, - typename Objects, - typename Lights, - typename Ray, - typename Intersection, - typename Tracer + typename Camera, typename Objects, typename Lights, + typename Ray, typename Intersection, typename Tracer > - SPROUT_CONSTEXPR Color operator()( - Camera const& camera, - Objects const& objs, - Lights const& lights, - Ray const& ray, - Intersection const& inter, - Tracer const& tracer, + SPROUT_CONSTEXPR Color + operator()( + Camera const& camera, Objects const& objs, Lights const& lights, + Ray const& ray, Intersection const& inter, Tracer const& tracer, std::size_t depth_max ) const { @@ -95,12 +79,8 @@ namespace sprout { && sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) > std::numeric_limits::epsilon() ? color_1( - camera, - objs, - lights, - ray, - inter, - tracer, + camera, objs, lights, + ray, inter, tracer, depth_max, sprout::darkroom::coords::reflect( sprout::darkroom::rays::direction(ray), @@ -121,16 +101,11 @@ namespace sprout { private: infinity_color_type infinity_color_; private: - template< - typename Color, - typename Ray, - typename Intersection - > - SPROUT_CONSTEXPR Color color_3( - Ray const& ray, - Intersection const& inter, - Color const& diffuse_color, - Color const& mirror_color + template + SPROUT_CONSTEXPR Color + color_3( + Ray const& ray, Intersection const& inter, + Color const& diffuse_color, Color const& mirror_color ) const { return sprout::darkroom::intersects::does_intersect(inter) @@ -149,61 +124,40 @@ namespace sprout { } template< typename Color, - typename Camera, - typename Objects, - typename Lights, - typename Ray, - typename Intersection + typename Camera, typename Objects, typename Lights, + typename Ray, typename Intersection > - SPROUT_CONSTEXPR Color color_2( - Camera const& camera, - Objects const& objs, - Lights const& lights, - Ray const& ray, - std::size_t depth_max, - Intersection const& inter, + SPROUT_CONSTEXPR Color + color_2( + Camera const& camera, Objects const& objs, Lights const& lights, + Ray const& ray, std::size_t depth_max, Intersection const& inter, Color const& diffuse_color ) const { return color_3( - ray, - inter, + ray, inter, diffuse_color, sprout::darkroom::renderers::whitted_mirror().template operator()( - camera, - objs, - lights, - ray, - inter, - *this, + camera, objs, lights, + ray, inter, *this, depth_max ) ); } template< typename Color, - typename Camera, - typename Objects, - typename Lights, - typename Ray, - typename Intersection + typename Camera, typename Objects, typename Lights, + typename Ray, typename Intersection > - SPROUT_CONSTEXPR Color color_1( - Camera const& camera, - Objects const& objs, - Lights const& lights, - Ray const& ray, - std::size_t depth_max, - Intersection const& inter + SPROUT_CONSTEXPR Color + color_1( + Camera const& camera, Objects const& objs, Lights const& lights, + Ray const& ray, std::size_t depth_max, Intersection const& inter ) const { return color_2( - camera, - objs, - lights, - ray, - depth_max, - inter, + camera, objs, lights, + ray, depth_max, inter, lights.template operator()(inter, objs) ); } @@ -215,27 +169,16 @@ namespace sprout { explicit SPROUT_CONSTEXPR whitted_style(infinity_color_type const& infinity_color) : infinity_color_(infinity_color) {} - template< - typename Color, - typename Camera, - typename Objects, - typename Lights, - typename Ray - > - SPROUT_CONSTEXPR Color operator()( - Camera const& camera, - Objects const& objs, - Lights const& lights, - Ray const& ray, - std::size_t depth_max + template + SPROUT_CONSTEXPR Color + operator()( + Camera const& camera, Objects const& objs, Lights const& lights, + Ray const& ray, std::size_t depth_max ) const { return color_1( - camera, - objs, - lights, - ray, - depth_max, + camera, objs, lights, + ray, depth_max, sprout::darkroom::objects::intersect_list(objs, ray) ); } diff --git a/sprout/darkroom/textures/texture.hpp b/sprout/darkroom/textures/texture.hpp index 85c153a8..a1653f8b 100644 --- a/sprout/darkroom/textures/texture.hpp +++ b/sprout/darkroom/textures/texture.hpp @@ -61,11 +61,7 @@ namespace sprout { pixels_type pixels_; public: template - SPROUT_CONSTEXPR image_type( - unsigned long image_format, - unsigned long pixel_format, - Elems const&... elems - ) + SPROUT_CONSTEXPR image_type(unsigned long image_format, unsigned long pixel_format, Elems const&... elems) : pixels_{{ color_type( static_cast((elems >> 16) & 0xFF) / 0xFF, @@ -76,16 +72,20 @@ namespace sprout { { static_assert(sizeof...(Elems) == static_width * static_height, "image_type<>: unmatch image size"); } - SPROUT_CONSTEXPR value_type const& operator()(size_type x, size_type y) const { + SPROUT_CONSTEXPR value_type const& + operator()(size_type x, size_type y) const { return pixels_[y * static_width + x]; } - SPROUT_CONSTEXPR size_type width() const { + SPROUT_CONSTEXPR size_type + width() const { return static_width; } - SPROUT_CONSTEXPR size_type height() const { + SPROUT_CONSTEXPR size_type + height() const { return static_height; } - SPROUT_CONSTEXPR pixels_type const& pixels() const { + SPROUT_CONSTEXPR pixels_type const& + pixels() const { return pixels_; } }; diff --git a/sprout/darkroom/tracers/raytracer.hpp b/sprout/darkroom/tracers/raytracer.hpp index c41a6cfd..5afafe80 100644 --- a/sprout/darkroom/tracers/raytracer.hpp +++ b/sprout/darkroom/tracers/raytracer.hpp @@ -16,29 +16,15 @@ namespace sprout { public: typedef Color color_type; public: - template< - typename Renderer, - typename Camera, - typename Objects, - typename Lights, - typename Unit2D - > + template SPROUT_CONSTEXPR color_type operator()( - Renderer const& renderer, - Camera const& camera, - Objects const& objs, - Lights const& lights, - Unit2D const& x, - Unit2D const& y, - Unit2D const& width, - Unit2D const& height, + Renderer const& renderer, Camera const& camera, Objects const& objs, Lights const& lights, + Unit2D const& x, Unit2D const& y, Unit2D const& width, Unit2D const& height, std::size_t depth_max = 8 ) const { return renderer.template operator()( - camera, - objs, - lights, + camera, objs, lights, camera.template operator()(x, y, width, height), depth_max ); diff --git a/sprout/detail/algorithm/count_n.hpp b/sprout/detail/algorithm/count_n.hpp index 57b893c7..60910216 100644 --- a/sprout/detail/algorithm/count_n.hpp +++ b/sprout/detail/algorithm/count_n.hpp @@ -11,12 +11,8 @@ namespace sprout { // count_n // template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type count_n( - InputIterator first, - Size n, - T const& value - ) - { + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + count_n(InputIterator first, Size n, T const& value) { return n == 0 ? 0 : (*first == value ? 1 : 0) + sprout::detail::count_n(sprout::next(first), n - 1, value) ; diff --git a/sprout/detail/algorithm/count_n_if.hpp b/sprout/detail/algorithm/count_n_if.hpp index 53b9f50a..a1e86469 100644 --- a/sprout/detail/algorithm/count_n_if.hpp +++ b/sprout/detail/algorithm/count_n_if.hpp @@ -11,12 +11,8 @@ namespace sprout { // count_n_if // template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type count_n_if( - InputIterator first, - Size n, - Predicate pred - ) - { + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + count_n_if(InputIterator first, Size n, Predicate pred) { return n == 0 ? 0 : (pred(*first) ? 1 : 0) + sprout::detail::count_n_if(sprout::next(first), n - 1, pred) ; diff --git a/sprout/detail/algorithm/overlap_count.hpp b/sprout/detail/algorithm/overlap_count.hpp index 582f8f0c..58e16269 100644 --- a/sprout/detail/algorithm/overlap_count.hpp +++ b/sprout/detail/algorithm/overlap_count.hpp @@ -8,17 +8,15 @@ namespace sprout { namespace detail { template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type overlap_count_impl( - InputIterator first, - InputIterator last, + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + overlap_count_impl( + InputIterator first, InputIterator last, typename std::iterator_traits::value_type const& value, typename std::iterator_traits::difference_type current = 0 ) { - return first == last - ? 0 - : *first == value - ? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, value) + return first == last ? 0 + : *first == value ? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, value) : sprout::detail::overlap_count_impl(sprout::next(first), last, *first) ; } @@ -26,29 +24,22 @@ namespace sprout { // overlap_count // template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type overlap_count( - InputIterator first, - InputIterator last - ) - { - return first == last - ? 0 + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + overlap_count(InputIterator first, InputIterator last) { + return first == last ? 0 : sprout::detail::overlap_count_impl(sprout::next(first), last, *first) ; } template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type overlap_count_impl( - InputIterator first, - InputIterator last, - Predicate pred, - typename std::iterator_traits::value_type const& value + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + overlap_count_impl( + InputIterator first, InputIterator last, + Predicate pred, typename std::iterator_traits::value_type const& value ) { - return first == last - ? 0 - : pred(*first, value) - ? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, pred, value) + return first == last ? 0 + : pred(*first, value) ? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, pred, value) : sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first) ; } @@ -56,14 +47,9 @@ namespace sprout { // overlap_count // template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type overlap_count( - InputIterator first, - InputIterator last, - Predicate pred - ) - { - return first == last - ? 0 + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + overlap_count(InputIterator first, InputIterator last, Predicate pred) { + return first == last ? 0 : sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first) ; } diff --git a/sprout/detail/algorithm/set_overlap_count.hpp b/sprout/detail/algorithm/set_overlap_count.hpp index bbe77d87..3c731902 100644 --- a/sprout/detail/algorithm/set_overlap_count.hpp +++ b/sprout/detail/algorithm/set_overlap_count.hpp @@ -11,11 +11,10 @@ namespace sprout { // set_overlap_count // template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type set_overlap_count( - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + set_overlap_count( + InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, Compare comp ) { @@ -32,11 +31,10 @@ namespace sprout { // set_overlap_count // template - inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type set_overlap_count( - InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2 + inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + set_overlap_count( + InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2 ) { return first1 != last1 && first2 != last2 diff --git a/sprout/detail/char_conversion.hpp b/sprout/detail/char_conversion.hpp index fe1bcce4..3428de97 100644 --- a/sprout/detail/char_conversion.hpp +++ b/sprout/detail/char_conversion.hpp @@ -9,21 +9,24 @@ namespace sprout { namespace detail { template - inline SPROUT_CONSTEXPR Elem int_to_char(IntType val, int base){ + inline SPROUT_CONSTEXPR Elem + int_to_char(IntType val, int base) { return val >= 0 && val < 10 ? static_cast('0') + val : val >= 10 && val < static_cast(base) ? static_cast('a') + (val - 10) : throw std::invalid_argument("value out of bounds") ; } template - inline SPROUT_CONSTEXPR Elem int_to_char(IntType val){ + inline SPROUT_CONSTEXPR Elem + int_to_char(IntType val) { return val >= 0 && val < 10 ? static_cast('0') + val : throw std::invalid_argument("value out of bounds") ; } template - inline SPROUT_CONSTEXPR IntType char_to_int(Elem c, int base){ + inline SPROUT_CONSTEXPR IntType + char_to_int(Elem c, int base) { return sprout::ascii::isdigit(c) && c - static_cast('0') < base ? c - static_cast('0') : sprout::ascii::islower(c) && c - static_cast('a') + 10 < base ? c - static_cast('a') + 10 : sprout::ascii::isupper(c) && c - static_cast('A') + 10 < base ? c - static_cast('A') + 10 @@ -31,7 +34,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR IntType char_to_int(Elem c){ + inline SPROUT_CONSTEXPR IntType + char_to_int(Elem c) { return sprout::ascii::isdigit(c) ? c - static_cast('0') : static_cast(-1) ; diff --git a/sprout/detail/container_complate.hpp b/sprout/detail/container_complate.hpp index 6a065ecd..c6ec0385 100644 --- a/sprout/detail/container_complate.hpp +++ b/sprout/detail/container_complate.hpp @@ -14,29 +14,24 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_2( - Result const& result, - Args const&... args - ) - { + >::type + container_complate_2(Result const& result, Args const&... args) { return sprout::remake(result, sprout::size(result), args...); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_2( - Result const& result, - Args const&... args - ) - { + >::type + container_complate_2(Result const& result, Args const&... args) { return container_complate_2(result, args..., *sprout::next(sprout::internal_begin(result), sizeof...(Args))); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_1( + >::type + container_complate_1( Result const& result, typename sprout::container_traits::difference_type remain, Args const&... args @@ -48,7 +43,8 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_1( + >::type + container_complate_1( Result const& result, typename sprout::container_traits::difference_type remain, Args const&... args @@ -63,22 +59,16 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate( - Result const& result, - Args const&... args - ) - { + >::type + container_complate(Result const& result, Args const&... args) { return sprout::remake(result, sprout::size(result), args...); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate( - Result const& result, - Args const&... args - ) - { + >::type + container_complate(Result const& result, Args const&... args) { return container_complate_1(result, sprout::internal_begin_offset(result), args...); } } // namespace detail diff --git a/sprout/detail/container_complate_backward.hpp b/sprout/detail/container_complate_backward.hpp index 629045d1..ee9332a0 100644 --- a/sprout/detail/container_complate_backward.hpp +++ b/sprout/detail/container_complate_backward.hpp @@ -14,29 +14,24 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_backward_2( - Result const& result, - Args const&... args - ) - { + >::type + container_complate_backward_2(Result const& result, Args const&... args) { return sprout::remake(result, sprout::size(result), args...); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_backward_2( - Result const& result, - Args const&... args - ) - { + >::type + container_complate_backward_2(Result const& result, Args const&... args) { return container_complate_backward_2(result, *sprout::prev(sprout::internal_end(result), sizeof...(Args) + 1), args...); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_backward_1( + >::type + container_complate_backward_1( Result const& result, typename sprout::container_traits::difference_type remain, Args const&... args @@ -48,7 +43,8 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_backward_1( + >::type + container_complate_backward_1( Result const& result, typename sprout::container_traits::difference_type remain, Args const&... args @@ -63,22 +59,16 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_backward( - Result const& result, - Args const&... args - ) - { + >::type + container_complate_backward(Result const& result, Args const&... args) { return sprout::remake(result, sprout::size(result), args...); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type - >::type container_complate_backward( - Result const& result, - Args const&... args - ) - { + >::type + container_complate_backward(Result const& result, Args const&... args) { return container_complate_backward_1(result, sprout::internal_end_offset_backward(result), args...); } } // namespace detail diff --git a/sprout/detail/integer/static_log2.hpp b/sprout/detail/integer/static_log2.hpp index 67923ab7..06fc2587 100644 --- a/sprout/detail/integer/static_log2.hpp +++ b/sprout/detail/integer/static_log2.hpp @@ -15,8 +15,12 @@ namespace sprout { template struct choose_initial_n { - SPROUT_STATIC_CONSTEXPR bool c = (sprout::detail::static_log2_impl::argument_type(1) << n << n) != 0; - SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_impl::result_type value = !c * n + choose_initial_n<2 * c * n>::value; + SPROUT_STATIC_CONSTEXPR bool c + = (sprout::detail::static_log2_impl::argument_type(1) << n << n) != 0 + ; + SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_impl::result_type value + = !c * n + choose_initial_n<2 * c * n>::value + ; }; template<> struct choose_initial_n<0> { @@ -24,7 +28,9 @@ namespace sprout { }; SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_impl::result_type n_zero = 16; - SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_impl::result_type initial_n = sprout::detail::static_log2_impl::choose_initial_n::value; + SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_impl::result_type initial_n + = sprout::detail::static_log2_impl::choose_initial_n::value + ; template< sprout::detail::static_log2_impl::argument_type x, @@ -32,7 +38,9 @@ namespace sprout { > struct static_log2_impl { SPROUT_STATIC_CONSTEXPR bool c = (x >> n) > 0; - SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_impl::result_type value = c * n + (static_log2_impl<(x >> c * n), n / 2>::value); + SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_impl::result_type value + = c * n + (static_log2_impl<(x >> c * n), n / 2>::value) + ; }; template<> struct static_log2_impl<1, 0> { @@ -42,7 +50,9 @@ namespace sprout { template struct static_log2 { - SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_result_type value = sprout::detail::static_log2_impl::static_log2_impl::value; + SPROUT_STATIC_CONSTEXPR sprout::detail::static_log2_result_type value + = sprout::detail::static_log2_impl::static_log2_impl::value + ; }; template<> struct static_log2<0> {}; diff --git a/sprout/detail/math/float.hpp b/sprout/detail/math/float.hpp index 8fcd9e3d..67984328 100644 --- a/sprout/detail/math/float.hpp +++ b/sprout/detail/math/float.hpp @@ -27,7 +27,10 @@ namespace sprout { : FloatType(1) ; } - template::value>::type = sprout::enabler> + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR FloatType float_pow10(int exponent) { return exponent < 0 @@ -53,7 +56,10 @@ namespace sprout { : 0 ; } - template::value>::type = sprout::enabler> + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR int float_exponent10(FloatType val) { return val < 0 @@ -69,7 +75,10 @@ namespace sprout { // // float_digits // - template::value>::type = sprout::enabler> + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR int float_digits_impl(FloatType val) { return val < 1 ? 0 @@ -88,7 +97,10 @@ namespace sprout { // // float_digit_at // - template::value>::type = sprout::enabler> + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR int float_digit_of_impl(FloatType val) { return static_cast((val - sprout::floor(val)) * 10); @@ -102,7 +114,10 @@ namespace sprout { // // float_round_at // - template::value>::type = sprout::enabler> + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR FloatType float_round_impl(FloatType val, FloatType p10) { return sprout::round(val * p10) / p10; diff --git a/sprout/detail/math/int.hpp b/sprout/detail/math/int.hpp index a2f4679d..48006c84 100644 --- a/sprout/detail/math/int.hpp +++ b/sprout/detail/math/int.hpp @@ -10,7 +10,10 @@ namespace sprout { // // int_pow // - template::value>::type = sprout::enabler> + template< + typename IntType, int Base = 10, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR IntType int_pow(int exponent) { return exponent ? Base * sprout::detail::int_pow(exponent - 1) @@ -28,7 +31,10 @@ namespace sprout { : 0 ; } - template::value>::type = sprout::enabler> + template< + int Base = 10, typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR int int_digits(IntType val) { return val ? 1 + sprout::detail::int_digits_impl(val / Base) @@ -39,7 +45,10 @@ namespace sprout { // // int_digit_at // - template::value>::type = sprout::enabler> + template< + int Base = 10, typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR int int_digit_at(IntType val, int digits) { return val < 0 ? -((val / sprout::detail::int_pow(digits)) % Base) diff --git a/sprout/detail/param_at.hpp b/sprout/detail/param_at.hpp index 65933db2..9eaf0eca 100644 --- a/sprout/detail/param_at.hpp +++ b/sprout/detail/param_at.hpp @@ -11,24 +11,16 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Values) == 0, R - >::type param_at( - std::size_t n, - T const& v, - Values const&... values - ) - { + >::type + param_at(std::size_t n, T const& v, Values const&... values) { return v; } template inline SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Values) != 0, R - >::type param_at( - std::size_t n, - T const& v, - Values const&... values - ) - { + >::type + param_at(std::size_t n, T const& v, Values const&... values) { return n == 0 ? v : sprout::detail::param_at(n - 1, values...); } @@ -36,26 +28,16 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Values) == 0, R - >::type param_seq_at( - std::size_t n, - std::size_t m, - T const& v, - Values const&... values - ) - { + >::type + param_seq_at(std::size_t n, std::size_t m, T const& v, Values const&... values) { return v[m]; } template inline SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Values) != 0, R - >::type param_seq_at( - std::size_t n, - std::size_t m, - T const& v, - Values const&... values - ) - { + >::type + param_seq_at(std::size_t n, std::size_t m, T const& v, Values const&... values) { return n == 0 ? v[m] : sprout::detail::param_seq_at(n - 1, m, values...); } } // namespace detail diff --git a/sprout/functional/bind/bind.hpp b/sprout/functional/bind/bind.hpp index e5e126fc..ff015b65 100644 --- a/sprout/functional/bind/bind.hpp +++ b/sprout/functional/bind/bind.hpp @@ -170,14 +170,14 @@ namespace sprout { sprout::tuples::tuple& tuple, sprout::index_tuple ) const volatile - -> decltype(arg(std::declval()...)) + -> decltype(arg(std::declval()...)) { return arg(sprout::forward(sprout::tuples::get(tuple))...); } public: template SPROUT_CONSTEXPR auto operator()(CVArg& arg, sprout::tuples::tuple& tuple) const volatile - -> decltype(arg(std::declval()...)) + -> decltype(arg(std::declval()...)) { return call(arg, tuple, sprout::index_range<0, sizeof...(Args)>::make()); } @@ -252,13 +252,13 @@ namespace sprout { template inline auto volget(sprout::tuples::tuple volatile& tuple) - -> typename sprout::tuples::tuple_element >::type volatile& + -> typename sprout::tuples::tuple_element >::type volatile& { return sprout::tuples::get(const_cast&>(tuple)); } template inline SPROUT_CONSTEXPR auto volget(sprout::tuples::tuple const volatile& tuple) - -> typename sprout::tuples::tuple_element >::type const volatile& + -> typename sprout::tuples::tuple_element >::type const volatile& { return sprout::tuples::get(const_cast const&>(tuple)); } diff --git a/sprout/generator/generated_value.hpp b/sprout/generator/generated_value.hpp index 914c42df..555f8e2a 100644 --- a/sprout/generator/generated_value.hpp +++ b/sprout/generator/generated_value.hpp @@ -171,7 +171,7 @@ namespace sprout_generator_detail { > inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type generated_value_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) { return generated_value(sprout::forward(t)); } @@ -181,7 +181,7 @@ namespace sprout_generator_detail { > inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type generated_value_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) { return sprout::forward(t).generated_value(); } @@ -191,7 +191,7 @@ namespace sprout_generator_detail { > inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type generated_value_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) { return get<0>(sprout::forward(t)); } @@ -205,7 +205,7 @@ namespace sprout { template inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type generated_value(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) { return sprout_generator_detail::generated_value_impl(sprout::forward(t)); } diff --git a/sprout/generator/next_generator.hpp b/sprout/generator/next_generator.hpp index 20801a9d..47932258 100644 --- a/sprout/generator/next_generator.hpp +++ b/sprout/generator/next_generator.hpp @@ -171,7 +171,7 @@ namespace sprout_generator_detail { > inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type next_generator_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) { return next_generator(sprout::forward(t)); } @@ -181,7 +181,7 @@ namespace sprout_generator_detail { > inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type next_generator_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) { return sprout::forward(t).next_generator(); } @@ -191,7 +191,7 @@ namespace sprout_generator_detail { > inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type next_generator_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) { return get<1>(sprout::forward(t)); } @@ -205,7 +205,7 @@ namespace sprout { template inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type next_generator(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) { return sprout_generator_detail::next_generator_impl(sprout::forward(t)); } diff --git a/sprout/index_tuple/make_indexes.hpp b/sprout/index_tuple/make_indexes.hpp index 9a74478d..21cd51c5 100644 --- a/sprout/index_tuple/make_indexes.hpp +++ b/sprout/index_tuple/make_indexes.hpp @@ -8,7 +8,8 @@ namespace sprout { // make_indexes // template - inline SPROUT_CONSTEXPR typename IndexTupleType::type make_indexes() { + inline SPROUT_CONSTEXPR typename IndexTupleType::type + make_indexes() { return typename IndexTupleType::type(); } } // namespace sprout diff --git a/sprout/io.hpp b/sprout/io.hpp index 84bd992b..f9166e07 100644 --- a/sprout/io.hpp +++ b/sprout/io.hpp @@ -162,18 +162,20 @@ namespace sprout { // width // fill // - inline SPROUT_CONSTEXPR sprout::io::flags::precision_t - precision(sprout::io::flags::precision_t::type value) { - return sprout::io::flags::precision_t(value); - } - inline SPROUT_CONSTEXPR sprout::io::flags::width_t - width(sprout::io::flags::width_t::type value) { - return sprout::io::flags::width_t(value); - } - inline SPROUT_CONSTEXPR sprout::io::flags::fill_t - fill(sprout::io::flags::fill_t::type value) { - return sprout::io::flags::fill_t(value); - } + namespace { + inline SPROUT_CONSTEXPR sprout::io::flags::precision_t + precision(sprout::io::flags::precision_t::type value) { + return sprout::io::flags::precision_t(value); + } + inline SPROUT_CONSTEXPR sprout::io::flags::width_t + width(sprout::io::flags::width_t::type value) { + return sprout::io::flags::width_t(value); + } + inline SPROUT_CONSTEXPR sprout::io::flags::fill_t + fill(sprout::io::flags::fill_t::type value) { + return sprout::io::flags::fill_t(value); + } + } // anonymous-namespace // // format_settings @@ -525,10 +527,10 @@ namespace sprout { template inline SPROUT_CONSTEXPR auto operator<<(sprout::io::format_expression const& lhs, sprout::io::format_holder const& rhs) - -> sprout::io::format_expression< - sprout::io::format_expression, - decltype(std::declval() << rhs.value()) - > + -> sprout::io::format_expression< + sprout::io::format_expression, + decltype(std::declval() << rhs.value()) + > { typedef decltype(sprout::io::root << rhs.value()) type; return sprout::io::format_expression, type>( @@ -681,7 +683,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR auto eval(sprout::io::format_holder const& holder) - -> decltype(sprout::int_to_string(holder.value())) + -> decltype(sprout::int_to_string(holder.value())) { return sprout::int_to_string(holder.value()); } @@ -691,7 +693,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR auto eval(sprout::io::format_holder const& holder) - -> decltype(sprout::float_to_string(holder.value())) + -> decltype(sprout::float_to_string(holder.value())) { return sprout::float_to_string(holder.value()); } @@ -701,7 +703,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR auto eval(sprout::io::format_holder const& holder) - -> decltype(sprout::basic_string{{static_cast(holder.value())}, 1}) + -> decltype(sprout::basic_string{{static_cast(holder.value())}, 1}) { return sprout::basic_string{{static_cast(holder.value())}, 1}; } @@ -711,7 +713,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR auto eval(sprout::io::format_holder const& holder) - -> decltype(sprout::to_string(holder.value())) + -> decltype(sprout::to_string(holder.value())) { return sprout::to_string(holder.value()); } @@ -721,7 +723,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR auto eval(sprout::io::format_holder const& holder) - -> decltype(holder.value()) + -> decltype(holder.value()) { return holder.value(); } diff --git a/sprout/iterator/bytes_iterator.hpp b/sprout/iterator/bytes_iterator.hpp index 38493f3c..f5e8e0d5 100644 --- a/sprout/iterator/bytes_iterator.hpp +++ b/sprout/iterator/bytes_iterator.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace sprout { // @@ -89,10 +90,11 @@ namespace sprout { SPROUT_CONSTEXPR bytes_iterator prev() const { return bytes_iterator(it_, i_ - 1, prev_tag()); } - void swap(bytes_iterator& other) { - using std::swap; - swap(it_, other.it_); - swap(i_, other.i_); + void swap(bytes_iterator& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(it_, other.it_))) + { + sprout::swap(it_, other.it_); + sprout::swap(i_, other.i_); } friend SPROUT_CONSTEXPR bool operator==(bytes_iterator const& lhs, bytes_iterator const& rhs) { return lhs.it_ == rhs.it_ && lhs.i_ == rhs.i_; @@ -166,11 +168,13 @@ namespace sprout { // make_bytes_iterator // template - inline SPROUT_CONSTEXPR sprout::bytes_iterator make_bytes_iterator(Iterator it) { + inline SPROUT_CONSTEXPR sprout::bytes_iterator + make_bytes_iterator(Iterator it) { return sprout::bytes_iterator(it); } template - inline SPROUT_CONSTEXPR sprout::bytes_iterator make_bytes_iterator(Iterator it, Traits) { + inline SPROUT_CONSTEXPR sprout::bytes_iterator + make_bytes_iterator(Iterator it, Traits) { return sprout::bytes_iterator(it); } @@ -178,7 +182,10 @@ namespace sprout { // swap // template - inline void swap(sprout::bytes_iterator& lhs, sprout::bytes_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::bytes_iterator& lhs, sprout::bytes_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -187,11 +194,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::bytes_iterator first, - sprout::bytes_iterator last - ) - { + iterator_distance(sprout::bytes_iterator first, sprout::bytes_iterator last) { return last - first; } @@ -199,14 +202,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::bytes_iterator iterator_next( - sprout::bytes_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::bytes_iterator + iterator_next(sprout::bytes_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::bytes_iterator iterator_next( + inline SPROUT_CONSTEXPR sprout::bytes_iterator + iterator_next( sprout::bytes_iterator const& it, typename sprout::bytes_iterator::difference_type n ) @@ -218,14 +220,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::bytes_iterator iterator_prev( - sprout::bytes_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::bytes_iterator + iterator_prev(sprout::bytes_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::bytes_iterator iterator_prev( + inline SPROUT_CONSTEXPR sprout::bytes_iterator + iterator_prev( sprout::bytes_iterator const& it, typename sprout::bytes_iterator::difference_type n ) diff --git a/sprout/iterator/counting_iterator.hpp b/sprout/iterator/counting_iterator.hpp index 06d07838..1998e764 100644 --- a/sprout/iterator/counting_iterator.hpp +++ b/sprout/iterator/counting_iterator.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace sprout { // @@ -100,70 +101,51 @@ namespace sprout { SPROUT_CONSTEXPR counting_iterator prev() const { return counting_iterator(current_ - 1); } - void swap(counting_iterator& other) { - using std::swap; - swap(current_, other.current_); + void swap(counting_iterator& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(current_, other.current_))) + { + sprout::swap(current_, other.current_); } }; template - SPROUT_CONSTEXPR bool operator==( - sprout::counting_iterator const& lhs, - sprout::counting_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator==(sprout::counting_iterator const& lhs, sprout::counting_iterator const& rhs) { return *lhs == *rhs; } template - SPROUT_CONSTEXPR bool operator!=( - sprout::counting_iterator const& lhs, - sprout::counting_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::counting_iterator const& lhs, sprout::counting_iterator const& rhs) { return !(lhs == rhs); } template - SPROUT_CONSTEXPR bool operator<( - sprout::counting_iterator const& lhs, - sprout::counting_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<(sprout::counting_iterator const& lhs, sprout::counting_iterator const& rhs) { return *lhs < *rhs; } template - SPROUT_CONSTEXPR bool operator>( - sprout::counting_iterator const& lhs, - sprout::counting_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>(sprout::counting_iterator const& lhs, sprout::counting_iterator const& rhs) { return rhs < lhs; } template - SPROUT_CONSTEXPR bool operator<=( - sprout::counting_iterator const& lhs, - sprout::counting_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::counting_iterator const& lhs, sprout::counting_iterator const& rhs) { return !(rhs < lhs); } template - SPROUT_CONSTEXPR bool operator>=( - sprout::counting_iterator const& lhs, - sprout::counting_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::counting_iterator const& lhs, sprout::counting_iterator const& rhs) { return !(lhs < rhs); } template - SPROUT_CONSTEXPR typename sprout::counting_iterator::difference_type operator-( - sprout::counting_iterator const& lhs, - sprout::counting_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR typename sprout::counting_iterator::difference_type + operator-(sprout::counting_iterator const& lhs, sprout::counting_iterator const& rhs) { return static_cast::difference_type>(*lhs - *rhs); } template - SPROUT_CONSTEXPR sprout::counting_iterator operator+( + inline SPROUT_CONSTEXPR sprout::counting_iterator + operator+( typename sprout::counting_iterator::difference_type n, sprout::counting_iterator const& it ) @@ -175,7 +157,7 @@ namespace sprout { // make_counting_iterator // template - SPROUT_CONSTEXPR sprout::counting_iterator + inline SPROUT_CONSTEXPR sprout::counting_iterator make_counting_iterator(Incrementable const& v) { return sprout::counting_iterator(v); } @@ -184,7 +166,8 @@ namespace sprout { // swap // template - inline void swap(sprout::counting_iterator& lhs, sprout::counting_iterator& rhs) + inline void + swap(sprout::counting_iterator& lhs, sprout::counting_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); @@ -195,11 +178,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::counting_iterator first, - sprout::counting_iterator last - ) - { + iterator_distance(sprout::counting_iterator first, sprout::counting_iterator last) { return last - first; } @@ -207,14 +186,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::counting_iterator iterator_next( - sprout::counting_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::counting_iterator + iterator_next(sprout::counting_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::counting_iterator iterator_next( + inline SPROUT_CONSTEXPR sprout::counting_iterator + iterator_next( sprout::counting_iterator const& it, typename sprout::counting_iterator::difference_type n ) @@ -226,14 +204,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::counting_iterator iterator_prev( - sprout::counting_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::counting_iterator + iterator_prev(sprout::counting_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::counting_iterator iterator_prev( + inline SPROUT_CONSTEXPR sprout::counting_iterator + iterator_prev( sprout::counting_iterator const& it, typename sprout::counting_iterator::difference_type n ) diff --git a/sprout/iterator/filter_iterator.hpp b/sprout/iterator/filter_iterator.hpp index 44d5c50a..9b59c72a 100644 --- a/sprout/iterator/filter_iterator.hpp +++ b/sprout/iterator/filter_iterator.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace sprout { // @@ -134,11 +135,16 @@ namespace sprout { SPROUT_CONSTEXPR filter_iterator prev() const { return filter_iterator(pred, find_prev(sprout::prev(current), pred), last, private_constructor_tag()); } - void swap(filter_iterator& other) { - using std::swap; - swap(current, other.current); - swap(last, other.last); - swap(pred, other.pred); + void swap(filter_iterator& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(last, other.last)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(pred, other.pred)) + ) + { + sprout::swap(current, other.current); + sprout::swap(last, other.last); + sprout::swap(pred, other.pred); } }; @@ -172,7 +178,10 @@ namespace sprout { // swap // template - inline void swap(sprout::filter_iterator& lhs, sprout::filter_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::filter_iterator& lhs, sprout::filter_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -180,10 +189,8 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::filter_iterator iterator_next( - sprout::filter_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::filter_iterator + iterator_next(sprout::filter_iterator const& it) { return it.next(); } @@ -191,10 +198,8 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::filter_iterator iterator_prev( - sprout::filter_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::filter_iterator + iterator_prev(sprout::filter_iterator const& it) { return it.prev(); } } // namespace sprout diff --git a/sprout/iterator/generator_iterator.hpp b/sprout/iterator/generator_iterator.hpp index 16a15326..609e4066 100644 --- a/sprout/iterator/generator_iterator.hpp +++ b/sprout/iterator/generator_iterator.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace sprout { // @@ -69,10 +70,11 @@ namespace sprout { SPROUT_CONSTEXPR generator_iterator next_generator() const { return (*this)(); } - void swap(generator_iterator& other) { - using std::swap; - swap(gen_, other.gen_); - swap(count_, other.count_); + void swap(generator_iterator& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(gen_, other.gen_))) + { + sprout::swap(gen_, other.gen_); + sprout::swap(count_, other.count_); } friend SPROUT_CONSTEXPR bool operator==(generator_iterator const& lhs, generator_iterator const& rhs) { return lhs.count_ == rhs.count_; @@ -124,10 +126,9 @@ namespace sprout { // swap // template - void swap( - sprout::generator_iterator& lhs, - sprout::generator_iterator& rhs - ) + inline void + swap(sprout::generator_iterator& lhs, sprout::generator_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } @@ -137,11 +138,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::generator_iterator first, - sprout::generator_iterator last - ) - { + iterator_distance(sprout::generator_iterator first, sprout::generator_iterator last) { return last - first; } @@ -149,10 +146,8 @@ namespace sprout { // iterator_next // template - SPROUT_CONSTEXPR sprout::generator_iterator iterator_next( - sprout::generator_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::generator_iterator + iterator_next(sprout::generator_iterator const& it) { return it.next(); } } // namespace sprout diff --git a/sprout/iterator/index_iterator.hpp b/sprout/iterator/index_iterator.hpp index 2531887b..2de357cb 100644 --- a/sprout/iterator/index_iterator.hpp +++ b/sprout/iterator/index_iterator.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace sprout { // @@ -91,10 +92,11 @@ namespace sprout { SPROUT_CONSTEXPR index_iterator prev() const { return index_iterator(holder_, index_ - 1); } - void swap(index_iterator& other) { - using std::swap; - swap(holder_, other.holder_); - swap(index_, other.index_); + void swap(index_iterator& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(holder_, other.holder_))) + { + sprout::swap(holder_, other.holder_); + sprout::swap(index_, other.index_); } friend SPROUT_CONSTEXPR bool operator==(index_iterator const& lhs, index_iterator const& rhs) { return lhs.index_ == rhs.index_; @@ -171,7 +173,10 @@ namespace sprout { // swap // template - inline void swap(sprout::index_iterator& lhs, sprout::index_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::index_iterator& lhs, sprout::index_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -200,11 +205,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::index_iterator first, - sprout::index_iterator last - ) - { + iterator_distance(sprout::index_iterator first, sprout::index_iterator last) { return last - first; } @@ -212,14 +213,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::index_iterator iterator_next( - sprout::index_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::index_iterator + iterator_next(sprout::index_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::index_iterator iterator_next( + inline SPROUT_CONSTEXPR sprout::index_iterator + iterator_next( sprout::index_iterator const& it, typename sprout::index_iterator::difference_type n ) @@ -231,14 +231,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::index_iterator iterator_prev( - sprout::index_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::index_iterator + iterator_prev(sprout::index_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::index_iterator iterator_prev( + inline SPROUT_CONSTEXPR sprout::index_iterator + iterator_prev( sprout::index_iterator const& it, typename sprout::index_iterator::difference_type n ) diff --git a/sprout/iterator/next.hpp b/sprout/iterator/next.hpp index bede5413..6de60faf 100644 --- a/sprout/iterator/next.hpp +++ b/sprout/iterator/next.hpp @@ -16,19 +16,13 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< std::is_literal_type::value, RandomAccessIterator - >::type next_impl( - RandomAccessIterator const& it, - std::random_access_iterator_tag* - ) - { + >::type + next_impl(RandomAccessIterator const& it, std::random_access_iterator_tag*) { return it + 1; } template - inline SPROUT_CONSTEXPR ForwardIterator next_impl( - ForwardIterator const& it, - void* - ) - { + inline SPROUT_CONSTEXPR ForwardIterator + next_impl(ForwardIterator const& it, void*) { return std::next(it); } @@ -36,18 +30,18 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< std::is_literal_type::value, RandomAccessIterator - >::type next_impl( - RandomAccessIterator const& it, - typename std::iterator_traits::difference_type n, + >::type + next_impl( + RandomAccessIterator const& it, typename std::iterator_traits::difference_type n, std::random_access_iterator_tag* ) { return it + n; } template - inline SPROUT_CONSTEXPR ForwardIterator next_impl( - ForwardIterator const& it, - typename std::iterator_traits::difference_type n, + inline SPROUT_CONSTEXPR ForwardIterator + next_impl( + ForwardIterator const& it, typename std::iterator_traits::difference_type n, void* ) { diff --git a/sprout/iterator/prev.hpp b/sprout/iterator/prev.hpp index c4237d31..5fb3dc67 100644 --- a/sprout/iterator/prev.hpp +++ b/sprout/iterator/prev.hpp @@ -16,19 +16,13 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< std::is_literal_type::value, RandomAccessIterator - >::type prev_impl( - RandomAccessIterator const& it, - std::random_access_iterator_tag* - ) - { + >::type + prev_impl(RandomAccessIterator const& it, std::random_access_iterator_tag*) { return it - 1; } template - inline SPROUT_CONSTEXPR BidirectionalIterator prev_impl( - BidirectionalIterator const& it, - void* - ) - { + inline SPROUT_CONSTEXPR BidirectionalIterator + prev_impl(BidirectionalIterator const& it, void*) { return std::prev(it); } @@ -36,18 +30,18 @@ namespace sprout { inline SPROUT_CONSTEXPR typename std::enable_if< std::is_literal_type::value, RandomAccessIterator - >::type prev_impl( - RandomAccessIterator const& it, - typename std::iterator_traits::difference_type n, + >::type + prev_impl( + RandomAccessIterator const& it, typename std::iterator_traits::difference_type n, std::random_access_iterator_tag* ) { return it - n; } template - inline SPROUT_CONSTEXPR BidirectionalIterator prev_impl( - BidirectionalIterator const& it, - typename std::iterator_traits::difference_type n, + inline SPROUT_CONSTEXPR BidirectionalIterator + prev_impl( + BidirectionalIterator const& it, typename std::iterator_traits::difference_type n, void* ) { diff --git a/sprout/iterator/reverse_iterator.hpp b/sprout/iterator/reverse_iterator.hpp index 08a5ac41..2ba32bf5 100644 --- a/sprout/iterator/reverse_iterator.hpp +++ b/sprout/iterator/reverse_iterator.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace sprout { // @@ -110,71 +111,55 @@ namespace sprout { SPROUT_CONSTEXPR reverse_iterator prev() const { return reverse_iterator(sprout::next(current)); } - void swap(reverse_iterator& other) { - using std::swap; + void swap(reverse_iterator& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(swap(current, other.current)) + && SPROUT_NOEXCEPT_EXPR(swap(deref_tmp, other.deref_tmp)) + ) + { swap(current, other.current); swap(deref_tmp, other.deref_tmp); } }; template - inline SPROUT_CONSTEXPR bool operator==( - sprout::reverse_iterator const& lhs, - sprout::reverse_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator==(sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs) { return lhs.base() == rhs.base(); } template - inline SPROUT_CONSTEXPR bool operator!=( - sprout::reverse_iterator const& lhs, - sprout::reverse_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator<( - sprout::reverse_iterator const& lhs, - sprout::reverse_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<(sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs) { return lhs.base() < rhs.base(); } template - inline SPROUT_CONSTEXPR bool operator>( - sprout::reverse_iterator const& lhs, - sprout::reverse_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>(sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator<=( - sprout::reverse_iterator const& lhs, - sprout::reverse_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator>=( - sprout::reverse_iterator const& lhs, - sprout::reverse_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs) { return !(lhs < rhs); } template - inline SPROUT_CONSTEXPR decltype(std::declval() - std::declval()) operator-( - sprout::reverse_iterator const& lhs, - sprout::reverse_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR decltype(std::declval() - std::declval()) + operator-(sprout::reverse_iterator const& lhs, sprout::reverse_iterator const& rhs) { return lhs.base() - rhs.base(); } template - inline SPROUT_CONSTEXPR sprout::reverse_iterator operator+( + inline SPROUT_CONSTEXPR sprout::reverse_iterator + operator+( typename sprout::reverse_iterator::difference_type n, sprout::reverse_iterator const& it ) @@ -195,7 +180,10 @@ namespace sprout { // swap // template - inline void swap(sprout::reverse_iterator& lhs, sprout::reverse_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::reverse_iterator& lhs, sprout::reverse_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -204,11 +192,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::reverse_iterator first, - sprout::reverse_iterator last - ) - { + iterator_distance(sprout::reverse_iterator first, sprout::reverse_iterator last) { return last - first; } @@ -216,14 +200,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::reverse_iterator iterator_next( - sprout::reverse_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::reverse_iterator + iterator_next(sprout::reverse_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::reverse_iterator iterator_next( + inline SPROUT_CONSTEXPR sprout::reverse_iterator + iterator_next( sprout::reverse_iterator const& it, typename sprout::reverse_iterator::difference_type n ) @@ -235,14 +218,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::reverse_iterator iterator_prev( - sprout::reverse_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::reverse_iterator + iterator_prev(sprout::reverse_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::reverse_iterator iterator_prev( + inline SPROUT_CONSTEXPR sprout::reverse_iterator + iterator_prev( sprout::reverse_iterator const& it, typename sprout::reverse_iterator::difference_type n ) diff --git a/sprout/iterator/sawtooth_iterator.hpp b/sprout/iterator/sawtooth_iterator.hpp index 0c215348..68f622ee 100644 --- a/sprout/iterator/sawtooth_iterator.hpp +++ b/sprout/iterator/sawtooth_iterator.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace sprout { // @@ -136,77 +137,52 @@ namespace sprout { SPROUT_CONSTEXPR sawtooth_iterator prev() const { return sawtooth_iterator(*this, index_ - 1); } - void swap(sawtooth_iterator& other) { - using std::swap; - swap(index_, other.index_); - swap(frequency_, other.frequency_); - swap(amplitude_, other.amplitude_); - swap(phase_, other.phase_); + void swap(sawtooth_iterator& other) SPROUT_NOEXCEPT { + sprout::swap(index_, other.index_); + sprout::swap(frequency_, other.frequency_); + sprout::swap(amplitude_, other.amplitude_); + sprout::swap(phase_, other.phase_); } }; template - inline SPROUT_CONSTEXPR bool operator==( - sprout::sawtooth_iterator const& lhs, - sprout::sawtooth_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator==(sprout::sawtooth_iterator const& lhs, sprout::sawtooth_iterator const& rhs) { return lhs.index() == rhs.index(); } template - inline SPROUT_CONSTEXPR bool operator!=( - sprout::sawtooth_iterator const& lhs, - sprout::sawtooth_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::sawtooth_iterator const& lhs, sprout::sawtooth_iterator const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator<( - sprout::sawtooth_iterator const& lhs, - sprout::sawtooth_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<(sprout::sawtooth_iterator const& lhs, sprout::sawtooth_iterator const& rhs) { return lhs.index() < rhs.index(); } template - inline SPROUT_CONSTEXPR bool operator>( - sprout::sawtooth_iterator const& lhs, - sprout::sawtooth_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>(sprout::sawtooth_iterator const& lhs, sprout::sawtooth_iterator const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator<=( - sprout::sawtooth_iterator const& lhs, - sprout::sawtooth_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::sawtooth_iterator const& lhs, sprout::sawtooth_iterator const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator>=( - sprout::sawtooth_iterator const& lhs, - sprout::sawtooth_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::sawtooth_iterator const& lhs, sprout::sawtooth_iterator const& rhs) { return !(lhs < rhs); } template - inline SPROUT_CONSTEXPR typename sprout::sawtooth_iterator::difference_type operator-( - sprout::sawtooth_iterator const& lhs, - sprout::sawtooth_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR typename sprout::sawtooth_iterator::difference_type + operator-(sprout::sawtooth_iterator const& lhs, sprout::sawtooth_iterator const& rhs) { return lhs.index() - rhs.index(); } template - inline SPROUT_CONSTEXPR sprout::sawtooth_iterator operator+( - typename sprout::sawtooth_iterator::difference_type n, - sprout::sawtooth_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::sawtooth_iterator + operator+(typename sprout::sawtooth_iterator::difference_type n, sprout::sawtooth_iterator const& it) { return it + n; } @@ -214,7 +190,10 @@ namespace sprout { // swap // template - inline void swap(sprout::sawtooth_iterator& lhs, sprout::sawtooth_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::sawtooth_iterator& lhs, sprout::sawtooth_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -223,11 +202,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::sawtooth_iterator first, - sprout::sawtooth_iterator last - ) - { + iterator_distance(sprout::sawtooth_iterator first, sprout::sawtooth_iterator last) { return last - first; } @@ -235,18 +210,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::sawtooth_iterator iterator_next( - sprout::sawtooth_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::sawtooth_iterator + iterator_next(sprout::sawtooth_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::sawtooth_iterator iterator_next( - sprout::sawtooth_iterator const& it, - typename sprout::sawtooth_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::sawtooth_iterator + iterator_next(sprout::sawtooth_iterator const& it, typename sprout::sawtooth_iterator::difference_type n) { return it + n; } @@ -254,18 +224,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::sawtooth_iterator iterator_prev( - sprout::sawtooth_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::sawtooth_iterator + iterator_prev(sprout::sawtooth_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::sawtooth_iterator iterator_prev( - sprout::sawtooth_iterator const& it, - typename sprout::sawtooth_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::sawtooth_iterator + iterator_prev(sprout::sawtooth_iterator const& it, typename sprout::sawtooth_iterator::difference_type n) { return it - n; } } // namespace sprout diff --git a/sprout/iterator/sinusoid_iterator.hpp b/sprout/iterator/sinusoid_iterator.hpp index 98640621..09379d69 100644 --- a/sprout/iterator/sinusoid_iterator.hpp +++ b/sprout/iterator/sinusoid_iterator.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace sprout { // @@ -144,78 +145,53 @@ namespace sprout { SPROUT_CONSTEXPR sinusoid_iterator prev() const { return sinusoid_iterator(*this, index_ - 1); } - void swap(sinusoid_iterator& other) { - using std::swap; - swap(index_, other.index_); - swap(frequency_, other.frequency_); - swap(amplitude_, other.amplitude_); - swap(phase_, other.phase_); - swap(d_, other.d_); + void swap(sinusoid_iterator& other) SPROUT_NOEXCEPT { + sprout::swap(index_, other.index_); + sprout::swap(frequency_, other.frequency_); + sprout::swap(amplitude_, other.amplitude_); + sprout::swap(phase_, other.phase_); + sprout::swap(d_, other.d_); } }; template - inline SPROUT_CONSTEXPR bool operator==( - sprout::sinusoid_iterator const& lhs, - sprout::sinusoid_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator==(sprout::sinusoid_iterator const& lhs, sprout::sinusoid_iterator const& rhs) { return lhs.index() == rhs.index(); } template - inline SPROUT_CONSTEXPR bool operator!=( - sprout::sinusoid_iterator const& lhs, - sprout::sinusoid_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::sinusoid_iterator const& lhs, sprout::sinusoid_iterator const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator<( - sprout::sinusoid_iterator const& lhs, - sprout::sinusoid_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<(sprout::sinusoid_iterator const& lhs, sprout::sinusoid_iterator const& rhs) { return lhs.index() < rhs.index(); } template - inline SPROUT_CONSTEXPR bool operator>( - sprout::sinusoid_iterator const& lhs, - sprout::sinusoid_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>(sprout::sinusoid_iterator const& lhs, sprout::sinusoid_iterator const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator<=( - sprout::sinusoid_iterator const& lhs, - sprout::sinusoid_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::sinusoid_iterator const& lhs, sprout::sinusoid_iterator const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator>=( - sprout::sinusoid_iterator const& lhs, - sprout::sinusoid_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::sinusoid_iterator const& lhs, sprout::sinusoid_iterator const& rhs) { return !(lhs < rhs); } template - inline SPROUT_CONSTEXPR typename sprout::sinusoid_iterator::difference_type operator-( - sprout::sinusoid_iterator const& lhs, - sprout::sinusoid_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR typename sprout::sinusoid_iterator::difference_type + operator-(sprout::sinusoid_iterator const& lhs, sprout::sinusoid_iterator const& rhs) { return lhs.index() - rhs.index(); } template - inline SPROUT_CONSTEXPR sprout::sinusoid_iterator operator+( - typename sprout::sinusoid_iterator::difference_type n, - sprout::sinusoid_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::sinusoid_iterator + operator+(typename sprout::sinusoid_iterator::difference_type n, sprout::sinusoid_iterator const& it) { return it + n; } @@ -223,7 +199,10 @@ namespace sprout { // swap // template - inline void swap(sprout::sinusoid_iterator& lhs, sprout::sinusoid_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::sinusoid_iterator& lhs, sprout::sinusoid_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -232,11 +211,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::sinusoid_iterator first, - sprout::sinusoid_iterator last - ) - { + iterator_distance(sprout::sinusoid_iterator first, sprout::sinusoid_iterator last) { return last - first; } @@ -244,18 +219,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::sinusoid_iterator iterator_next( - sprout::sinusoid_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::sinusoid_iterator + iterator_next(sprout::sinusoid_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::sinusoid_iterator iterator_next( - sprout::sinusoid_iterator const& it, - typename sprout::sinusoid_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::sinusoid_iterator + iterator_next(sprout::sinusoid_iterator const& it, typename sprout::sinusoid_iterator::difference_type n) { return it + n; } @@ -263,18 +233,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::sinusoid_iterator iterator_prev( - sprout::sinusoid_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::sinusoid_iterator + iterator_prev(sprout::sinusoid_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::sinusoid_iterator iterator_prev( - sprout::sinusoid_iterator const& it, - typename sprout::sinusoid_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::sinusoid_iterator + iterator_prev(sprout::sinusoid_iterator const& it, typename sprout::sinusoid_iterator::difference_type n) { return it - n; } } // namespace sprout diff --git a/sprout/iterator/size_enum_iterator.hpp b/sprout/iterator/size_enum_iterator.hpp index 8f2489c4..1598f96a 100644 --- a/sprout/iterator/size_enum_iterator.hpp +++ b/sprout/iterator/size_enum_iterator.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace sprout { // @@ -112,9 +113,10 @@ namespace sprout { SPROUT_CONSTEXPR size_enum_iterator prev() const { return size_enum_iterator(sprout::prev(current)); } - void swap(size_enum_iterator& other) { - using std::swap; - swap(current, other.current); + void swap(size_enum_iterator& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))) + { + sprout::swap(current, other.current); } }; @@ -254,11 +256,12 @@ namespace sprout { : size_enum_iterator(sprout::prev(current), sep_size, true) ; } - void swap(size_enum_iterator& other) { - using std::swap; - swap(current, other.current); - swap(sep_size, other.sep_size); - swap(is_sep, other.is_sep); + void swap(size_enum_iterator& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))) + { + sprout::swap(current, other.current); + sprout::swap(sep_size, other.sep_size); + sprout::swap(is_sep, other.is_sep); } }; @@ -266,7 +269,8 @@ namespace sprout { typename Iterator1, bool Separated1, typename Iterator2, bool Separated2 > - inline SPROUT_CONSTEXPR bool operator==( + inline SPROUT_CONSTEXPR bool + operator==( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -277,7 +281,8 @@ namespace sprout { typename Iterator1, bool Separated1, typename Iterator2, bool Separated2 > - inline SPROUT_CONSTEXPR bool operator!=( + inline SPROUT_CONSTEXPR bool + operator!=( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -288,7 +293,8 @@ namespace sprout { typename Iterator1, bool Separated1, typename Iterator2, bool Separated2 > - inline SPROUT_CONSTEXPR bool operator<( + inline SPROUT_CONSTEXPR bool + operator<( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -301,7 +307,8 @@ namespace sprout { typename Iterator1, bool Separated1, typename Iterator2, bool Separated2 > - inline SPROUT_CONSTEXPR bool operator>( + inline SPROUT_CONSTEXPR bool + operator>( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -312,7 +319,8 @@ namespace sprout { typename Iterator1, bool Separated1, typename Iterator2, bool Separated2 > - inline SPROUT_CONSTEXPR bool operator<=( + inline SPROUT_CONSTEXPR bool + operator<=( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -323,7 +331,8 @@ namespace sprout { typename Iterator1, bool Separated1, typename Iterator2, bool Separated2 > - inline SPROUT_CONSTEXPR bool operator>=( + inline SPROUT_CONSTEXPR bool + operator>=( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -331,7 +340,8 @@ namespace sprout { return !(lhs < rhs); } template - inline SPROUT_CONSTEXPR decltype(std::declval() - std::declval()) operator-( + inline SPROUT_CONSTEXPR decltype(std::declval() - std::declval()) + operator-( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -339,7 +349,8 @@ namespace sprout { return lhs.base() - rhs.base(); } template - inline SPROUT_CONSTEXPR decltype(std::declval() - std::declval()) operator-( + inline SPROUT_CONSTEXPR decltype(std::declval() - std::declval()) + operator-( sprout::size_enum_iterator const& lhs, sprout::size_enum_iterator const& rhs ) @@ -352,7 +363,8 @@ namespace sprout { ; } template - inline SPROUT_CONSTEXPR sprout::size_enum_iterator operator+( + inline SPROUT_CONSTEXPR sprout::size_enum_iterator + operator+( typename sprout::size_enum_iterator::difference_type n, sprout::size_enum_iterator const& it ) @@ -383,11 +395,8 @@ namespace sprout { // swap // template - void swap( - sprout::size_enum_iterator& lhs, - sprout::size_enum_iterator& rhs - ) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + void swap(sprout::size_enum_iterator& lhs, sprout::size_enum_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } @@ -397,11 +406,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::size_enum_iterator first, - sprout::size_enum_iterator last - ) - { + iterator_distance(sprout::size_enum_iterator first, sprout::size_enum_iterator last) { return last - first; } @@ -409,14 +414,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::size_enum_iterator iterator_next( - sprout::size_enum_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::size_enum_iterator + iterator_next(sprout::size_enum_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::size_enum_iterator iterator_next( + inline SPROUT_CONSTEXPR sprout::size_enum_iterator + iterator_next( sprout::size_enum_iterator const& it, typename sprout::size_enum_iterator::difference_type n ) @@ -428,14 +432,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::size_enum_iterator iterator_prev( - sprout::size_enum_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::size_enum_iterator + iterator_prev(sprout::size_enum_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::size_enum_iterator iterator_prev( + inline SPROUT_CONSTEXPR sprout::size_enum_iterator + iterator_prev( sprout::size_enum_iterator const& it, typename sprout::size_enum_iterator::difference_type n ) diff --git a/sprout/iterator/square_iterator.hpp b/sprout/iterator/square_iterator.hpp index 83a936e3..7cd34917 100644 --- a/sprout/iterator/square_iterator.hpp +++ b/sprout/iterator/square_iterator.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace sprout { // @@ -145,78 +146,53 @@ namespace sprout { SPROUT_CONSTEXPR square_iterator prev() const { return square_iterator(*this, index_ - 1); } - void swap(square_iterator& other) { - using std::swap; - swap(index_, other.index_); - swap(frequency_, other.frequency_); - swap(amplitude_, other.amplitude_); - swap(phase_, other.phase_); - swap(duty_, other.duty_); + void swap(square_iterator& other) SPROUT_NOEXCEPT { + sprout::swap(index_, other.index_); + sprout::swap(frequency_, other.frequency_); + sprout::swap(amplitude_, other.amplitude_); + sprout::swap(phase_, other.phase_); + sprout::swap(duty_, other.duty_); } }; template - inline SPROUT_CONSTEXPR bool operator==( - sprout::square_iterator const& lhs, - sprout::square_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator==(sprout::square_iterator const& lhs, sprout::square_iterator const& rhs) { return lhs.index() == rhs.index(); } template - inline SPROUT_CONSTEXPR bool operator!=( - sprout::square_iterator const& lhs, - sprout::square_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::square_iterator const& lhs, sprout::square_iterator const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator<( - sprout::square_iterator const& lhs, - sprout::square_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<(sprout::square_iterator const& lhs, sprout::square_iterator const& rhs) { return lhs.index() < rhs.index(); } template - inline SPROUT_CONSTEXPR bool operator>( - sprout::square_iterator const& lhs, - sprout::square_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>(sprout::square_iterator const& lhs, sprout::square_iterator const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator<=( - sprout::square_iterator const& lhs, - sprout::square_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::square_iterator const& lhs, sprout::square_iterator const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator>=( - sprout::square_iterator const& lhs, - sprout::square_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::square_iterator const& lhs, sprout::square_iterator const& rhs) { return !(lhs < rhs); } template - inline SPROUT_CONSTEXPR typename sprout::square_iterator::difference_type operator-( - sprout::square_iterator const& lhs, - sprout::square_iterator const& rhs - ) - { + inline SPROUT_CONSTEXPR typename sprout::square_iterator::difference_type + operator-(sprout::square_iterator const& lhs, sprout::square_iterator const& rhs) { return lhs.index() - rhs.index(); } template - inline SPROUT_CONSTEXPR sprout::square_iterator operator+( - typename sprout::square_iterator::difference_type n, - sprout::square_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::square_iterator + operator+(typename sprout::square_iterator::difference_type n, sprout::square_iterator const& it) { return it + n; } @@ -224,7 +200,10 @@ namespace sprout { // swap // template - inline void swap(sprout::square_iterator& lhs, sprout::square_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::square_iterator& lhs, sprout::square_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -233,11 +212,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::square_iterator first, - sprout::square_iterator last - ) - { + iterator_distance(sprout::square_iterator first, sprout::square_iterator last) { return last - first; } @@ -245,18 +220,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::square_iterator iterator_next( - sprout::square_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::square_iterator + iterator_next(sprout::square_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::square_iterator iterator_next( - sprout::square_iterator const& it, - typename sprout::square_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::square_iterator + iterator_next(sprout::square_iterator const& it, typename sprout::square_iterator::difference_type n) { return it + n; } @@ -264,18 +234,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::square_iterator iterator_prev( - sprout::square_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::square_iterator + iterator_prev(sprout::square_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::square_iterator iterator_prev( - sprout::square_iterator const& it, - typename sprout::square_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::square_iterator + iterator_prev(sprout::square_iterator const& it, typename sprout::square_iterator::difference_type n) { return it - n; } } // namespace sprout diff --git a/sprout/iterator/transform_iterator.hpp b/sprout/iterator/transform_iterator.hpp index 65b81a61..cfce8e59 100644 --- a/sprout/iterator/transform_iterator.hpp +++ b/sprout/iterator/transform_iterator.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace sprout { // @@ -146,11 +147,16 @@ namespace sprout { SPROUT_CONSTEXPR transform_iterator prev() const { return transform_iterator(sprout::prev(current), sprout::prev(current2), func); } - void swap(transform_iterator& other) { - using std::swap; - swap(current, other.current); - swap(current2, other.current2); - swap(func, other.func); + void swap(transform_iterator& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(current2, other.current2)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(func, other.func)) + ) + { + sprout::swap(current, other.current); + sprout::swap(current2, other.current2); + sprout::swap(func, other.func); } }; @@ -266,10 +272,14 @@ namespace sprout { SPROUT_CONSTEXPR transform_iterator prev() const { return transform_iterator(sprout::prev(current), func); } - void swap(transform_iterator& other) { - using std::swap; - swap(current, other.current); - swap(func, other.func); + void swap(transform_iterator& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(func, other.func)) + ) + { + sprout::swap(current, other.current); + sprout::swap(func, other.func); } }; @@ -377,11 +387,12 @@ namespace sprout { // swap // template - void swap( + inline void + swap( sprout::transform_iterator& lhs, sprout::transform_iterator& rhs ) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } @@ -403,14 +414,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::transform_iterator iterator_next( - sprout::transform_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::transform_iterator + iterator_next(sprout::transform_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::transform_iterator iterator_next( + inline SPROUT_CONSTEXPR sprout::transform_iterator + iterator_next( sprout::transform_iterator const& it, typename sprout::transform_iterator::difference_type n ) @@ -422,14 +432,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::transform_iterator iterator_prev( - sprout::transform_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::transform_iterator + iterator_prev(sprout::transform_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::transform_iterator iterator_prev( + inline SPROUT_CONSTEXPR sprout::transform_iterator + iterator_prev( sprout::transform_iterator const& it, typename sprout::transform_iterator::difference_type n ) diff --git a/sprout/iterator/triangle_iterator.hpp b/sprout/iterator/triangle_iterator.hpp index e1c31049..3fec7361 100644 --- a/sprout/iterator/triangle_iterator.hpp +++ b/sprout/iterator/triangle_iterator.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace sprout { // @@ -136,12 +137,11 @@ namespace sprout { SPROUT_CONSTEXPR triangle_iterator prev() const { return triangle_iterator(*this, index_ - 1); } - void swap(triangle_iterator& other) { - using std::swap; - swap(index_, other.index_); - swap(frequency_, other.frequency_); - swap(amplitude_, other.amplitude_); - swap(phase_, other.phase_); + void swap(triangle_iterator& other) SPROUT_NOEXCEPT { + sprout::swap(index_, other.index_); + sprout::swap(frequency_, other.frequency_); + sprout::swap(amplitude_, other.amplitude_); + sprout::swap(phase_, other.phase_); } }; @@ -214,7 +214,10 @@ namespace sprout { // swap // template - inline void swap(sprout::triangle_iterator& lhs, sprout::triangle_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::triangle_iterator& lhs, sprout::triangle_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -223,11 +226,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR typename std::iterator_traits >::difference_type - iterator_distance( - sprout::triangle_iterator first, - sprout::triangle_iterator last - ) - { + iterator_distance(sprout::triangle_iterator first, sprout::triangle_iterator last) { return last - first; } @@ -235,18 +234,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::triangle_iterator iterator_next( - sprout::triangle_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::triangle_iterator + iterator_next(sprout::triangle_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::triangle_iterator iterator_next( - sprout::triangle_iterator const& it, - typename sprout::triangle_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::triangle_iterator + iterator_next(sprout::triangle_iterator const& it, typename sprout::triangle_iterator::difference_type n) { return it + n; } @@ -254,18 +248,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::triangle_iterator iterator_prev( - sprout::triangle_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::triangle_iterator + iterator_prev(sprout::triangle_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::triangle_iterator iterator_prev( - sprout::triangle_iterator const& it, - typename sprout::triangle_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::triangle_iterator + iterator_prev(sprout::triangle_iterator const& it, typename sprout::triangle_iterator::difference_type n) { return it - n; } } // namespace sprout diff --git a/sprout/iterator/value_iterator.hpp b/sprout/iterator/value_iterator.hpp index e83312c7..ced49b45 100644 --- a/sprout/iterator/value_iterator.hpp +++ b/sprout/iterator/value_iterator.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace sprout { // @@ -74,10 +75,11 @@ namespace sprout { SPROUT_CONSTEXPR value_iterator prev() const { return value_iterator(holder_, count_ != 0 ? count_ + 1 : count_); } - void swap(value_iterator& other) { - using std::swap; - swap(holder_, other.holder_); - swap(count_, other.count_); + void swap(value_iterator& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(holder_, other.holder_))) + { + sprout::swap(holder_, other.holder_); + sprout::swap(count_, other.count_); } friend SPROUT_CONSTEXPR bool operator==(value_iterator const& lhs, value_iterator const& rhs) { return lhs.count_ == rhs.count_ && (lhs.count_ == 0 || lhs.holder_.get() == rhs.holder_.get()); @@ -160,7 +162,10 @@ namespace sprout { // swap // template - inline void swap(sprout::value_iterator& lhs, sprout::value_iterator& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::value_iterator& lhs, sprout::value_iterator& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } @@ -177,18 +182,13 @@ namespace sprout { // iterator_next // template - inline SPROUT_CONSTEXPR sprout::value_iterator iterator_next( - sprout::value_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::value_iterator + iterator_next(sprout::value_iterator const& it) { return it.next(); } template - inline SPROUT_CONSTEXPR sprout::value_iterator iterator_next( - sprout::value_iterator const& it, - typename sprout::value_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::value_iterator + iterator_next(sprout::value_iterator const& it, typename sprout::value_iterator::difference_type n) { return it + n; } @@ -196,18 +196,13 @@ namespace sprout { // iterator_prev // template - inline SPROUT_CONSTEXPR sprout::value_iterator iterator_prev( - sprout::value_iterator const& it - ) - { + inline SPROUT_CONSTEXPR sprout::value_iterator + iterator_prev(sprout::value_iterator const& it) { return it.prev(); } template - inline SPROUT_CONSTEXPR sprout::value_iterator iterator_prev( - sprout::value_iterator const& it, - typename sprout::value_iterator::difference_type n - ) - { + inline SPROUT_CONSTEXPR sprout::value_iterator + iterator_prev(sprout::value_iterator const& it, typename sprout::value_iterator::difference_type n) { return it - n; } } // namespace sprout diff --git a/sprout/pit/comparison.hpp b/sprout/pit/comparison.hpp index bd1425b1..23491f48 100644 --- a/sprout/pit/comparison.hpp +++ b/sprout/pit/comparison.hpp @@ -14,27 +14,33 @@ namespace sprout { // operator>= // template - inline SPROUT_CONSTEXPR bool operator==(sprout::pit const& lhs, sprout::pit const& rhs) { + inline SPROUT_CONSTEXPR bool + operator==(sprout::pit const& lhs, sprout::pit const& rhs) { return lhs.front() == rhs.front(); } template - inline SPROUT_CONSTEXPR bool operator!=(sprout::pit const& lhs, sprout::pit const& rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::pit const& lhs, sprout::pit const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator<(sprout::pit const& lhs, sprout::pit const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<(sprout::pit const& lhs, sprout::pit const& rhs) { return lhs.front() < rhs.front(); } template - inline SPROUT_CONSTEXPR bool operator>(sprout::pit const& lhs, sprout::pit const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>(sprout::pit const& lhs, sprout::pit const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator<=(sprout::pit const& lhs, sprout::pit const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::pit const& lhs, sprout::pit const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator>=(sprout::pit const& lhs, sprout::pit const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::pit const& lhs, sprout::pit const& rhs) { return !(lhs < rhs); } } // namespace sprout diff --git a/sprout/pit/container.hpp b/sprout/pit/container.hpp index 5bfac75b..9bd7515b 100644 --- a/sprout/pit/container.hpp +++ b/sprout/pit/container.hpp @@ -17,20 +17,18 @@ namespace sprout { typedef typename sprout::container_construct_traits::copied_type copied_type; public: template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { + static SPROUT_CONSTEXPR copied_type + deep_copy(Cont&& cont) { return copied_type(); } template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + 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 - ) - { + 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)...); } }; diff --git a/sprout/pit/hash.hpp b/sprout/pit/hash.hpp index fd78832a..1d6accd0 100644 --- a/sprout/pit/hash.hpp +++ b/sprout/pit/hash.hpp @@ -8,7 +8,8 @@ namespace sprout { template - inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::pit const& v) { + inline SPROUT_CONSTEXPR std::size_t + hash_value(sprout::pit const& v) { return sprout::to_hash(v.elem); } } // namespace sprout diff --git a/sprout/pit/pit.hpp b/sprout/pit/pit.hpp index ce650c33..15936a66 100644 --- a/sprout/pit/pit.hpp +++ b/sprout/pit/pit.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace sprout { // @@ -35,9 +36,10 @@ namespace sprout { value_type elem; public: pit() = default; - void swap(pit& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { - using std::swap; - swap(elem, other.elem); + void swap(pit& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(elem, other.elem))) + { + sprout::swap(elem, other.elem); } // iterators: iterator begin() { @@ -131,7 +133,10 @@ namespace sprout { // swap // template - inline void swap(sprout::pit& lhs, sprout::pit& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void + swap(sprout::pit& lhs, sprout::pit& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } } // namespace sprout diff --git a/sprout/pit/tuple.hpp b/sprout/pit/tuple.hpp index ce9930c3..963f68f7 100644 --- a/sprout/pit/tuple.hpp +++ b/sprout/pit/tuple.hpp @@ -8,7 +8,7 @@ #include #include -namespace sprout_adl { +namespace sprout { // // tuple_get // @@ -27,11 +27,11 @@ namespace sprout_adl { template inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type&& tuple_get(sprout::pit&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get(t)))) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get(t)))) { return sprout::move(sprout::tuples::get(t)); } -} // namespace sprout_adl +} // namespace sprout namespace std { // diff --git a/sprout/random/inversive_congruential.hpp b/sprout/random/inversive_congruential.hpp index aa3a7a14..4e771f9c 100644 --- a/sprout/random/inversive_congruential.hpp +++ b/sprout/random/inversive_congruential.hpp @@ -38,7 +38,9 @@ namespace sprout { static SPROUT_CONSTEXPR IntType arg_check(IntType const& x0) { return arg_check_nothrow(x0) ? x0 - : throw std::invalid_argument("inversive_congruential_engine<>: invalid argument (x0 >= static_min() && x0 <= static_max())") + : throw std::invalid_argument( + "inversive_congruential_engine<>: invalid argument (x0 >= static_min() && x0 <= static_max())" + ) ; } static SPROUT_CONSTEXPR IntType init_seed_2(IntType const& x0) { diff --git a/sprout/random/iterator.hpp b/sprout/random/iterator.hpp index dfad5893..b8913e7e 100644 --- a/sprout/random/iterator.hpp +++ b/sprout/random/iterator.hpp @@ -20,7 +20,7 @@ namespace sprout { Engine const& engine, Distribution const& distribution, typename sprout::generator_iterator::type>::difference_type count = -1 ) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { return sprout::generator_iterator::type>(distribution(engine), count); } @@ -30,7 +30,7 @@ namespace sprout { Engine const& engine, typename sprout::generator_iterator::type>::difference_type count = -1 ) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { return sprout::generator_iterator::type>(engine(), count); } @@ -44,14 +44,14 @@ namespace sprout { > inline SPROUT_CONSTEXPR auto end(Engine const& engine, Distribution const& distribution) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { return sprout::generator_iterator::type>(); } template inline SPROUT_CONSTEXPR auto end(Engine const& engine) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { return sprout::generator_iterator::type>(); } diff --git a/sprout/random/mersenne_twister.hpp b/sprout/random/mersenne_twister.hpp index 84306056..1b672294 100644 --- a/sprout/random/mersenne_twister.hpp +++ b/sprout/random/mersenne_twister.hpp @@ -15,7 +15,11 @@ namespace sprout { // // mersenne_twister_engine // - template + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > class mersenne_twister_engine { public: typedef UIntType result_type; @@ -79,41 +83,55 @@ namespace sprout { : x_(x) , i_(i) {} - SPROUT_CONSTEXPR UIntType rewind_find_1(UIntType const* last, std::size_t size, std::size_t index) const { + SPROUT_CONSTEXPR UIntType + rewind_find_1(UIntType const* last, std::size_t size, std::size_t index) const { return index < n - size ? x_[index] : *(last - (n - 1 - index)) ; } - SPROUT_CONSTEXPR UIntType rewind_find(UIntType const* last, std::size_t size, std::size_t i) const { + SPROUT_CONSTEXPR UIntType + rewind_find(UIntType const* last, std::size_t size, std::size_t i) const { return rewind_find_1(last, size, (i + n - size + n - 1) % n); } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == n, sprout::array - >::type rewind_finish_1(sprout::array const& data, Args const&... args) const { + >::type + rewind_finish_1(sprout::array const& data, Args const&... args) const { return sprout::array{{args...}}; } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) < n, sprout::array - >::type rewind_finish_1(sprout::array const& data, Args const&... args) const { + >::type + rewind_finish_1(sprout::array const& data, Args const&... args) const { return rewind_finish_1(data, args..., data[sizeof...(args)]); } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == n, sprout::array - >::type rewind_finish(sprout::array const& data, UIntType const* last, std::size_t z, std::size_t i, Args const&... args) const { + >::type + rewind_finish( + sprout::array const& data, UIntType const* last, std::size_t z, std::size_t i, + Args const&... args + ) const + { return sprout::array{{args...}}; } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) < n, sprout::array - >::type rewind_finish(sprout::array const& data, UIntType const* last, std::size_t z, std::size_t i, Args const&... args) const { + >::type + rewind_finish( + sprout::array const& data, UIntType const* last, std::size_t z, std::size_t i, + Args const&... args + ) const + { return &data[0] + i == last - z ? rewind_finish_1(data, data[i], args...) : rewind_finish(data, last, z, i + 1, data[i], args...) @@ -123,21 +141,26 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == n, sprout::array - >::type rewind_4(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, Args const&... args) const { + >::type + rewind_4( + sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, + Args const&... args + ) const + { return sprout::array{{args...}}; } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) < n, sprout::array - >::type rewind_4(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, Args const&... args) const { + >::type + rewind_4( + sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, + Args const&... args + ) const + { return rewind_2( - data, - last, - z, - y1, - i, - (y0 & upper_mask) | (y1 & lower_mask), + data, last, z, y1, i, (y0 & upper_mask) | (y1 & lower_mask), args... ); } @@ -145,19 +168,26 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == n, sprout::array - >::type rewind_3(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, Args const&... args) const { + >::type + rewind_3( + sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, + Args const&... args + ) const + { return sprout::array{{args...}}; } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) < n, sprout::array - >::type rewind_3(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, Args const&... args) const { + >::type + rewind_3( + sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, UIntType y1, std::size_t i, + Args const&... args + ) const + { return rewind_4( - data, - last, - z, - y0, + data, last, z, y0, y1 & (static_cast(1) << (w - 1)) ? ((y1 ^ a) << 1) | 1 : y1 << 1 @@ -170,20 +200,31 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == n, sprout::array - >::type rewind_2(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, std::size_t i, Args const&... args) const { + >::type + rewind_2( + sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, std::size_t i, + Args const&... args + ) const + { return sprout::array{{args...}}; } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) < n, sprout::array - >::type rewind_2(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, std::size_t i, Args const&... args) const { + >::type + rewind_2( + sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0, std::size_t i, + Args const&... args + ) const + { return i < z ? rewind_3(data, last, z, y0, rewind_find(last, i, m - 1) ^ rewind_find(last, i, n - 1), i, args...) : rewind_finish(data, last, z, 0, args...) ; } - SPROUT_CONSTEXPR sprout::array rewind_1(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0) const { + SPROUT_CONSTEXPR sprout::array + rewind_1(sprout::array const& data, UIntType const* last, std::size_t z, UIntType y0) const { return rewind_2( data, last, @@ -195,10 +236,12 @@ namespace sprout { 0 ); } - SPROUT_CONSTEXPR sprout::array rewind(sprout::array const& data, UIntType const* last, std::size_t z) const { + SPROUT_CONSTEXPR sprout::array + rewind(sprout::array const& data, UIntType const* last, std::size_t z) const { return rewind_1(data, last, z, x_[m - 1] ^ x_[n - 1]); } - SPROUT_CONSTEXPR bool equal_impl_2(mersenne_twister_engine const& other, sprout::array back, std::size_t offset, std::size_t i = 0) const { + SPROUT_CONSTEXPR bool + equal_impl_2(mersenne_twister_engine const& other, sprout::array back, std::size_t offset, std::size_t i = 0) const { return i < offset ? back[i + n - offset] != other.x_[i] ? false @@ -206,7 +249,8 @@ namespace sprout { : true ; } - SPROUT_CONSTEXPR bool equal_impl_1(mersenne_twister_engine const& other, sprout::array back, std::size_t offset, std::size_t i = 0) const { + SPROUT_CONSTEXPR bool + equal_impl_1(mersenne_twister_engine const& other, sprout::array back, std::size_t offset, std::size_t i = 0) const { return i + offset < n ? x_[i] != other.x_[i + offset] ? false @@ -214,7 +258,8 @@ namespace sprout { : equal_impl_2(other, rewind(back, &back[n - 1], offset), offset) ; } - SPROUT_CONSTEXPR bool equal_impl(mersenne_twister_engine const& other) const { + SPROUT_CONSTEXPR bool + equal_impl(mersenne_twister_engine const& other) const { return equal_impl_1(other, sprout::array(), other.i_ - i_); } SPROUT_CONSTEXPR UIntType generate_impl_4(UIntType z) const { @@ -245,7 +290,9 @@ namespace sprout { template SPROUT_CONSTEXPR mersenne_twister_engine twist_5(Args const&... args) const { return mersenne_twister_engine( - sprout::array{{args..., x_[m - 1] ^ ((x_[n - 1] & upper_mask) | (x_[0] & lower_mask) >> 1) ^ ((x_[0] & 1) * a)}}, + sprout::array{{ + args..., x_[m - 1] ^ ((x_[n - 1] & upper_mask) | (x_[0] & lower_mask) >> 1) ^ ((x_[0] & 1) * a) + }}, 0, private_constructor_tag() ); @@ -262,7 +309,9 @@ namespace sprout { sizeof...(Args) < n - 1, mersenne_twister_engine >::type twist_4(std::size_t i, Args const&... args) const { - return twist_4(i + 1, args..., x_[i - (n - m)] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a)); + return twist_4( + i + 1, args..., x_[i - (n - m)] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a) + ); } template SPROUT_CONSTEXPR typename std::enable_if< @@ -276,7 +325,9 @@ namespace sprout { sizeof...(Args) < n - 1 - unroll_extra2, mersenne_twister_engine >::type twist_3(std::size_t i, Args const&... args) const { - return twist_3(i + 1, args..., x_[i - (n - m)] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a)); + return twist_3( + i + 1, args..., x_[i - (n - m)] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a) + ); } template SPROUT_CONSTEXPR typename std::enable_if< @@ -290,7 +341,9 @@ namespace sprout { sizeof...(Args) < n - m, mersenne_twister_engine >::type twist_2(std::size_t i, Args const&... args) const { - return twist_2(i + 1, args..., x_[i + m] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a)); + return twist_2( + i + 1, args..., x_[i + m] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a) + ); } template SPROUT_CONSTEXPR typename std::enable_if< @@ -304,7 +357,9 @@ namespace sprout { sizeof...(Args) < n - m - unroll_extra1, mersenne_twister_engine >::type twist_1(std::size_t i, Args const&... args) const { - return twist_1(i + 1, args..., x_[i + m] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a)); + return twist_1( + i + 1, args..., x_[i + m] ^ ((x_[i] & upper_mask) | (x_[i + 1] & lower_mask) >> 1) ^ ((x_[i + 1] & 1) * a) + ); } SPROUT_CONSTEXPR mersenne_twister_engine twist() const { return twist_1(0); @@ -371,34 +426,118 @@ namespace sprout { return lhs; } }; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::word_size; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::state_size; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::shift_size; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::mask_bits; - template - SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::mersenne_twister_engine::xor_mask; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::tempering_u; - template - SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::mersenne_twister_engine::tempering_d; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::tempering_s; - template - SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::mersenne_twister_engine::tempering_b; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::tempering_t; - template - SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::mersenne_twister_engine::tempering_c; - template - SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::random::mersenne_twister_engine::tempering_l; - template - SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::mersenne_twister_engine::initialization_multiplier; - template - SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::mersenne_twister_engine::default_seed; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::word_size + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::state_size + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::shift_size + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::mask_bits + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST UIntType + sprout::random::mersenne_twister_engine::xor_mask + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::tempering_u + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST UIntType + sprout::random::mersenne_twister_engine::tempering_d + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::tempering_s + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST UIntType + sprout::random::mersenne_twister_engine::tempering_b + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::tempering_t + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST UIntType + sprout::random::mersenne_twister_engine::tempering_c + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST std::size_t + sprout::random::mersenne_twister_engine::tempering_l + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST UIntType + sprout::random::mersenne_twister_engine::initialization_multiplier + ; + template< + typename UIntType, + std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, + std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f + > + SPROUT_CONSTEXPR_OR_CONST UIntType + sprout::random::mersenne_twister_engine::default_seed + ; // // mt11213b diff --git a/sprout/random/normal_distribution.hpp b/sprout/random/normal_distribution.hpp index 84fd1dd5..f4a1dd87 100644 --- a/sprout/random/normal_distribution.hpp +++ b/sprout/random/normal_distribution.hpp @@ -107,12 +107,8 @@ namespace sprout { bool valid_; private: SPROUT_CONSTEXPR normal_distribution( - RealType mean, - RealType sigma, - RealType r1, - RealType r2, - RealType cached_rho, - bool valid, + RealType mean, RealType sigma, RealType r1, RealType r2, + RealType cached_rho, bool valid, private_constructor_tag ) : mean_(mean) @@ -123,7 +119,8 @@ namespace sprout { , valid_(valid) {} template - SPROUT_CONSTEXPR sprout::random::random_result generate_2(Engine const& eng, RealType r1, RealType r2, RealType cached_rho, bool valid) const { + SPROUT_CONSTEXPR sprout::random::random_result + generate_2(Engine const& eng, RealType r1, RealType r2, RealType cached_rho, bool valid) const { return sprout::random::random_result( cached_rho * (valid @@ -144,15 +141,21 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR sprout::random::random_result generate_1_1(RealType r1, Random const& rnd) const { - return generate_2(rnd.engine(), r1, rnd.result(), sprout::sqrt(-result_type(2) * sprout::log(result_type(1) - rnd.result())), true); + SPROUT_CONSTEXPR sprout::random::random_result + generate_1_1(RealType r1, Random const& rnd) const { + return generate_2( + rnd.engine(), r1, rnd.result(), + sprout::sqrt(-result_type(2) * sprout::log(result_type(1) - rnd.result())), true + ); } template - SPROUT_CONSTEXPR sprout::random::random_result generate_1(Random const& rnd) const { + SPROUT_CONSTEXPR sprout::random::random_result + generate_1(Random const& rnd) const { return generate_1_1(rnd.result(), rnd()); } template - SPROUT_CONSTEXPR sprout::random::random_result generate(Engine const& eng) const { + SPROUT_CONSTEXPR sprout::random::random_result + generate(Engine const& eng) const { return !valid_ ? generate_1(sprout::random::uniform_01()(eng)) : generate_2(eng, r1_, r2_, cached_rho_, false) @@ -236,7 +239,11 @@ namespace sprout { return lhs << rhs.param() << " " << rhs.valid_ << " " << rhs.cached_rho_ << " " << rhs.r1_ << " " << rhs.r2_; } friend SPROUT_CONSTEXPR bool operator==(normal_distribution const& lhs, normal_distribution const& rhs) { - return lhs.param() == rhs.param() && lhs.valid_ == rhs.valid_ && lhs.cached_rho_ == rhs.cached_rho_ && lhs.r1_ == rhs.r1_ && lhs.r2_ == rhs.r2_; + return lhs.param() == rhs.param() + && lhs.valid_ == rhs.valid_ + && lhs.cached_rho_ == rhs.cached_rho_ + && lhs.r1_ == rhs.r1_ && lhs.r2_ == rhs.r2_ + ; } friend SPROUT_CONSTEXPR bool operator!=(normal_distribution const& lhs, normal_distribution const& rhs) { return !(lhs == rhs); diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index a823dab2..eaa6770d 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace sprout { namespace random { @@ -109,11 +110,16 @@ namespace sprout { SPROUT_CONSTEXPR result_type max() const { return distribution_.max(); } - void swap(random_result& other) { - using std::swap; - swap(result_, other.result_); - swap(engine_, other.engine_); - swap(distribution_, other.distribution_); + void swap(random_result& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(result_, other.result_)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(engine_, other.engine_)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(distribution_, other.distribution_)) + ) + { + sprout::swap(result_, other.result_); + sprout::swap(engine_, other.engine_); + sprout::swap(distribution_, other.distribution_); } friend SPROUT_CONSTEXPR bool operator==(random_result const& lhs, random_result const& rhs) { return lhs.result_ == rhs.result_ @@ -231,10 +237,14 @@ namespace sprout { friend SPROUT_CONSTEXPR bool operator!=(random_result const& lhs, random_result const& rhs) { return !(lhs == rhs); } - void swap(random_result& other) { - using std::swap; - swap(result_, other.result_); - swap(engine_, other.engine_); + void swap(random_result& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(result_, other.result_)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(engine_, other.engine_)) + ) + { + sprout::swap(result_, other.result_); + sprout::swap(engine_, other.engine_); } SPROUT_CONSTEXPR reference operator*() const { return result_; @@ -259,10 +269,9 @@ namespace sprout { // swap // template - void swap( - sprout::random::random_result& lhs, - sprout::random::random_result& rhs - ) + inline void + swap(sprout::random::random_result& lhs, sprout::random::random_result& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } @@ -271,7 +280,7 @@ namespace sprout { // iterator_next // template - SPROUT_CONSTEXPR sprout::random::random_result + inline SPROUT_CONSTEXPR sprout::random::random_result iterator_next(sprout::random::random_result const& it) { return it(); } diff --git a/sprout/random/uniform_int_distribution.hpp b/sprout/random/uniform_int_distribution.hpp index 5ca2de27..6aa68738 100644 --- a/sprout/random/uniform_int_distribution.hpp +++ b/sprout/random/uniform_int_distribution.hpp @@ -22,30 +22,19 @@ namespace sprout { }; template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int( - Engine const& eng, - T min_value, - T max_value, - std::true_type - ); + SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int(Engine const& eng, T min_value, T max_value, std::true_type); template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_3_1( - sprout::random::random_result const& rnd, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - BaseUnsigned bucket_size + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_3_1( + sprout::random::random_result const& rnd, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, BaseUnsigned bucket_size ); template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_3_1_1( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - BaseUnsigned bucket_size, - BaseUnsigned result + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_3_1_1( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, BaseUnsigned bucket_size, BaseUnsigned result ) { typedef T result_type; @@ -55,50 +44,34 @@ namespace sprout { eng } : generate_uniform_int_true_3_1( - eng(), - min_value, - range, - bmin, - brange, - bucket_size + eng(), min_value, range, + bmin, brange, bucket_size ) ; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_3_1( - sprout::random::random_result const& rnd, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - BaseUnsigned bucket_size + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_3_1( + sprout::random::random_result const& rnd, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, BaseUnsigned bucket_size ) { return sprout::random::detail::generate_uniform_int_true_3_1_1( - rnd.engine(), - min_value, - range, - bmin, - brange, - bucket_size, + rnd.engine(), min_value, range, + bmin, brange, bucket_size, sprout::random::detail::subtract()(rnd.result(), bmin) / bucket_size ); } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_3( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_3( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange ) { return sprout::random::detail::generate_uniform_int_true_3_1( - eng(), - min_value, - range, - bmin, - brange, + eng(), min_value, range, + bmin, brange, brange == std::numeric_limits::max() ? brange / (static_cast(range) + 1) + ( brange % (static_cast(range) + 1) == static_cast(range) ? 1 : 0 @@ -107,22 +80,16 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange + SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange ); template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2_4( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - RangeType result, - RangeType result_increment + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2_4( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, RangeType result, RangeType result_increment ) { typedef T result_type; @@ -135,74 +102,44 @@ namespace sprout { ; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2_3( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - RangeType result, - RangeType mult, - RangeType result_increment + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2_3( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, RangeType result, RangeType mult, RangeType result_increment ) { return std::numeric_limits::max() / mult < result_increment ? sprout::random::detail::generate_uniform_int_true_2(eng, min_value, range, bmin, brange) : generate_uniform_int_true_2_4( - eng, - min_value, - range, - bmin, - brange, - result + (result_increment * mult), - result_increment * mult + eng, min_value, range, + bmin, brange, result + (result_increment * mult), result_increment * mult ) ; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2_2( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - RangeType result, - RangeType mult, - Result const& result_increment_base + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2_2( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, RangeType result, RangeType mult, Result const& result_increment_base ) { return sprout::random::detail::generate_uniform_int_true_2_3( - result_increment_base.engine, - min_value, - range, - bmin, - brange, - result, - mult, - result_increment_base.result + result_increment_base.engine, min_value, range, + bmin, brange, result, mult, result_increment_base.result ); } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2_1( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - RangeType limit, - RangeType result = RangeType(0), - RangeType mult = RangeType(1) + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2_1( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, RangeType limit, + RangeType result = RangeType(0), RangeType mult = RangeType(1) ); template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2_1_1( - sprout::random::random_result const& rnd, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - RangeType limit, - RangeType result, - RangeType mult + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2_1_1( + sprout::random::random_result const& rnd, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, RangeType limit, RangeType result, RangeType mult ) { return mult * RangeType(brange) == range - mult + 1 @@ -213,48 +150,31 @@ namespace sprout { rnd.engine() } : sprout::random::detail::generate_uniform_int_true_2_1( - rnd.engine(), - min_value, - range, - bmin, - brange, - limit, + rnd.engine(), min_value, range, + bmin, brange, limit, result + static_cast(sprout::random::detail::subtract()(rnd.result(), bmin) * mult), mult * (RangeType(brange) + RangeType(1)) ) ; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2_1( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange, - RangeType limit, - RangeType result, - RangeType mult + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2_1( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange, RangeType limit, + RangeType result, RangeType mult ) { return mult <= limit ? generate_uniform_int_true_2_1_1( - eng(), - min_value, - range, - bmin, - brange, - limit, - result, - mult + eng(), min_value, range, + bmin, brange, limit, + result, mult ) : sprout::random::detail::generate_uniform_int_true_2_2( - eng, - min_value, - range, - bmin, - brange, - result, - mult, + eng, min_value, range, + bmin, brange, + result, mult, sprout::random::detail::generate_uniform_int( eng, static_cast(0), @@ -265,20 +185,15 @@ namespace sprout { ; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_2( - Engine const& eng, - T min_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_2( + Engine const& eng, T min_value, RangeType range, + BaseResult bmin, BaseUnsigned brange ) { return sprout::random::detail::generate_uniform_int_true_2_1( - eng, - min_value, - range, - bmin, - brange, + eng, min_value, range, + bmin, brange, range == std::numeric_limits::max() ? range / (RangeType(brange) + 1) + ( range % (RangeType(brange) + 1) == RangeType(brange) ? 1 : 0 @@ -287,10 +202,9 @@ namespace sprout { ); } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_1_1( - sprout::random::random_result const& rnd, - T min_value, - BaseResult bmin + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_1_1( + sprout::random::random_result const& rnd, T min_value, BaseResult bmin ) { typedef T result_type; @@ -304,13 +218,10 @@ namespace sprout { }; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_true_1( - Engine const& eng, - T min_value, - T max_value, - RangeType range, - BaseResult bmin, - BaseUnsigned brange + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_true_1( + Engine const& eng, T min_value, T max_value, RangeType range, + BaseResult bmin, BaseUnsigned brange ) { return range == 0 ? sprout::random::detail::generate_uniform_int_result{min_value, eng} @@ -320,11 +231,9 @@ namespace sprout { ; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int( - Engine const& eng, - T min_value, - T max_value, - std::true_type + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int( + Engine const& eng, T min_value, T max_value, std::true_type ) { typedef T result_type; @@ -332,52 +241,41 @@ namespace sprout { typedef typename Engine::result_type base_result; typedef typename std::make_unsigned::type base_unsigned; return sprout::random::detail::generate_uniform_int_true_1( - eng, - min_value, - max_value, + eng, min_value, max_value, range_type(sprout::random::detail::subtract()(max_value, min_value)), base_result(eng.min()), base_unsigned(sprout::random::detail::subtract()(eng.max(), eng.min())) ); } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int_false_1( - Result const& rnd - ) - { + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int_false_1(Result const& rnd) { return sprout::random::detail::generate_uniform_int_result{ - rnd.result, - rnd.engine.base() + rnd.result, rnd.engine.base() }; } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int( - Engine const& eng, - T min_value, - T max_value, - std::false_type + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int( + Engine const& eng, T min_value, T max_value, std::false_type ) { return generate_uniform_int_false_1( sprout::random::detail::generate_uniform_int( sprout::random::detail::uniform_int_float(eng), - min_value, - max_value, + min_value, max_value, std::true_type() ) ); } template - SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result generate_uniform_int( - Engine const& eng, - T min_value, - T max_value + inline SPROUT_CONSTEXPR sprout::random::detail::generate_uniform_int_result + generate_uniform_int( + Engine const& eng, T min_value, T max_value ) { return sprout::random::detail::generate_uniform_int( - eng, - min_value, - max_value, + eng, min_value, max_value, std::is_integral() ); } @@ -395,8 +293,7 @@ namespace sprout { return min_arg <= max_arg; } static SPROUT_CONSTEXPR IntType arg_check(IntType min_arg, IntType max_arg) { - return arg_check_nothrow(min_arg, max_arg) - ? min_arg + return arg_check_nothrow(min_arg, max_arg) ? min_arg : throw std::invalid_argument("uniform_int_distribution<>: invalid argument (min_arg <= max_arg)") ; } diff --git a/sprout/random/unique_seed.hpp b/sprout/random/unique_seed.hpp index 74f13429..8fe965af 100644 --- a/sprout/random/unique_seed.hpp +++ b/sprout/random/unique_seed.hpp @@ -13,7 +13,8 @@ namespace sprout { // make_seed // template - SPROUT_CONSTEXPR std::size_t make_seed(T const& v) { + SPROUT_CONSTEXPR std::size_t + make_seed(T const& v) { return sprout::to_hash(v); } @@ -22,14 +23,16 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) + 1 == N, sprout::array - >::type make_seed_seq_impl(T const& v, std::size_t seed, Args const&... args) { + >::type + make_seed_seq_impl(T const& v, std::size_t seed, Args const&... args) { return sprout::array{{args..., seed}}; } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) + 1 != N, sprout::array - >::type make_seed_seq_impl(T const& v, std::size_t seed, Args const&... args) { + >::type + make_seed_seq_impl(T const& v, std::size_t seed, Args const&... args) { return sprout::detail::make_seed_seq_impl(v, sprout::hash_combine(seed, v), args..., seed); } } // namespace detail @@ -37,7 +40,8 @@ namespace sprout { // make_seed_seq // template - SPROUT_CONSTEXPR sprout::array make_seed_seq(T const& v) { + SPROUT_CONSTEXPR sprout::array + make_seed_seq(T const& v) { return sprout::detail::make_seed_seq_impl(v, sprout::to_hash(v)); } } // namespace sprout diff --git a/sprout/range/algorithm/adjacent_find.hpp b/sprout/range/algorithm/adjacent_find.hpp index a1e4786d..04dfcc82 100644 --- a/sprout/range/algorithm/adjacent_find.hpp +++ b/sprout/range/algorithm/adjacent_find.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/equal_range.hpp b/sprout/range/algorithm/equal_range.hpp index 8f5f10a6..aabd717e 100644 --- a/sprout/range/algorithm/equal_range.hpp +++ b/sprout/range/algorithm/equal_range.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/find.hpp b/sprout/range/algorithm/find.hpp index 07b89f84..e2aec459 100644 --- a/sprout/range/algorithm/find.hpp +++ b/sprout/range/algorithm/find.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/find_end.hpp b/sprout/range/algorithm/find_end.hpp index a03fb3fa..4a8b013e 100644 --- a/sprout/range/algorithm/find_end.hpp +++ b/sprout/range/algorithm/find_end.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/find_first_of.hpp b/sprout/range/algorithm/find_first_of.hpp index e0175284..520d9c94 100644 --- a/sprout/range/algorithm/find_first_of.hpp +++ b/sprout/range/algorithm/find_first_of.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/find_if.hpp b/sprout/range/algorithm/find_if.hpp index 7685f11b..0c3cd83d 100644 --- a/sprout/range/algorithm/find_if.hpp +++ b/sprout/range/algorithm/find_if.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/find_if_not.hpp b/sprout/range/algorithm/find_if_not.hpp index 3d966521..6d074ada 100644 --- a/sprout/range/algorithm/find_if_not.hpp +++ b/sprout/range/algorithm/find_if_not.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/is_heap_until.hpp b/sprout/range/algorithm/is_heap_until.hpp index 4f1e19b9..062fa5d6 100644 --- a/sprout/range/algorithm/is_heap_until.hpp +++ b/sprout/range/algorithm/is_heap_until.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/is_sorted_until.hpp b/sprout/range/algorithm/is_sorted_until.hpp index 1ab86fa5..af93a351 100644 --- a/sprout/range/algorithm/is_sorted_until.hpp +++ b/sprout/range/algorithm/is_sorted_until.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/lower_bound.hpp b/sprout/range/algorithm/lower_bound.hpp index f553d9e7..975d6673 100644 --- a/sprout/range/algorithm/lower_bound.hpp +++ b/sprout/range/algorithm/lower_bound.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/max_element.hpp b/sprout/range/algorithm/max_element.hpp index 06e21275..ead5dd9a 100644 --- a/sprout/range/algorithm/max_element.hpp +++ b/sprout/range/algorithm/max_element.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/min_element.hpp b/sprout/range/algorithm/min_element.hpp index caff9398..0ef0b8b0 100644 --- a/sprout/range/algorithm/min_element.hpp +++ b/sprout/range/algorithm/min_element.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/minmax_element.hpp b/sprout/range/algorithm/minmax_element.hpp index f8123876..f0dfcaea 100644 --- a/sprout/range/algorithm/minmax_element.hpp +++ b/sprout/range/algorithm/minmax_element.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include diff --git a/sprout/range/algorithm/mismatch.hpp b/sprout/range/algorithm/mismatch.hpp index 4dc7edbd..e10ce60c 100644 --- a/sprout/range/algorithm/mismatch.hpp +++ b/sprout/range/algorithm/mismatch.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include diff --git a/sprout/range/algorithm/partition_point.hpp b/sprout/range/algorithm/partition_point.hpp index 71dafbb7..3767ee75 100644 --- a/sprout/range/algorithm/partition_point.hpp +++ b/sprout/range/algorithm/partition_point.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/search.hpp b/sprout/range/algorithm/search.hpp index 844a9ea9..a1a9b087 100644 --- a/sprout/range/algorithm/search.hpp +++ b/sprout/range/algorithm/search.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/search_n.hpp b/sprout/range/algorithm/search_n.hpp index 4245d3f1..3b5f5257 100644 --- a/sprout/range/algorithm/search_n.hpp +++ b/sprout/range/algorithm/search_n.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/algorithm/upper_bound.hpp b/sprout/range/algorithm/upper_bound.hpp index 344e3a08..eea8d289 100644 --- a/sprout/range/algorithm/upper_bound.hpp +++ b/sprout/range/algorithm/upper_bound.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/range/range_container.hpp b/sprout/range/range_container.hpp index 8de7f0d1..cd1dc3b9 100644 --- a/sprout/range/range_container.hpp +++ b/sprout/range/range_container.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace sprout { namespace range { @@ -39,10 +40,14 @@ namespace sprout { {} template - void swap(range_container& other) { - using std::swap; - swap(other.first_, first_); - swap(other.last_, last_); + void swap(range_container& other) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(other.first_, first_)) + && SPROUT_NOEXCEPT_EXPR(sprout::swap(other.last_, last_)) + ) + { + sprout::swap(other.first_, first_); + sprout::swap(other.last_, last_); } // iterators: SPROUT_CONSTEXPR iterator begin() const { diff --git a/sprout/range/range_return.hpp b/sprout/range/range_return.hpp index 77fdf524..24e9b0ce 100644 --- a/sprout/range/range_return.hpp +++ b/sprout/range/range_return.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/sprout/rational.hpp b/sprout/rational.hpp index df1da97c..e5980f84 100644 --- a/sprout/rational.hpp +++ b/sprout/rational.hpp @@ -1,725 +1,14 @@ #ifndef SPROUT_RATIONAL_HPP #define SPROUT_RATIONAL_HPP -#include -#include -#include -#include -#include #include -#include -#include -#include -#include - -namespace sprout { - // - // bad_rational - // - class bad_rational - : public std::domain_error - { - public: - explicit bad_rational() - : std::domain_error("bad rational: zero denominator") - {} - }; - - template - class rational; - - namespace detail { - struct rational_private_constructor_tag {}; - - template - inline SPROUT_CONSTEXPR sprout::rational make_rational( - typename sprout::detail::call_traits::param_type n, - typename sprout::detail::call_traits::param_type d, - sprout::detail::rational_private_constructor_tag - ); - } // namespace detail - - namespace detail { - template - class rational_impl { - protected: - typedef IntType int_type; - typedef typename sprout::detail::call_traits::param_type param_type; - protected: - IntType num_; - IntType den_; - protected: - SPROUT_CONSTEXPR rational_impl() - : num_(0) - , den_(1) - {} - rational_impl(rational_impl const&) = default; - SPROUT_CONSTEXPR rational_impl(param_type n) - : num_(n) - , den_(1) - {} - SPROUT_CONSTEXPR rational_impl(param_type n, param_type d) - : num_(n) - , den_(d) - {} - SPROUT_CONSTEXPR rational_impl(param_type n, param_type d, param_type g) - : num_(n / g) - , den_(d / g) - {} - }; - } // namespace detail - - // - // rational - // - template - class rational - : private sprout::detail::rational_impl - { - static_assert(std::numeric_limits::is_specialized, "std::numeric_limits::is_specialized"); - public: - typedef IntType int_type; - typedef typename sprout::detail::call_traits::param_type param_type; - private: - struct private_constructor_tag {}; - typedef sprout::detail::rational_impl base_type; - private: - static SPROUT_CONSTEXPR IntType normalize_g_1(IntType den, IntType g) { - return den / g < 0 ? -g : g; - } - static SPROUT_CONSTEXPR IntType normalize_g(IntType num, IntType den) { - return den == 0 ? throw sprout::bad_rational() - : num == 0 ? den - : normalize_g_1(den, sprout::math::gcd(num, den)) - ; - } - private: - using base_type::num_; - using base_type::den_; - private: - SPROUT_CONSTEXPR rational(param_type n, param_type d, private_constructor_tag) - : base_type(n, d) - {} - public: - SPROUT_CONSTEXPR rational() - : base_type() - {} - rational(rational const&) = default; - SPROUT_CONSTEXPR rational(param_type n) - : base_type(n) - {} - SPROUT_CONSTEXPR rational(param_type n, param_type d) - : base_type(n, d, normalize_g(n, d)) - {} - - rational& operator=(rational const&) = default; - rational& operator=(param_type n) { - return assign(n, 1); - } - rational& assign(param_type n, param_type d) { - using std::swap; - rational temp(n, d); - swap(temp, *this); - return *this; - } - - SPROUT_CONSTEXPR IntType numerator() const { - return num_; - } - SPROUT_CONSTEXPR IntType denominator() const { - return den_; - } - - rational& operator+=(rational const& rhs) { - IntType g = sprout::math::gcd(den_, rhs.den_); - den_ /= g; - num_ = num_ * (rhs.den_ / g) + rhs.num_ * den_; - g = sprout::math::gcd(num_, g); - num_ /= g; - den_ *= rhs.den_ / g; - return *this; - } - rational& operator-=(rational const& rhs) { - IntType g = sprout::math::gcd(den_, rhs.den_); - den_ /= g; - num_ = num_ * (rhs.den_ / g) - rhs.num_ * den_; - g = sprout::math::gcd(num_, g); - num_ /= g; - den_ *= rhs.den_ / g; - return *this; - } - rational& operator*=(rational const& rhs) { - IntType gcd1 = sprout::math::gcd(num_, rhs.den_); - IntType gcd2 = sprout::math::gcd(rhs.num_, den_); - num_ =(num_ / gcd1) * (rhs.num_ / gcd2); - den_ =(den_ / gcd2) * (rhs.den_ / gcd1); - return *this; - } - rational& operator/=(rational const& rhs) { - if (rhs.num_ == IntType(0)) { - throw bad_rational(); - } - if (num_ == IntType(0)) { - return *this; - } - IntType gcd1 = sprout::math::gcd(num_, rhs.num_); - IntType gcd2 = sprout::math::gcd(rhs.den_, den_); - num_ =(num_ / gcd1) * (rhs.den_ / gcd2); - den_ =(den_ / gcd2) * (rhs.num_ / gcd1); - if (den_ < IntType(0)) { - num_ = -num_; - den_ = -den_; - } - return *this; - } - rational& operator+=(param_type rhs) { - return *this += rational(rhs); - } - rational& operator-=(param_type rhs) { - return *this -= rational(rhs); - } - rational& operator*=(param_type rhs) { - return *this *= rational(rhs); - } - rational& operator/=(param_type rhs) { - return *this /= rational(rhs); - } - - rational& operator++() { - num_ += den_; - return *this; - } - rational& operator--() { - num_ -= den_; - return *this; - } - rational operator++(int) { - rational result(*this); - ++*this; - return result; - } - rational operator--(int) { - rational result(*this); - --*this; - return result; - } - - SPROUT_CONSTEXPR bool operator!() const { - return !num_; - } - SPROUT_CONSTEXPR operator bool() const { - return num_ != 0; - } - - public: - friend sprout::rational sprout::detail::make_rational( - typename sprout::detail::call_traits::param_type n, - typename sprout::detail::call_traits::param_type d, - sprout::detail::rational_private_constructor_tag - ); - }; - - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::rational make_rational( - typename sprout::detail::call_traits::param_type n, - typename sprout::detail::call_traits::param_type d, - sprout::detail::rational_private_constructor_tag - ) - { - return sprout::rational( - n, d, - typename sprout::rational::private_constructor_tag() - ); - } - } // namespace detail - - // - // operator+ - // operator- - // - template - inline SPROUT_CONSTEXPR sprout::rational - operator+(rational const& r) { - return r; - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator-(rational const& r) { - return sprout::detail::make_rational( - -r.numerator(), r.denominator(), - sprout::detail::rational_private_constructor_tag() - ); - } - - // - // operator+ - // operator- - // operator* - // operator/ - // - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::rational - rational_add_impl_3( - sprout::rational const& rhs, - IntType g, IntType den, IntType num - ) - { - return sprout::detail::make_rational( - num / g, den * (rhs.denominator() / g), - sprout::detail::rational_private_constructor_tag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - rational_add_impl_2( - sprout::rational const& rhs, - IntType g, IntType den, IntType num - ) - { - return rational_add_impl_3( - rhs, - sprout::math::gcd(num, g), den, num - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - rational_add_impl_1( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType g, IntType den - ) - { - return rational_add_impl_2( - rhs, - g, den, lhs.numerator() * (rhs.denominator() / g) + rhs.numerator() * den - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - rational_add_impl( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType g - ) - { - return rational_add_impl_1( - lhs, rhs, - g, lhs.denominator() / g - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::rational - operator+(sprout::rational const& lhs, sprout::rational const& rhs) { - return sprout::detail::rational_add_impl( - lhs, rhs, - sprout::math::gcd(lhs.denominator(), rhs.denominator()) - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator+(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return lhs + sprout::rational(rhs); - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator+(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return sprout::rational(lhs) + rhs; - } - - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::rational - rational_sub_impl_3( - sprout::rational const& rhs, - IntType g, IntType den, IntType num - ) - { - return sprout::detail::make_rational( - num / g, den * (rhs.denominator() / g), - sprout::detail::rational_private_constructor_tag() - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - rational_sub_impl_2( - sprout::rational const& rhs, - IntType g, IntType den, IntType num - ) - { - return rational_sub_impl_3( - rhs, - sprout::math::gcd(num, g), den, num - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - rational_sub_impl_1( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType g, IntType den - ) - { - return rational_sub_impl_2( - rhs, - g, den, lhs.numerator() * (rhs.denominator() / g) - rhs.numerator() * den - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - rational_sub_impl( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType g - ) - { - return rational_sub_impl_1( - lhs, rhs, - g, lhs.denominator() / g - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::rational - operator-(sprout::rational const& lhs, sprout::rational const& rhs) { - return sprout::detail::rational_sub_impl( - lhs, rhs, - sprout::math::gcd(lhs.denominator(), rhs.denominator()) - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator-(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return lhs - sprout::rational(rhs); - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator-(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return sprout::rational(lhs) - rhs; - } - - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::rational - rational_mul_impl( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType gcd1, IntType gcd2 - ) - { - return sprout::detail::make_rational( - (lhs.numerator() / gcd1) * (rhs.numerator() / gcd2), - (lhs.denominator() / gcd2) * (rhs.denominator() / gcd1), - sprout::detail::rational_private_constructor_tag() - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::rational - operator*(sprout::rational const& lhs, sprout::rational const& rhs) { - return sprout::detail::rational_mul_impl( - lhs, rhs, - sprout::math::gcd(lhs.numerator(), rhs.denominator()), - sprout::math::gcd(rhs.numerator(), lhs.denominator()) - ); - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator*(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return lhs * sprout::rational(rhs); - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator*(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return sprout::rational(lhs) * rhs; - } - - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::rational - rational_div_impl_1(IntType num, IntType den) { - return den < IntType(0) ? sprout::detail::make_rational( - -num, -den, - sprout::detail::rational_private_constructor_tag() - ) - : sprout::detail::make_rational( - num, den, - sprout::detail::rational_private_constructor_tag() - ) - ; - } - template - inline SPROUT_CONSTEXPR sprout::rational - rational_div_impl( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType gcd1, IntType gcd2 - ) - { - return sprout::detail::rational_div_impl_1( - (lhs.numerator() / gcd1) * (rhs.denominator() / gcd2), - (lhs.denominator() / gcd2) * (rhs.numerator() / gcd1) - ); - } - } // namespace detail - template - inline SPROUT_CONSTEXPR sprout::rational - operator/(sprout::rational const& lhs, sprout::rational const& rhs) { - return rhs.numerator() == IntType(0) ? throw sprout::bad_rational() - : lhs.numerator() == IntType(0) ? lhs - : sprout::detail::rational_div_impl( - lhs, rhs, - sprout::math::gcd(lhs.numerator(), rhs.numerator()), - sprout::math::gcd(rhs.denominator(), lhs.denominator()) - ) - ; - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator/(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return lhs / sprout::rational(rhs); - } - template - inline SPROUT_CONSTEXPR sprout::rational - operator/(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return sprout::rational(lhs) / rhs; - } - - // - // operator== - // operator!= - // - template - inline SPROUT_CONSTEXPR bool - operator==(sprout::rational const& lhs, sprout::rational const& rhs) { - return lhs.numerator() == rhs.numerator() && lhs.denominator() == rhs.denominator(); - } - template - inline SPROUT_CONSTEXPR bool - operator==(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return lhs.denominator() == IntType(1) && lhs.numerator() == rhs; - } - template - inline SPROUT_CONSTEXPR bool - operator==(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return rhs == lhs; - } - template - inline SPROUT_CONSTEXPR bool - operator!=(sprout::rational const& lhs, sprout::rational const& rhs) { - return !(lhs == rhs); - } - template - inline SPROUT_CONSTEXPR bool - operator!=(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return !(lhs == rhs); - } - template - inline SPROUT_CONSTEXPR bool - operator!=(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return !(lhs == rhs); - } - - // - // operator< - // operator> - // operator<= - // operator>= - // - namespace detail { - template - inline SPROUT_CONSTEXPR bool - rational_less_impl_2( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType d1, IntType q1, IntType r1, - IntType d2, IntType q2, IntType r2, - unsigned reverse = 0 - ) - { - return q1 != q2 ? reverse ? q1 > q2 : q1 < q2 - : r1 == IntType(0) || r2 == IntType(0) - ? r1 == r2 ? false - : (r1 != IntType(0)) != static_cast(reverse ^ 1) - : sprout::detail::rational_less_impl_2( - lhs, rhs, - r1, d1 / r1, d1 % r1, - r2, d2 / r2, d2 % r2, - reverse ^ 1 - ) - ; - } - template - inline SPROUT_CONSTEXPR bool - rational_less_impl_1( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType d1, IntType q1, IntType r1, - IntType d2, IntType q2, IntType r2 - ) - { - return r2 < IntType(0) ? sprout::detail::rational_less_impl_1( - lhs, rhs, - d1, q1, r1, - d2, q2 - 1, r2 + d2 - ) - : sprout::detail::rational_less_impl_2( - lhs, rhs, - d1, q1, r1, - d2, q2, r2 - ) - ; - } - template - inline SPROUT_CONSTEXPR bool - rational_less_impl( - sprout::rational const& lhs, sprout::rational const& rhs, - IntType d1, IntType q1, IntType r1 - ) - { - return r1 < IntType(0) ? sprout::detail::rational_less_impl( - lhs, rhs, - d1, q1 - 1, r1 + d1 - ) - : sprout::detail::rational_less_impl_1( - lhs, rhs, - d1, q1, r1, - rhs.denominator(), rhs.numerator() / rhs.denominator(), rhs.numerator() % rhs.denominator() - ) - ; - } - - template - inline SPROUT_CONSTEXPR bool - rational_less_impl( - sprout::rational const& lhs, typename sprout::rational::param_type rhs, - IntType q, IntType r - ) - { - return r < IntType(0) ? sprout::detail::rational_less_impl( - lhs, rhs, - r + lhs.denominator(), q - 1 - ) - : q < rhs - ; - } - } // namespace detail - template - inline SPROUT_CONSTEXPR bool - operator<(sprout::rational const& lhs, sprout::rational const& rhs) { - return sprout::detail::rational_less_impl( - lhs, rhs, - lhs.denominator(), lhs.numerator() / lhs.denominator(), lhs.numerator() % lhs.denominator() - ); - } - template - inline SPROUT_CONSTEXPR bool - operator<(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return sprout::detail::rational_less_impl( - lhs, rhs, - lhs.numerator() / lhs.denominator(), lhs.numerator() % lhs.denominator() - ); - } - template - inline SPROUT_CONSTEXPR bool - operator<(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return lhs != rhs && !(rhs < lhs); - } - - template - inline SPROUT_CONSTEXPR bool - operator>(sprout::rational const& lhs, sprout::rational const& rhs) { - return rhs < lhs; - } - template - inline SPROUT_CONSTEXPR bool - operator>(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return rhs < lhs; - } - template - inline SPROUT_CONSTEXPR bool - operator>(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return rhs < lhs; - } - - template - inline SPROUT_CONSTEXPR bool - operator<=(sprout::rational const& lhs, sprout::rational const& rhs) { - return !(rhs < lhs); - } - template - inline SPROUT_CONSTEXPR bool - operator<=(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return !(rhs < lhs); - } - template - inline SPROUT_CONSTEXPR bool - operator<=(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return !(rhs < lhs); - } - - template - inline SPROUT_CONSTEXPR bool - operator>=(sprout::rational const& lhs, sprout::rational const& rhs) { - return !(lhs < rhs); - } - template - inline SPROUT_CONSTEXPR bool - operator>=(sprout::rational const& lhs, typename sprout::rational::param_type rhs) { - return !(lhs < rhs); - } - template - inline SPROUT_CONSTEXPR bool - operator>=(typename sprout::rational::param_type lhs, sprout::rational const& rhs) { - return !(lhs < rhs); - } - - // - // operator>> - // operator<< - // - template - inline std::basic_istream& - operator>>(std::basic_istream& lhs, sprout::rational& rhs) { - IntType n = IntType(0); - IntType d = IntType(1); - Elem c = 0; - sprout::detail::io::ios_flags_saver saver(lhs); - lhs >> n; - c = lhs.get(); - if (c != Elem('/')) { - lhs.clear(std::istream::badbit); - } - lhs >> std::noskipws; - lhs >> d; - if (lhs) { - rhs.assign(n, d); - } - return lhs; - } - template - inline std::basic_ostream& - operator<<(std::basic_ostream& lhs, sprout::rational const& rhs) { - return lhs << rhs.numerator() << Elem('/') << rhs.denominator(); - } - - // - // rational_cast - // - template - inline SPROUT_CONSTEXPR T - rational_cast(sprout::rational const& src) { - return static_cast(src.numerator()) / static_cast(src.denominator()); - } - - // - // abs - // - template - inline SPROUT_CONSTEXPR sprout::rational - abs(sprout::rational const& x) { - return x.numerator() >= IntType(0) ? x - : sprout::detail::make_rational( - -x.numerator(), x.denominator(), - sprout::detail::rational_private_constructor_tag() - ) - ; - } - -} // namespace sprout +#include +#include +#include +#include +#include +#include +#include +#include #endif // SPROUT_RATIONAL_HPP diff --git a/sprout/rational/hash.hpp b/sprout/rational/hash.hpp index d58ae4c4..6864917a 100644 --- a/sprout/rational/hash.hpp +++ b/sprout/rational/hash.hpp @@ -11,7 +11,8 @@ namespace sprout { // hash_value // template - inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::rational const& v) { + inline SPROUT_CONSTEXPR std::size_t + hash_value(sprout::rational const& v) { return sprout::hash_values(v.numerator(), v.denominator()); } } // namespace sprout diff --git a/sprout/rational/rational.hpp b/sprout/rational/rational.hpp index 46846695..b4963f86 100644 --- a/sprout/rational/rational.hpp +++ b/sprout/rational/rational.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace sprout { @@ -101,9 +102,8 @@ namespace sprout { return assign(n, 1); } rational& assign(param_type n, param_type d) { - using std::swap; rational temp(n, d); - swap(temp, *this); + sprout::swap(temp, *this); return *this; } @@ -194,7 +194,6 @@ namespace sprout { SPROUT_CONSTEXPR operator bool() const { return num_ != 0; } - public: friend sprout::rational sprout::detail::make_rational( typename sprout::detail::call_traits::param_type n, @@ -205,7 +204,8 @@ namespace sprout { namespace detail { template - inline SPROUT_CONSTEXPR sprout::rational make_rational( + inline SPROUT_CONSTEXPR sprout::rational + make_rational( typename sprout::detail::call_traits::param_type n, typename sprout::detail::call_traits::param_type d, sprout::detail::rational_private_constructor_tag diff --git a/sprout/string/comparison.hpp b/sprout/string/comparison.hpp index bbef6f16..cad764f0 100644 --- a/sprout/string/comparison.hpp +++ b/sprout/string/comparison.hpp @@ -15,75 +15,93 @@ namespace sprout { // operator>= // template - inline SPROUT_CONSTEXPR bool operator==(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator==(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { return lhs.compare(rhs) == 0; } template - inline SPROUT_CONSTEXPR bool operator==(sprout::basic_string const& lhs, T const* rhs) { + inline SPROUT_CONSTEXPR bool + operator==(sprout::basic_string const& lhs, T const* rhs) { return lhs.compare(rhs) == 0; } template - inline SPROUT_CONSTEXPR bool operator==(T const* lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator==(T const* lhs, sprout::basic_string const& rhs) { return 0 == rhs.compare(lhs); } template - inline SPROUT_CONSTEXPR bool operator!=(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator!=(sprout::basic_string const& lhs, T const* rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::basic_string const& lhs, T const* rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator!=(T const* lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator!=(T const* lhs, sprout::basic_string const& rhs) { return !(lhs == rhs); } template - inline SPROUT_CONSTEXPR bool operator<(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { return lhs.compare(rhs) < 0; } template - inline SPROUT_CONSTEXPR bool operator<(sprout::basic_string const& lhs, T const* rhs) { + inline SPROUT_CONSTEXPR bool + operator<(sprout::basic_string const& lhs, T const* rhs) { return lhs.compare(rhs) < 0; } template - inline SPROUT_CONSTEXPR bool operator<(T const* lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<(T const* lhs, sprout::basic_string const& rhs) { return 0 < rhs.compare(lhs); } template - inline SPROUT_CONSTEXPR bool operator>(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator>(sprout::basic_string const& lhs, T const* rhs) { + inline SPROUT_CONSTEXPR bool + operator>(sprout::basic_string const& lhs, T const* rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator>(T const* lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>(T const* lhs, sprout::basic_string const& rhs) { return rhs < lhs; } template - inline SPROUT_CONSTEXPR bool operator<=(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator<=(sprout::basic_string const& lhs, T const* rhs) { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::basic_string const& lhs, T const* rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator<=(T const* lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator<=(T const* lhs, sprout::basic_string const& rhs) { return !(rhs < lhs); } template - inline SPROUT_CONSTEXPR bool operator>=(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { return !(lhs < rhs); } template - inline SPROUT_CONSTEXPR bool operator>=(sprout::basic_string const& lhs, T const* rhs) { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::basic_string const& lhs, T const* rhs) { return !(lhs < rhs); } template - inline SPROUT_CONSTEXPR bool operator>=(T const* lhs, sprout::basic_string const& rhs) { + inline SPROUT_CONSTEXPR bool + operator>=(T const* lhs, sprout::basic_string const& rhs) { return !(lhs < rhs); } } // namespace sprout diff --git a/sprout/string/concat.hpp b/sprout/string/concat.hpp index a6591d23..51082ef9 100644 --- a/sprout/string/concat.hpp +++ b/sprout/string/concat.hpp @@ -13,8 +13,7 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::basic_string string_concat( - sprout::basic_string const& lhs, - std::size_t lsize, + sprout::basic_string const& lhs, std::size_t lsize, T const& rhs, sprout::index_tuple ) @@ -33,8 +32,7 @@ namespace sprout { inline SPROUT_CONSTEXPR sprout::basic_string string_concat( T const& lhs, - sprout::basic_string const& rhs, - std::size_t rsize, + sprout::basic_string const& rhs, std::size_t rsize, sprout::index_tuple ) { @@ -51,10 +49,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::basic_string string_concat( - sprout::basic_string const& lhs, - std::size_t lsize, - T const (& rhs)[M], - std::size_t rsize, + sprout::basic_string const& lhs, std::size_t lsize, + T const (& rhs)[M], std::size_t rsize, sprout::index_tuple ) { @@ -71,10 +67,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::basic_string string_concat( - T const (& lhs)[M], - std::size_t lsize, - sprout::basic_string const& rhs, - std::size_t rsize, + T const (& lhs)[M], std::size_t lsize, + sprout::basic_string const& rhs, std::size_t rsize, sprout::index_tuple ) { @@ -91,10 +85,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::basic_string string_concat( - sprout::basic_string const& lhs, - std::size_t lsize, - sprout::basic_string const& rhs, - std::size_t rsize, + sprout::basic_string const& lhs, std::size_t lsize, + sprout::basic_string const& rhs, std::size_t rsize, sprout::index_tuple ) { diff --git a/sprout/string/container.hpp b/sprout/string/container.hpp index 7063c0e8..891d0ba1 100644 --- a/sprout/string/container.hpp +++ b/sprout/string/container.hpp @@ -17,21 +17,19 @@ namespace sprout { typedef sprout::basic_string copied_type; public: template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { + static SPROUT_CONSTEXPR copied_type + deep_copy(Cont&& cont) { return sprout::forward(cont); } template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + static SPROUT_CONSTEXPR copied_type + make(Args&&... args) { typedef sprout::detail::make_construct_impl impl_type; return impl_type::make(sprout::forward(args)...); } template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits >::difference_type size, - Args&&... args - ) - { + static SPROUT_CONSTEXPR copied_type + remake(Cont&& cont, typename sprout::container_traits >::difference_type size, Args&&... args) { typedef sprout::detail::make_construct_impl impl_type; return impl_type::make(static_cast(size), sprout::forward(args)...); } diff --git a/sprout/string/float_to_string.hpp b/sprout/string/float_to_string.hpp index c313b31e..cb75a06b 100644 --- a/sprout/string/float_to_string.hpp +++ b/sprout/string/float_to_string.hpp @@ -33,7 +33,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::basic_string::value> float_to_string(FloatType val, bool negative, int digits, sprout::index_tuple) { - return negative ? sprout::basic_string::value>{ + return negative + ? sprout::basic_string::value>{ { static_cast('-'), (Indexes < digits ? sprout::detail::int_to_char(sprout::detail::float_digit_at(val, digits - 1 - Indexes)) @@ -62,8 +63,7 @@ namespace sprout { // float_to_string // template< - typename Elem, - typename FloatType, + typename Elem, typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> @@ -101,7 +101,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::basic_string::value> float_to_string_exp(FloatType val, bool negative, int exponent10, int e10_digits, sprout::index_tuple) { - return negative ? sprout::basic_string::value>{ + return negative + ? sprout::basic_string::value>{ { static_cast('-'), (Indexes == 0 ? sprout::detail::int_to_char(sprout::detail::float_digit_at(val, 0)) @@ -140,8 +141,7 @@ namespace sprout { // float_to_string_exp // template< - typename Elem, - typename FloatType, + typename Elem, typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> @@ -170,18 +170,6 @@ namespace sprout { // // to_string // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(float val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(double val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(long double val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_string(FloatType val) { @@ -191,18 +179,6 @@ namespace sprout { // // to_wstring // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(float val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(double val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(long double val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_wstring(FloatType val) { @@ -212,18 +188,6 @@ namespace sprout { // // to_u16string // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(float val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(double val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(long double val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_u16string(FloatType val) { @@ -233,18 +197,6 @@ namespace sprout { // // to_u32string // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(float val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(double val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(long double val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_u32string(FloatType val) { diff --git a/sprout/string/hash.hpp b/sprout/string/hash.hpp index ab7747a3..b0ee5354 100644 --- a/sprout/string/hash.hpp +++ b/sprout/string/hash.hpp @@ -11,7 +11,8 @@ namespace sprout { // hash_value // template - inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::basic_string const& v) { + inline SPROUT_CONSTEXPR std::size_t + hash_value(sprout::basic_string const& v) { return sprout::hash_range(v.begin(), v.end()); } } // namespace sprout diff --git a/sprout/string/int_to_string.hpp b/sprout/string/int_to_string.hpp index 4be37f4d..99006916 100644 --- a/sprout/string/int_to_string.hpp +++ b/sprout/string/int_to_string.hpp @@ -25,9 +25,7 @@ namespace sprout { namespace detail { template< - typename Elem, - int Base, - typename IntType, + typename Elem, int Base, typename IntType, sprout::index_t... Indexes, typename sprout::enabler_if::value>::type = sprout::enabler > @@ -53,9 +51,7 @@ namespace sprout { ; } template< - typename Elem, - int Base, - typename IntType, + typename Elem, int Base, typename IntType, sprout::index_t... Indexes, typename sprout::enabler_if::value>::type = sprout::enabler > @@ -76,9 +72,7 @@ namespace sprout { // int_to_string // template< - typename Elem, - int Base = 10, - typename IntType, + typename Elem, int Base = 10, typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> @@ -93,7 +87,10 @@ namespace sprout { // // to_string_of // - template::value>::type = sprout::enabler> + template< + typename Elem, typename IntType, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR sprout::basic_string::value> to_string_of(IntType val) { return sprout::int_to_string(val); @@ -102,30 +99,6 @@ namespace sprout { // // to_string // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(int val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(unsigned val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(unsigned long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(long long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_string(unsigned long long val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_string(IntType val) { @@ -135,30 +108,6 @@ namespace sprout { // // to_wstring // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(int val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(unsigned val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(unsigned long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(long long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_wstring(unsigned long long val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_wstring(IntType val) { @@ -168,30 +117,6 @@ namespace sprout { // // to_u16string // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(int val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(unsigned val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(unsigned long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(long long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u16string(unsigned long long val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_u16string(IntType val) { @@ -201,30 +126,6 @@ namespace sprout { // // to_u32string // -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(int val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(unsigned val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(unsigned long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(long long val) { -// return sprout::to_string_of(val); -// } -// inline SPROUT_CONSTEXPR sprout::basic_string::value> -// to_u32string(unsigned long long val) { -// return sprout::to_string_of(val); -// } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_u32string(IntType val) { diff --git a/sprout/string/shrink.hpp b/sprout/string/shrink.hpp index 71b0c526..7d30767e 100644 --- a/sprout/string/shrink.hpp +++ b/sprout/string/shrink.hpp @@ -21,9 +21,9 @@ namespace sprout { typedef sprout::value_holder holder_type; private: template - static SPROUT_CONSTEXPR sprout::basic_string implicit_conversion_impl( - T const(& elems)[M], - std::size_t len, + static SPROUT_CONSTEXPR sprout::basic_string + implicit_conversion_impl( + T const(& elems)[M], std::size_t len, sprout::index_tuple ) { diff --git a/sprout/string/string.hpp b/sprout/string/string.hpp index 8e4254d4..00bf8090 100644 --- a/sprout/string/string.hpp +++ b/sprout/string/string.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT #include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT @@ -46,14 +47,16 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR size_type npos = -1; SPROUT_STATIC_CONSTEXPR size_type static_size = N; private: - static SPROUT_CONSTEXPR int compare_impl_2(int compared, size_type n1, size_type n2) { + static SPROUT_CONSTEXPR int + compare_impl_2(int compared, size_type n1, size_type n2) { return compared != 0 ? compared : n1 < n2 ? -1 : n2 < n1 ? 1 : 0 ; } - static SPROUT_CONSTEXPR int compare_impl_1(value_type const* dest, size_type pos1, size_type n1, value_type const* s, size_type n2) { + static SPROUT_CONSTEXPR int + compare_impl_1(value_type const* dest, size_type pos1, size_type n1, value_type const* s, size_type n2) { return compare_impl_2( traits_type::compare(dest + pos1, s, NS_SSCRISK_CEL_OR_SPROUT::min(n1, n2)), n1, @@ -61,12 +64,8 @@ namespace sprout { ); } template - static SPROUT_CONSTEXPR basic_string from_c_str_impl( - value_type const* s, - size_type n, - sprout::index_tuple - ) - { + static SPROUT_CONSTEXPR basic_string + from_c_str_impl(value_type const* s, size_type n, sprout::index_tuple) { return sprout::basic_string{{(Indexes < n ? s[Indexes] : T())...}, n}; } #if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION @@ -74,14 +73,16 @@ namespace sprout { static SPROUT_CONSTEXPR typename std::enable_if< sprout::is_index_iterator::value, int - >::type compare_impl_1(value_type const* dest, size_type pos1, size_type n1, ConstIterator s, size_type n2) { + >::type + compare_impl_1(value_type const* dest, size_type pos1, size_type n1, ConstIterator s, size_type n2) { return compare_impl_2( traits_type::compare(dest + pos1, s, NS_SSCRISK_CEL_OR_SPROUT::min(n1, n2)), n1, n2 ); } - static SPROUT_CONSTEXPR int compare_impl_1(const_iterator dest, size_type pos1, size_type n1, value_type const* s, size_type n2) { + static SPROUT_CONSTEXPR int + compare_impl_1(const_iterator dest, size_type pos1, size_type n1, value_type const* s, size_type n2) { return compare_impl_2( traits_type::compare(dest + pos1, s, NS_SSCRISK_CEL_OR_SPROUT::min(n1, n2)), n1, @@ -92,7 +93,8 @@ namespace sprout { static SPROUT_CONSTEXPR typename std::enable_if< sprout::is_index_iterator::value, int - >::type compare_impl_1(const_iterator dest, size_type pos1, size_type n1, ConstIterator s, size_type n2) { + >::type + compare_impl_1(const_iterator dest, size_type pos1, size_type n1, ConstIterator s, size_type n2) { return compare_impl_2( traits_type::compare(dest + pos1, s, NS_SSCRISK_CEL_OR_SPROUT::min(n1, n2)), n1, @@ -101,12 +103,8 @@ namespace sprout { } #endif template - static SPROUT_CONSTEXPR basic_string implicit_conversion_impl( - T const(& elems)[M], - size_type len, - sprout::index_tuple - ) - { + static SPROUT_CONSTEXPR basic_string + implicit_conversion_impl(T const(& elems)[M], size_type len, sprout::index_tuple) { return sprout::basic_string{{(Indexes < M - 1 ? elems[Indexes] : T())...}, len}; } public: @@ -299,12 +297,11 @@ namespace sprout { len = n; return *this; } - void swap(basic_string& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { + void swap(basic_string& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) + { std::swap_ranges(other.begin(), other.begin() + other.max_size(), begin()); - { - using std::swap; - swap(len, other.len); - } + sprout::swap(len, other.len); } // string operations: SPROUT_CONSTEXPR const_pointer c_str() const SPROUT_NOEXCEPT { @@ -438,10 +435,9 @@ namespace sprout { // swap // template - inline void swap( - sprout::basic_string& lhs, - sprout::basic_string& rhs - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + inline void + swap(sprout::basic_string& lhs, sprout::basic_string& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } @@ -456,19 +452,16 @@ namespace sprout { typedef sprout::basic_string copied_type; private: template - static SPROUT_CONSTEXPR typename copied_type::size_type length_impl(sprout::array const& arr) { + static SPROUT_CONSTEXPR typename copied_type::size_type + length_impl(sprout::array const& arr) { return NS_SSCRISK_CEL_OR_SPROUT::distance( arr.begin(), NS_SSCRISK_CEL_OR_SPROUT::find(arr.begin(), arr.end(), T()) ); } template - static SPROUT_CONSTEXPR copied_type make_impl( - typename copied_type::size_type size, - sprout::index_tuple, - Args&&... args - ) - { + static SPROUT_CONSTEXPR copied_type + make_impl(typename copied_type::size_type size, sprout::index_tuple, Args&&... args) { return copied_type{ {(Indexes < size ? sprout::forward(args) : T())...}, size @@ -476,11 +469,13 @@ namespace sprout { } public: template - static SPROUT_CONSTEXPR typename copied_type::size_type length(Args&&... args) { + static SPROUT_CONSTEXPR typename copied_type::size_type + length(Args&&... args) { return length_impl(sprout::make_array(sprout::forward(args)...)); } template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + static SPROUT_CONSTEXPR copied_type + make(Args&&... args) { return make_impl( length(args...), sprout::index_range<0, sizeof...(Args)>::make(), @@ -488,7 +483,8 @@ namespace sprout { ); } template - static SPROUT_CONSTEXPR copied_type make(typename copied_type::size_type size, Args&&... args) { + static SPROUT_CONSTEXPR copied_type + make(typename copied_type::size_type size, Args&&... args) { return make_impl( size, sprout::index_range<0, sizeof...(Args)>::make(), @@ -503,25 +499,23 @@ namespace sprout { // namespace detail { template - inline SPROUT_CONSTEXPR sprout::basic_string to_string_impl_1( - T const(& arr)[N], - typename sprout::basic_string::size_type n, + inline SPROUT_CONSTEXPR sprout::basic_string + to_string_impl_1( + T const(& arr)[N], typename sprout::basic_string::size_type n, sprout::index_tuple ) { return sprout::basic_string{{(Indexes < n ? arr[Indexes] : T())...}, n}; } template - inline SPROUT_CONSTEXPR sprout::basic_string to_string_impl( - T const(& arr)[N], - sprout::index_tuple - ) - { + inline SPROUT_CONSTEXPR sprout::basic_string + to_string_impl(T const(& arr)[N], sprout::index_tuple) { return to_string_impl_1(arr, sprout::char_traits::length(arr), sprout::index_tuple()); } } // namespace detail template - inline SPROUT_CONSTEXPR sprout::basic_string to_string(T const(& arr)[N]) { + inline SPROUT_CONSTEXPR sprout::basic_string + to_string(T const(& arr)[N]) { return sprout::detail::to_string_impl(arr, sprout::index_range<0, N - 1>::make()); } @@ -529,11 +523,13 @@ namespace sprout { // string_from_c_str // template - inline SPROUT_CONSTEXPR sprout::basic_string string_from_c_str(T const* s, std::size_t n) { + inline SPROUT_CONSTEXPR sprout::basic_string + string_from_c_str(T const* s, std::size_t n) { return sprout::basic_string::from_c_str(s, n); } template - inline SPROUT_CONSTEXPR sprout::basic_string string_from_c_str(T const* s) { + inline SPROUT_CONSTEXPR sprout::basic_string + string_from_c_str(T const* s) { return sprout::basic_string::from_c_str(s); } } // namespace sprout diff --git a/sprout/string/string_to_float.hpp b/sprout/string/string_to_float.hpp index 2c496dae..6f8aaffe 100644 --- a/sprout/string/string_to_float.hpp +++ b/sprout/string/string_to_float.hpp @@ -12,10 +12,7 @@ namespace sprout { namespace detail { template< - typename FloatType, - typename Elem, - std::size_t N, - typename Traits + typename FloatType, typename Elem, std::size_t N, typename Traits > inline FloatType string_to_float_dynamic(sprout::basic_string const& str, std::size_t* idx) { Elem* endptr = nullptr; @@ -29,25 +26,21 @@ namespace sprout { // string_to_float // template< - typename FloatType, - typename Elem, - std::size_t N, - typename Traits, + typename FloatType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR FloatType string_to_float(sprout::basic_string const& str, std::size_t* idx) { + inline SPROUT_CONSTEXPR FloatType + string_to_float(sprout::basic_string const& str, std::size_t* idx) { return !idx ? sprout::detail::str_to_float(str.begin()) : sprout::detail::string_to_float_dynamic(str, idx) ; } template< - typename FloatType, - typename Elem, - std::size_t N, - typename Traits, + typename FloatType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR FloatType string_to_float(sprout::basic_string const& str) { + inline SPROUT_CONSTEXPR FloatType + string_to_float(sprout::basic_string const& str) { return sprout::detail::str_to_float(str.begin()); } @@ -55,11 +48,13 @@ namespace sprout { // stof // template - inline SPROUT_CONSTEXPR float stof(sprout::basic_string const& str, std::size_t* idx) { + inline SPROUT_CONSTEXPR float + stof(sprout::basic_string const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template - inline SPROUT_CONSTEXPR float stof(sprout::basic_string const& str) { + inline SPROUT_CONSTEXPR float + stof(sprout::basic_string const& str) { return sprout::string_to_float(str); } @@ -67,11 +62,13 @@ namespace sprout { // stod // template - inline SPROUT_CONSTEXPR double stod(sprout::basic_string const& str, std::size_t* idx) { + inline SPROUT_CONSTEXPR double + stod(sprout::basic_string const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template - inline SPROUT_CONSTEXPR double stod(sprout::basic_string const& str) { + inline SPROUT_CONSTEXPR double + stod(sprout::basic_string const& str) { return sprout::string_to_float(str); } @@ -79,11 +76,13 @@ namespace sprout { // stold // template - inline SPROUT_CONSTEXPR long double stold(sprout::basic_string const& str, std::size_t* idx) { + inline SPROUT_CONSTEXPR long double + stold(sprout::basic_string const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template - inline SPROUT_CONSTEXPR long double stold(sprout::basic_string const& str) { + inline SPROUT_CONSTEXPR long double + stold(sprout::basic_string const& str) { return sprout::string_to_float(str); } @@ -91,23 +90,19 @@ namespace sprout { // from_string // template< - typename FloatType, - typename Elem, - std::size_t N, - typename Traits, + typename FloatType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR FloatType from_string(sprout::basic_string const& str, std::size_t* idx) { + inline SPROUT_CONSTEXPR FloatType + from_string(sprout::basic_string const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template< - typename FloatType, - typename Elem, - std::size_t N, - typename Traits, + typename FloatType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR FloatType from_string(sprout::basic_string const& str) { + inline SPROUT_CONSTEXPR FloatType + from_string(sprout::basic_string const& str) { return sprout::string_to_float(str); } } // namespace sprout diff --git a/sprout/string/string_to_int.hpp b/sprout/string/string_to_int.hpp index e936597a..cb3b34f2 100644 --- a/sprout/string/string_to_int.hpp +++ b/sprout/string/string_to_int.hpp @@ -12,13 +12,9 @@ namespace sprout { namespace detail { - template< - typename IntType, - typename Elem, - std::size_t N, - typename Traits - > - inline IntType string_to_int_dynamic(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + template + inline IntType + string_to_int_dynamic(sprout::basic_string const& str, std::size_t* idx, int base = 10) { Elem* endptr = nullptr; IntType result = sprout::detail::str_to_int(str.c_str(), &endptr, base); *idx = endptr - str.c_str(); @@ -30,25 +26,21 @@ namespace sprout { // string_to_int // template< - typename IntType, - typename Elem, - std::size_t N, - typename Traits, + typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR IntType string_to_int(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR IntType + string_to_int(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return !idx ? sprout::detail::str_to_int(str.begin(), base) : sprout::detail::string_to_int_dynamic(str, idx, base) ; } template< - typename IntType, - typename Elem, - std::size_t N, - typename Traits, + typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR IntType string_to_int(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR IntType + string_to_int(sprout::basic_string const& str, int base = 10) { return sprout::detail::str_to_int(str.begin(), base); } @@ -56,11 +48,13 @@ namespace sprout { // stoi // template - inline SPROUT_CONSTEXPR int stoi(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR int + stoi(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template - inline SPROUT_CONSTEXPR int stoi(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR int + stoi(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -68,11 +62,13 @@ namespace sprout { // stol // template - inline SPROUT_CONSTEXPR long stol(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR long + stol(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template - inline SPROUT_CONSTEXPR long stol(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR long + stol(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -80,11 +76,13 @@ namespace sprout { // stoul // template - inline SPROUT_CONSTEXPR unsigned long stoul(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR unsigned long + stoul(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template - inline SPROUT_CONSTEXPR unsigned long stoul(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR unsigned long + stoul(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -92,11 +90,13 @@ namespace sprout { // stoll // template - inline SPROUT_CONSTEXPR long long stoll(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR long long + stoll(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template - inline SPROUT_CONSTEXPR long long stoll(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR long long + stoll(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -104,11 +104,13 @@ namespace sprout { // stoull // template - inline SPROUT_CONSTEXPR unsigned long long stoull(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR unsigned long long + stoull(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template - inline SPROUT_CONSTEXPR unsigned long long stoull(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR unsigned long long + stoull(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -116,11 +118,13 @@ namespace sprout { // stoimax // template - inline SPROUT_CONSTEXPR std::intmax_t stoimax(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR std::intmax_t + stoimax(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template - inline SPROUT_CONSTEXPR std::intmax_t stoimax(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR std::intmax_t + stoimax(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -128,11 +132,13 @@ namespace sprout { // stoumax // template - inline SPROUT_CONSTEXPR std::uintmax_t stoumax(sprout::basic_string const& str, std::size_t* idx, int base = 10) { + inline SPROUT_CONSTEXPR std::uintmax_t + stoumax(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template - inline SPROUT_CONSTEXPR std::uintmax_t stoumax(sprout::basic_string const& str, int base = 10) { + inline SPROUT_CONSTEXPR std::uintmax_t + stoumax(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -140,23 +146,19 @@ namespace sprout { // from_string // template< - typename IntType, - typename Elem, - std::size_t N, - typename Traits, + typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR IntType from_string(sprout::basic_string const& str, std::size_t* idx) { + inline SPROUT_CONSTEXPR IntType + from_string(sprout::basic_string const& str, std::size_t* idx) { return sprout::string_to_int(str, idx, 0); } template< - typename IntType, - typename Elem, - std::size_t N, - typename Traits, + typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR IntType from_string(sprout::basic_string const& str) { + inline SPROUT_CONSTEXPR IntType + from_string(sprout::basic_string const& str) { return sprout::string_to_int(str, 0); } } // namespace sprout diff --git a/sprout/string/tuple.hpp b/sprout/string/tuple.hpp index 7e9b0423..81b3278e 100644 --- a/sprout/string/tuple.hpp +++ b/sprout/string/tuple.hpp @@ -4,11 +4,12 @@ #include #include #include +#include #include #include #include -namespace sprout_adl { +namespace sprout { // // tuple_get // @@ -29,7 +30,7 @@ namespace sprout_adl { tuple_get(sprout::basic_string&& t) SPROUT_NOEXCEPT { return sprout::move(sprout::tuples::get(t)); } -} // namespace sprout_adl +} // namespace sprout namespace std { // diff --git a/sprout/sub_array/container.hpp b/sprout/sub_array/container.hpp index 538bafc9..0080450e 100644 --- a/sprout/sub_array/container.hpp +++ b/sprout/sub_array/container.hpp @@ -22,11 +22,13 @@ namespace sprout { public: typedef sprout::sub_array copied_type; private: - static SPROUT_CONSTEXPR copied_type make_impl(internal_copied_type const& internal_copied) { + static SPROUT_CONSTEXPR copied_type + make_impl(internal_copied_type const& internal_copied) { return copied_type(internal_copied, sprout::begin(internal_copied), sprout::end(internal_copied)); } template - static SPROUT_CONSTEXPR copied_type remake_impl( + static SPROUT_CONSTEXPR copied_type + remake_impl( Cont&& cont, typename sprout::container_traits >::difference_type size, internal_copied_type const& internal_copied @@ -40,7 +42,8 @@ namespace sprout { } public: template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { + static SPROUT_CONSTEXPR copied_type + deep_copy(Cont&& cont) { return copied_type( sprout::deep_copy(sprout::get_internal(cont)), sprout::internal_begin_offset(cont), @@ -48,18 +51,15 @@ namespace sprout { ); } template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + static SPROUT_CONSTEXPR copied_type + make(Args&&... args) { return make_impl( sprout::make(sprout::forward(args)...) ); } template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits >::difference_type size, - Args&&... args - ) - { + static SPROUT_CONSTEXPR copied_type + remake(Cont&& cont, typename sprout::container_traits >::difference_type size, Args&&... args) { return remake_impl( sprout::forward(cont), size, @@ -107,7 +107,8 @@ namespace sprout { }; public: template - static SPROUT_CONSTEXPR typename internal::type get_internal(Cont&& cont) { + static SPROUT_CONSTEXPR typename internal::type + get_internal(Cont&& cont) { return call(sprout::forward(cont)); } }; diff --git a/sprout/sub_array/hash.hpp b/sprout/sub_array/hash.hpp index cdf161a0..b6d2b262 100644 --- a/sprout/sub_array/hash.hpp +++ b/sprout/sub_array/hash.hpp @@ -7,7 +7,8 @@ namespace sprout { template - SPROUT_CONSTEXPR std::size_t hash_value(sprout::sub_array const& v) { + SPROUT_CONSTEXPR std::size_t + hash_value(sprout::sub_array const& v) { return sprout::hash_range(v.begin(), v.end()); } } // namespace sprout diff --git a/sprout/sub_array/sub.hpp b/sprout/sub_array/sub.hpp index 02f5338c..78786c00 100644 --- a/sprout/sub_array/sub.hpp +++ b/sprout/sub_array/sub.hpp @@ -14,7 +14,8 @@ namespace sprout { // sub // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container& arr, typename sprout::container_traits >::const_iterator first, typename sprout::container_traits >::const_iterator last @@ -23,7 +24,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container& arr, typename sprout::container_traits >::difference_type first, typename sprout::container_traits >::difference_type last @@ -32,7 +34,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container& arr, typename sprout::container_traits >::const_iterator first ) @@ -40,7 +43,8 @@ namespace sprout { return sprout::sub(arr, first, sprout::end(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container& arr, typename sprout::container_traits >::difference_type first ) @@ -48,7 +52,8 @@ namespace sprout { return sprout::sub(arr, first, sprout::size(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container& arr ) { @@ -58,7 +63,8 @@ namespace sprout { // sub // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container const& arr, typename sprout::container_traits >::const_iterator first, typename sprout::container_traits >::const_iterator last @@ -67,7 +73,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container const& arr, typename sprout::container_traits >::difference_type first, typename sprout::container_traits >::difference_type last @@ -76,7 +83,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container const& arr, typename sprout::container_traits >::const_iterator first ) @@ -84,7 +92,8 @@ namespace sprout { return sprout::sub(arr, first, sprout::end(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container const& arr, typename sprout::container_traits >::difference_type first ) @@ -92,7 +101,8 @@ namespace sprout { return sprout::sub(arr, first, sprout::size(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub( Container const& arr ) { @@ -102,7 +112,8 @@ namespace sprout { // sub // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type + sub( Container const& arr, typename sprout::container_traits::const_iterator first, typename sprout::container_traits::const_iterator last @@ -111,7 +122,8 @@ namespace sprout { return Container(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type + sub( Container const& arr, typename sprout::container_traits::difference_type first, typename sprout::container_traits::difference_type last @@ -120,7 +132,8 @@ namespace sprout { return Container(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type + sub( Container const& arr, typename sprout::container_traits::const_iterator first ) @@ -128,7 +141,8 @@ namespace sprout { return sprout::sub(arr, first, sprout::end(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type + sub( Container const& arr, typename sprout::container_traits::difference_type first ) @@ -136,7 +150,8 @@ namespace sprout { return sprout::sub(arr, first, sprout::size(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type + sub( Container const& arr ) { @@ -147,7 +162,8 @@ namespace sprout { // csub // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits >::const_iterator first, typename sprout::container_traits >::const_iterator last @@ -156,7 +172,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits >::difference_type first, typename sprout::container_traits >::difference_type last @@ -165,7 +182,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits >::const_iterator first ) @@ -173,7 +191,8 @@ namespace sprout { return sprout::csub(arr, first, sprout::end(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits >::difference_type first ) @@ -181,7 +200,8 @@ namespace sprout { return sprout::csub(arr, first, sprout::size(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr ) { @@ -191,7 +211,8 @@ namespace sprout { // csub // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits::const_iterator first, typename sprout::container_traits::const_iterator last @@ -200,7 +221,8 @@ namespace sprout { return sprout::sub_array(arr.get_array(), first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits::difference_type first, typename sprout::container_traits::difference_type last @@ -213,7 +235,8 @@ namespace sprout { ); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits::const_iterator first ) @@ -221,7 +244,8 @@ namespace sprout { return sprout::csub(arr, first, sprout::end(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr, typename sprout::container_traits::difference_type first ) @@ -229,7 +253,8 @@ namespace sprout { return sprout::csub(arr, first, sprout::size(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub( Container const& arr ) { @@ -240,7 +265,8 @@ namespace sprout { // sub_copy // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::const_iterator first, typename sprout::container_traits::const_iterator last @@ -249,7 +275,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::difference_type first, typename sprout::container_traits::difference_type last @@ -258,7 +285,8 @@ namespace sprout { return sprout::sub_array(arr, first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::const_iterator first ) @@ -266,7 +294,8 @@ namespace sprout { return sprout::sub_copy(arr, first, sprout::end(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::difference_type first ) @@ -274,7 +303,8 @@ namespace sprout { return sprout::sub_copy(arr, first, sprout::size(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + ub_copy( Container const& arr ) { @@ -284,7 +314,8 @@ namespace sprout { // sub_copy // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::const_iterator first, typename sprout::container_traits::const_iterator last @@ -293,7 +324,8 @@ namespace sprout { return sprout::sub_array(arr.get_array(), first, last); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::difference_type first, typename sprout::container_traits::difference_type last @@ -306,7 +338,8 @@ namespace sprout { ); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::const_iterator first ) @@ -314,7 +347,8 @@ namespace sprout { return sprout::sub_copy(arr, first, sprout::end(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr, typename sprout::container_traits::difference_type first ) @@ -322,7 +356,8 @@ namespace sprout { return sprout::sub_copy(arr, first, sprout::size(arr)); } template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy( Container const& arr ) { diff --git a/sprout/sub_array/sub_array.hpp b/sprout/sub_array/sub_array.hpp index 7ea77a2d..c344e198 100644 --- a/sprout/sub_array/sub_array.hpp +++ b/sprout/sub_array/sub_array.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT namespace sprout { @@ -240,11 +241,12 @@ namespace sprout { std::fill_n(begin(), size(), value); } template - void swap(sub_array& other) { - using std::swap; - swap(other.array_, array_); - swap(other.first_, first_); - swap(other.last_, last_); + void swap(sub_array& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(other.array_, array_))) + { + sprout::swap(other.array_, array_); + sprout::swap(other.first_, first_); + sprout::swap(other.last_, last_); } // iterators: iterator begin() { @@ -360,7 +362,10 @@ namespace sprout { // swap // template - inline void swap(sprout::sub_array& lhs, sprout::sub_array& rhs) { + inline void + swap(sprout::sub_array& lhs, sprout::sub_array& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } } // namespace sprout diff --git a/sprout/sub_array/tuple.hpp b/sprout/sub_array/tuple.hpp index 41e61e78..181e3752 100644 --- a/sprout/sub_array/tuple.hpp +++ b/sprout/sub_array/tuple.hpp @@ -13,14 +13,14 @@ #include #include -namespace sprout_adl { +namespace sprout { // // tuple_get // template inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type& tuple_get(sprout::sub_array& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) { static_assert(I < sprout::container_traits >::static_size, "tuple_get: index out of range"); return *sprout::next(sprout::internal_begin(t), I); @@ -28,7 +28,7 @@ namespace sprout_adl { template inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type const& tuple_get(sprout::sub_array const& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) { static_assert(I < sprout::container_traits >::static_size, "tuple_get: index out of range"); return *sprout::next(sprout::internal_begin(t), I); @@ -36,11 +36,11 @@ namespace sprout_adl { template inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type&& tuple_get(sprout::sub_array&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get(t)))) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get(t)))) { return sprout::move(sprout::tuples::get(t)); } -} // namespace sprout_adl +} // namespace sprout namespace std { // diff --git a/sprout/tuple/sscrisk/cel/utility.hpp b/sprout/tuple/sscrisk/cel/utility.hpp index 5b665a77..ee23fa9e 100644 --- a/sprout/tuple/sscrisk/cel/utility.hpp +++ b/sprout/tuple/sscrisk/cel/utility.hpp @@ -69,29 +69,26 @@ namespace sprout { } // namespace sprout namespace sprout_adl { - // - // tuple_get - // - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& - tuple_get(sscrisk::cel::pair& t) SPROUT_NOEXCEPT { - static_assert(I < 2, "tuple_get: index out of range"); - return sprout::tuples::detail::get_impl >()(t); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& - tuple_get(sscrisk::cel::pair const& t) SPROUT_NOEXCEPT { - static_assert(I < 2, "tuple_get: index out of range"); - return sprout::tuples::detail::get_impl >()(t); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& - tuple_get(sscrisk::cel::pair&& t) SPROUT_NOEXCEPT { - return sprout::move(sprout::tuples::get(t)); - } - } // namespace tuples - - using sprout::tuples::get; + // + // tuple_get + // + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + tuple_get(sscrisk::cel::pair& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + tuple_get(sscrisk::cel::pair const& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + tuple_get(sscrisk::cel::pair&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); + } } // namespace sprout_adl #endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP diff --git a/sprout/tuple/tuple/get.hpp b/sprout/tuple/tuple/get.hpp index 4951f0c4..75efddb6 100644 --- a/sprout/tuple/tuple/get.hpp +++ b/sprout/tuple/tuple/get.hpp @@ -201,7 +201,7 @@ namespace sprout_tuple_detail { > inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result::type get_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get::value)) + SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get::value)) { return tuple_get(sprout::forward(t)); } @@ -211,7 +211,7 @@ namespace sprout_tuple_detail { > inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result::type get_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get::value)) + SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get::value)) { return std::get(sprout::forward(t)); } diff --git a/sprout/tuple/tuple/tuple.hpp b/sprout/tuple/tuple/tuple.hpp index 92f0e565..b7d0271d 100644 --- a/sprout/tuple/tuple/tuple.hpp +++ b/sprout/tuple/tuple/tuple.hpp @@ -6,7 +6,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -141,13 +143,13 @@ namespace sprout { return t; } protected: - void swap(tuple_impl& t) SPROUT_NOEXCEPT_EXPR( - SPROUT_NOEXCEPT_EXPR(swap(std::declval(), std::declval())) - && SPROUT_NOEXCEPT_EXPR(tail(t).swap(tail(t))) + void swap(tuple_impl& t) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(sprout::swap(head(std::declval()), head(t))) + && SPROUT_NOEXCEPT_EXPR(inherited_type::swap(tail(t))) ) { - using std::swap; - swap(head(*this), head(t)); + sprout::swap(head(*this), head(t)); inherited_type::swap(tail(t)); } public: @@ -318,7 +320,9 @@ namespace sprout { static_cast(*this) = rhs; return *this; } - tuple& operator=(tuple&& rhs) SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value) { + tuple& operator=(tuple&& rhs) + SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value) + { static_cast(*this) = sprout::move(rhs); return *this; } @@ -333,7 +337,9 @@ namespace sprout { return *this; } // tuple swap - void swap(tuple& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(inherited_type::swap(other))) { + void swap(tuple& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(inherited_type::swap(other))) + { inherited_type::swap(other); } }; @@ -348,10 +354,9 @@ namespace sprout { // swap // template - inline void swap( - sprout::tuples::tuple& lhs, - sprout::tuples::tuple& rhs - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + inline void + swap(sprout::tuples::tuple& lhs, sprout::tuples::tuple& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } diff --git a/sprout/utility/operation.hpp b/sprout/utility/operation.hpp index df6e1d40..5c2dd996 100644 --- a/sprout/utility/operation.hpp +++ b/sprout/utility/operation.hpp @@ -4,5 +4,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_UTILITY_OPERATION_HPP diff --git a/sprout/utility/pack.hpp b/sprout/utility/pack.hpp index 2bcd4ba2..7f259265 100644 --- a/sprout/utility/pack.hpp +++ b/sprout/utility/pack.hpp @@ -42,28 +42,25 @@ namespace sprout { // namespace detail { template< - std::size_t N, - typename R, - typename Head, - typename... Tail, + std::size_t N, typename R, typename Head, typename... Tail, typename sprout::enabler_if::type = sprout::enabler > - inline SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) { + inline SPROUT_CONSTEXPR R + fppack_at_impl(Head&& head, Tail&&... tail) { return sprout::forward(head); } template< - std::size_t N, - typename R, - typename Head, - typename... Tail, + std::size_t N, typename R, typename Head, typename... Tail, typename sprout::enabler_if::type = sprout::enabler > - inline SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) { + inline SPROUT_CONSTEXPR R + fppack_at_impl(Head&& head, Tail&&... tail) { return sprout::detail::fppack_at_impl(sprout::forward(tail)...); } } // namespace detail template - inline SPROUT_CONSTEXPR typename sprout::tppack_at::type fppack_at(Args&&... args) { + inline SPROUT_CONSTEXPR typename sprout::tppack_at::type + fppack_at(Args&&... args) { return sprout::detail::fppack_at_impl< N, typename sprout::tppack_at::type diff --git a/sprout/utility/pair.hpp b/sprout/utility/pair.hpp index 25fca28e..ff954673 100644 --- a/sprout/utility/pair.hpp +++ b/sprout/utility/pair.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -88,9 +89,8 @@ namespace sprout { second = p.second; return *this; } - pair& operator=(pair&& p) SPROUT_NOEXCEPT_EXPR( - std::is_nothrow_move_assignable::value && std::is_nothrow_move_assignable::value - ) + pair& operator=(pair&& p) + SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value && std::is_nothrow_move_assignable::value) { first = sprout::forward(p.first); second = std::forward(p.second); @@ -102,40 +102,45 @@ namespace sprout { second = std::forward(p.second); return *this; } - void swap(pair& p) SPROUT_NOEXCEPT_EXPR( - SPROUT_NOEXCEPT_EXPR(swap(first, p.first)) && SPROUT_NOEXCEPT_EXPR(swap(second, p.second)) + void swap(pair& p) + SPROUT_NOEXCEPT_EXPR( + SPROUT_NOEXCEPT_EXPR(swap(first, p.first)) + && SPROUT_NOEXCEPT_EXPR(swap(second, p.second)) ) { - using std::swap; - swap(first, p.first); - swap(second, p.second); + sprout::swap(first, p.first); + sprout::swap(second, p.second); } }; template - inline SPROUT_CONSTEXPR bool operator==(sprout::pair const& x, sprout::pair const& y) { + inline SPROUT_CONSTEXPR bool + operator==(sprout::pair const& x, sprout::pair const& y) { return x.first == y.first && x.second == y.second; } template - inline SPROUT_CONSTEXPR bool operator!=(sprout::pair const& x, sprout::pair const& y) { + inline SPROUT_CONSTEXPR bool + operator!=(sprout::pair const& x, sprout::pair const& y) { return !(x == y); } template - inline SPROUT_CONSTEXPR bool operator<(sprout::pair const& x, sprout::pair const& y) { - return x.first < y.first - || (!(y.first < x.first) && x.second < y.second) - ; + inline SPROUT_CONSTEXPR bool + operator<(sprout::pair const& x, sprout::pair const& y) { + return x.first < y.first || (!(y.first < x.first) && x.second < y.second); } template - inline SPROUT_CONSTEXPR bool operator>(sprout::pair const& x, sprout::pair const& y) { + inline SPROUT_CONSTEXPR bool + operator>(sprout::pair const& x, sprout::pair const& y) { return y < x; } template - inline SPROUT_CONSTEXPR bool operator<=(sprout::pair const& x, sprout::pair const& y) { + inline SPROUT_CONSTEXPR bool + operator<=(sprout::pair const& x, sprout::pair const& y) { return !(y < x); } template - inline SPROUT_CONSTEXPR bool operator>=(sprout::pair const& x, sprout::pair const& y) { + inline SPROUT_CONSTEXPR bool + operator>=(sprout::pair const& x, sprout::pair const& y) { return !(x < y); } @@ -143,15 +148,18 @@ namespace sprout { // swap // template - inline void swap(pair& x, pair& y) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(x.swap(y))) { - x.swap(y); + inline void + swap(sprout::pair& lhs, sprout::pair& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { + lhs.swap(rhs); } // // make_pair // template - SPROUT_CONSTEXPR sprout::pair< + inline SPROUT_CONSTEXPR sprout::pair< typename sprout::strip_reference::type>::type, typename sprout::strip_reference::type>::type > @@ -226,7 +234,7 @@ namespace std { {}; } // namespace std -namespace sprout_adl { +namespace sprout { // // tuple_get // @@ -247,6 +255,6 @@ namespace sprout_adl { tuple_get(sprout::pair&& t) SPROUT_NOEXCEPT { return sprout::move(sprout::tuples::get(t)); } -} // namespace sprout_adl +} // namespace sprout #endif // #ifndef SPROUT_UTILITY_PAIR_HPP diff --git a/sprout/utility/rel_ops.hpp b/sprout/utility/rel_ops.hpp index 2c9d0873..a74456b8 100644 --- a/sprout/utility/rel_ops.hpp +++ b/sprout/utility/rel_ops.hpp @@ -6,22 +6,26 @@ namespace sprout { namespace rel_ops { template - inline SPROUT_CONSTEXPR bool operator!=(T const& x, T const& y) { + inline SPROUT_CONSTEXPR bool + operator!=(T const& x, T const& y) { return !(x == y); } template - inline SPROUT_CONSTEXPR bool operator>(T const& x, T const& y) { + inline SPROUT_CONSTEXPR bool + operator>(T const& x, T const& y) { return y < x; } template - inline SPROUT_CONSTEXPR bool operator<=(T const& x, T const& y) { + inline SPROUT_CONSTEXPR bool + operator<=(T const& x, T const& y) { return !(y < x); } template - inline SPROUT_CONSTEXPR bool operator>=(T const& x, T const& y) { + inline SPROUT_CONSTEXPR bool + operator>=(T const& x, T const& y) { return !(x < y); } } // namespace rel_ops diff --git a/sprout/utility/swap.hpp b/sprout/utility/swap.hpp new file mode 100644 index 00000000..1c6f920e --- /dev/null +++ b/sprout/utility/swap.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_UTILITY_SWAP_HPP +#define SPROUT_UTILITY_SWAP_HPP + +#include +#include + +namespace sprout_swap_detail { + using std::swap; + + template + inline void + swap_impl(T& a, T& b) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(a, b))) + { + return swap(a, b); + } +} // namespace sprout_swap_detail + +namespace sprout { + // + // swap + // + template + inline void + swap(T1& lhs, T2& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_swap_detail::swap_impl(lhs, rhs))) + { + return sprout_swap_detail::swap_impl(lhs, rhs); + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_SWAP_HPP diff --git a/sprout/uuid/hash.hpp b/sprout/uuid/hash.hpp index 73c23a1f..08572aa6 100644 --- a/sprout/uuid/hash.hpp +++ b/sprout/uuid/hash.hpp @@ -7,7 +7,11 @@ #include namespace sprout { - inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::uuids::uuid const& v) { + // + // hash_value + // + inline SPROUT_CONSTEXPR std::size_t + hash_value(sprout::uuids::uuid const& v) { return sprout::hash_range(v.begin(), v.end()); } } // namespace sprout diff --git a/sprout/uuid/io.hpp b/sprout/uuid/io.hpp index 454aa2e2..b743765a 100644 --- a/sprout/uuid/io.hpp +++ b/sprout/uuid/io.hpp @@ -20,7 +20,8 @@ namespace sprout { // operator>> // template - std::basic_istream& operator>>(std::basic_istream& lhs, sprout::uuids::uuid& rhs) { + inline std::basic_istream& + operator>>(std::basic_istream& lhs, sprout::uuids::uuid& rhs) { typedef typename std::basic_ios::char_type char_type; typename std::basic_istream::sentry const ok(lhs); typedef std::ctype ctype_type; @@ -73,7 +74,8 @@ namespace sprout { // operator<< // template - std::basic_ostream& operator<<(std::basic_ostream& lhs, sprout::uuids::uuid const& rhs) { + inline std::basic_ostream& + operator<<(std::basic_ostream& lhs, sprout::uuids::uuid const& rhs) { sprout::detail::io::ios_flags_saver flags_saver(lhs); sprout::detail::io::basic_ios_fill_saver fill_saver(lhs); typename std::basic_ostream::sentry const ok(lhs); diff --git a/sprout/uuid/nil_generator.hpp b/sprout/uuid/nil_generator.hpp index f72352a9..3de2ace8 100644 --- a/sprout/uuid/nil_generator.hpp +++ b/sprout/uuid/nil_generator.hpp @@ -20,9 +20,12 @@ namespace sprout { // // nil_uuid // - inline SPROUT_CONSTEXPR sprout::uuids::uuid nil_uuid() { - return sprout::uuids::nil_generator()(); - } + namespace { + inline SPROUT_CONSTEXPR sprout::uuids::uuid + nil_uuid() { + return sprout::uuids::nil_generator()(); + } + } // anonymous-namespace } // namespace uuids } // namespace sprout diff --git a/sprout/uuid/string_generator.hpp b/sprout/uuid/string_generator.hpp index c9f1c510..72896278 100644 --- a/sprout/uuid/string_generator.hpp +++ b/sprout/uuid/string_generator.hpp @@ -99,18 +99,21 @@ namespace sprout { return open_brace == U'{' && c == U'}'; } template - SPROUT_CONSTEXPR result_type generate_2_3(next_char nc, Char open_brace, bool has_dashes, std::uint8_t byte, Args... args) const { + SPROUT_CONSTEXPR result_type + generate_2_3(next_char nc, Char open_brace, bool has_dashes, std::uint8_t byte, Args... args) const { return generate_2(nc, open_brace, has_dashes, args..., static_cast((byte << 4) | get_value(nc.c))); } template - SPROUT_CONSTEXPR result_type generate_2_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { + SPROUT_CONSTEXPR result_type + generate_2_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { return generate_2_3(nc.next(), open_brace, has_dashes, get_value(nc.c), args...); } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == 6 || sizeof...(Args) == 8 || sizeof...(Args) == 10, result_type - >::type generate_2_1(next_char nc, Char open_brace, bool has_dashes, Args... args) const { + >::type + generate_2_1(next_char nc, Char open_brace, bool has_dashes, Args... args) const { return has_dashes ? is_dash(nc.c) ? generate_2_2(nc.next(), open_brace, has_dashes, args...) @@ -122,7 +125,8 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == 4, result_type - >::type generate_2_1(next_char nc, Char open_brace, bool has_dashes, Args... args) const { + >::type + generate_2_1(next_char nc, Char open_brace, bool has_dashes, Args... args) const { return is_dash(nc.c) ? generate_2_2(nc.next(), open_brace, true, args...) : generate_2_2(nc, open_brace, false, args...) @@ -132,14 +136,16 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) != 4 && sizeof...(Args) != 6 && sizeof...(Args) != 8 && sizeof...(Args) != 10, result_type - >::type generate_2_1(next_char nc, Char open_brace, bool has_dashes, Args... args) const { + >::type + generate_2_1(next_char nc, Char open_brace, bool has_dashes, Args... args) const { return generate_2_2(nc, open_brace, has_dashes, args...); } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == 16, result_type - >::type generate_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { + >::type + generate_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { return !open_brace || (open_brace && is_close_brace(nc.next().c, open_brace)) ? result_type{{args...}} : throw std::domain_error("string_generator: invalid uuid string (brace not closed)") @@ -149,18 +155,21 @@ namespace sprout { SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) == 0, result_type - >::type generate_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { + >::type + generate_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { return generate_2_2(nc, open_brace, has_dashes, args...); } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) != 0 && sizeof...(Args) != 16, result_type - >::type generate_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { + >::type + generate_2(next_char nc, Char open_brace, bool has_dashes, Args... args) const { return generate_2_1(nc.next(), open_brace, has_dashes, args...); } template - SPROUT_CONSTEXPR result_type generate_1(next_char nc) const { + SPROUT_CONSTEXPR result_type + generate_1(next_char nc) const { return is_open_brace(nc.c) ? generate_2(nc.next(), nc.c, false) : generate_2(nc, typename next_char::char_type(), false) diff --git a/sprout/uuid/tuple.hpp b/sprout/uuid/tuple.hpp index 4e0c8260..aba7f2e8 100644 --- a/sprout/uuid/tuple.hpp +++ b/sprout/uuid/tuple.hpp @@ -9,7 +9,7 @@ #include #include -namespace sprout_adl { +namespace sprout { // // tuple_get // diff --git a/sprout/uuid/udl.hpp b/sprout/uuid/udl.hpp index f8279a64..a32ae559 100644 --- a/sprout/uuid/udl.hpp +++ b/sprout/uuid/udl.hpp @@ -15,16 +15,20 @@ namespace sprout { // // _uuid // - SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(char const* s, std::size_t size) { + inline SPROUT_CONSTEXPR sprout::uuids::uuid + operator "" _uuid(char const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } - SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(wchar_t const* s, std::size_t size) { + inline SPROUT_CONSTEXPR sprout::uuids::uuid + operator "" _uuid(wchar_t const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } - SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(char16_t const* s, std::size_t size) { + inline SPROUT_CONSTEXPR sprout::uuids::uuid + operator "" _uuid(char16_t const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } - SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(char32_t const* s, std::size_t size) { + inline SPROUT_CONSTEXPR sprout::uuids::uuid + operator "" _uuid(char32_t const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } } // namespace uuids diff --git a/sprout/uuid/uuid.hpp b/sprout/uuid/uuid.hpp index a2662f0e..4c93ba96 100644 --- a/sprout/uuid/uuid.hpp +++ b/sprout/uuid/uuid.hpp @@ -18,7 +18,8 @@ namespace sprout { namespace uuids { namespace detail { template - inline SPROUT_CONSTEXPR bool is_nil(InputIterator first, InputIterator last) { + inline SPROUT_CONSTEXPR bool + is_nil(InputIterator first, InputIterator last) { return first == last ? true : !*first && sprout::uuids::detail::is_nil(sprout::next(first), last) ; @@ -230,31 +231,44 @@ namespace sprout { // operator<= // operator>= // - inline SPROUT_CONSTEXPR bool operator==(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { - return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin()); - } - inline SPROUT_CONSTEXPR bool operator!=(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { - return !(lhs == rhs); - } - inline SPROUT_CONSTEXPR bool operator<(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { - return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); - } - inline SPROUT_CONSTEXPR bool operator>(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { - return rhs < lhs; - } - inline SPROUT_CONSTEXPR bool operator<=(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { - return !(rhs < lhs); - } - inline SPROUT_CONSTEXPR bool operator>=(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { - return !(lhs < rhs); - } + namespace { + inline SPROUT_CONSTEXPR bool + operator==(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { + return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin()); + } + inline SPROUT_CONSTEXPR bool + operator!=(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { + return !(lhs == rhs); + } + inline SPROUT_CONSTEXPR bool + operator<(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { + return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + } + inline SPROUT_CONSTEXPR bool + operator>(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { + return rhs < lhs; + } + inline SPROUT_CONSTEXPR bool + operator<=(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { + return !(rhs < lhs); + } + inline SPROUT_CONSTEXPR bool + operator>=(sprout::uuids::uuid const& lhs, sprout::uuids::uuid const& rhs) { + return !(lhs < rhs); + } + } // anonymous-namespace // // swap // - inline void swap(sprout::uuids::uuid& lhs, sprout::uuids::uuid& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { - lhs.swap(rhs); - } + namespace { + inline void + swap(sprout::uuids::uuid& lhs, sprout::uuids::uuid& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { + lhs.swap(rhs); + } + } // anonymous-namespace } // namespace uuids using sprout::uuids::uuid; diff --git a/sprout/variant/apply_visitor.hpp b/sprout/variant/apply_visitor.hpp index 88d6d4c8..97ef6c58 100644 --- a/sprout/variant/apply_visitor.hpp +++ b/sprout/variant/apply_visitor.hpp @@ -6,11 +6,8 @@ namespace sprout { template - inline SPROUT_CONSTEXPR typename Visitor::result_type apply_visitor( - Visitor&& visitor, - Visitable&& visitable - ) - { + inline SPROUT_CONSTEXPR typename Visitor::result_type + apply_visitor(Visitor&& visitor, Visitable&& visitable) { return sprout::forward(visitable).apply_visitor(sprout::forward(visitor)); } } // namespace sprout diff --git a/sprout/variant/tuple.hpp b/sprout/variant/tuple.hpp index f0abe6b7..46b8e286 100644 --- a/sprout/variant/tuple.hpp +++ b/sprout/variant/tuple.hpp @@ -8,7 +8,7 @@ #include #include -namespace sprout_adl { +namespace sprout { // // tuple_get // @@ -36,7 +36,7 @@ namespace sprout_adl { tuple_get(sprout::variant&& t) { return sprout::move(sprout::tuples::get(t)); } -} // namespace sprout_adl +} // namespace sprout namespace std { // diff --git a/sprout/variant/variant.hpp b/sprout/variant/variant.hpp index 3155883c..7f5a182a 100644 --- a/sprout/variant/variant.hpp +++ b/sprout/variant/variant.hpp @@ -7,7 +7,9 @@ #include #include #include -#include +#include +#include +#include #include #include #include @@ -43,13 +45,11 @@ namespace sprout { { static_assert(Index::value < sizeof...(Types), "variant<>: invalid operand"); } - void swap(variant_impl& other) SPROUT_NOEXCEPT_EXPR( - SPROUT_NOEXCEPT_EXPR(swap(std::declval(), std::declval())) - ) + void swap(variant_impl& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(tuple_, other.tuple_))) { - using std::swap; - swap(tuple_, other.tuple_); - swap(which_, other.which_); + sprout::swap(tuple_, other.tuple_); + sprout::swap(which_, other.which_); } variant_impl& operator=(variant_impl const&) = default; }; @@ -153,14 +153,18 @@ namespace sprout { ) {} // modifiers - void swap(variant& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(impl_type::swap(other))) { + void swap(variant& other) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(impl_type::swap(other))) + { impl_type::swap(other); } variant& operator=(variant const& rhs) { static_cast(*this) = rhs; return *this; } - variant& operator=(variant&& rhs) SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value) { + variant& operator=(variant&& rhs) + SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value) + { static_cast(*this) = sprout::move(rhs); return *this; } @@ -252,8 +256,9 @@ namespace sprout { // swap // template - inline void swap(sprout::variant& lhs, sprout::variant& rhs) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + inline void + swap(sprout::variant& lhs, sprout::variant& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); }