From 071217f1d400d7ff56f7a22326c0ee0bcc099cb6 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Fri, 9 Aug 2013 22:14:43 +0900 Subject: [PATCH] fix rational: for clang --- sprout/iterator/adjacent_filter_iterator.hpp | 6 +-- sprout/iterator/filter_iterator.hpp | 8 ++-- sprout/iterator/while_iterator.hpp | 8 ++-- sprout/random/additive_combine.hpp | 6 +-- sprout/random/inversive_congruential.hpp | 6 +-- sprout/random/linear_congruential.hpp | 12 +++--- sprout/random/linear_feedback_shift.hpp | 6 +-- sprout/random/mersenne_twister.hpp | 8 ++-- sprout/random/normal_distribution.hpp | 6 +-- sprout/random/shuffle_order.hpp | 6 +-- sprout/rational/arithmetic.hpp | 30 +++++-------- sprout/rational/rational.hpp | 45 ++++++++------------ sprout/rational/values.hpp | 5 +-- 13 files changed, 66 insertions(+), 86 deletions(-) diff --git a/sprout/iterator/adjacent_filter_iterator.hpp b/sprout/iterator/adjacent_filter_iterator.hpp index 719cbb95..419c3cad 100644 --- a/sprout/iterator/adjacent_filter_iterator.hpp +++ b/sprout/iterator/adjacent_filter_iterator.hpp @@ -44,7 +44,7 @@ namespace sprout { typedef typename std::iterator_traits::pointer pointer; typedef typename std::iterator_traits::reference reference; private: - struct private_constructor_tag {}; + struct private_construct_t {}; private: static SPROUT_CONSTEXPR iterator_type find_next(iterator_type first, iterator_type last, Predicate pred) { return sprout::adjacent_find(first, last, pred); @@ -62,7 +62,7 @@ namespace sprout { void satisfy_predicate() { current = sprout::adjacent_find(current, last, pred); } - SPROUT_CONSTEXPR adjacent_filter_iterator(Predicate pred, iterator_type it, iterator_type last, private_constructor_tag) + SPROUT_CONSTEXPR adjacent_filter_iterator(Predicate pred, iterator_type it, iterator_type last, private_construct_t) : current(it) , last(last) , pred(pred) @@ -119,7 +119,7 @@ namespace sprout { return result; } SPROUT_CONSTEXPR adjacent_filter_iterator next() const { - return adjacent_filter_iterator(pred, checked_next(find_next(current, last, pred), last), last, private_constructor_tag()); + return adjacent_filter_iterator(pred, checked_next(find_next(current, last, pred), last), last, private_construct_t()); } void swap(adjacent_filter_iterator& other) SPROUT_NOEXCEPT_EXPR( diff --git a/sprout/iterator/filter_iterator.hpp b/sprout/iterator/filter_iterator.hpp index c3899e34..048bd41b 100644 --- a/sprout/iterator/filter_iterator.hpp +++ b/sprout/iterator/filter_iterator.hpp @@ -45,7 +45,7 @@ namespace sprout { typedef typename std::iterator_traits::pointer pointer; typedef typename std::iterator_traits::reference reference; private: - struct private_constructor_tag {}; + struct private_construct_t {}; private: static SPROUT_CONSTEXPR iterator_type find_next(iterator_type first, iterator_type last, Predicate pred) { return sprout::find_if(first, last, pred); @@ -68,7 +68,7 @@ namespace sprout { --current; } } - SPROUT_CONSTEXPR filter_iterator(Predicate pred, iterator_type it, iterator_type last, private_constructor_tag) + SPROUT_CONSTEXPR filter_iterator(Predicate pred, iterator_type it, iterator_type last, private_construct_t) : current(it) , last(last) , pred(pred) @@ -132,10 +132,10 @@ namespace sprout { return temp; } SPROUT_CONSTEXPR filter_iterator next() const { - return filter_iterator(pred, find_next(sprout::next(current), last, pred), last, private_constructor_tag()); + return filter_iterator(pred, find_next(sprout::next(current), last, pred), last, private_construct_t()); } SPROUT_CONSTEXPR filter_iterator prev() const { - return filter_iterator(pred, find_prev(sprout::prev(current), pred), last, private_constructor_tag()); + return filter_iterator(pred, find_prev(sprout::prev(current), pred), last, private_construct_t()); } void swap(filter_iterator& other) SPROUT_NOEXCEPT_EXPR( diff --git a/sprout/iterator/while_iterator.hpp b/sprout/iterator/while_iterator.hpp index 2c87330c..4ea53554 100644 --- a/sprout/iterator/while_iterator.hpp +++ b/sprout/iterator/while_iterator.hpp @@ -47,7 +47,7 @@ namespace sprout { typedef typename std::iterator_traits::pointer pointer; typedef typename std::iterator_traits::reference reference; private: - struct private_constructor_tag {}; + struct private_construct_t {}; private: static SPROUT_CONSTEXPR iterator_type find_next(iterator_type first, iterator_type last, Predicate pred) { return first == last || pred(*first) ? first @@ -74,7 +74,7 @@ namespace sprout { --current; } } - SPROUT_CONSTEXPR while_iterator(Predicate pred, iterator_type it, iterator_type last, private_constructor_tag) + SPROUT_CONSTEXPR while_iterator(Predicate pred, iterator_type it, iterator_type last, private_construct_t) : current(it) , last(last) , pred(pred) @@ -138,10 +138,10 @@ namespace sprout { return temp; } SPROUT_CONSTEXPR while_iterator next() const { - return while_iterator(pred, find_next(sprout::next(current), last, pred), last, private_constructor_tag()); + return while_iterator(pred, find_next(sprout::next(current), last, pred), last, private_construct_t()); } SPROUT_CONSTEXPR while_iterator prev() const { - return while_iterator(pred, find_prev(sprout::prev(current), pred), last, private_constructor_tag()); + return while_iterator(pred, find_prev(sprout::prev(current), pred), last, private_construct_t()); } void swap(while_iterator& other) SPROUT_NOEXCEPT_EXPR( diff --git a/sprout/random/additive_combine.hpp b/sprout/random/additive_combine.hpp index d7470ed7..36bec930 100644 --- a/sprout/random/additive_combine.hpp +++ b/sprout/random/additive_combine.hpp @@ -36,7 +36,7 @@ namespace sprout { return base1_type::modulus - 1; } public: - struct private_constructor_tag {}; + struct private_construct_t {}; private: base1_type mlcg1_; base2_type mlcg2_; @@ -44,7 +44,7 @@ namespace sprout { SPROUT_CONSTEXPR additive_combine_engine( base1_type const& mlcg1, base2_type const& mlcg2, - private_constructor_tag + private_construct_t ) : mlcg1_(mlcg1) , mlcg2_(mlcg2) @@ -59,7 +59,7 @@ namespace sprout { additive_combine_engine( rnd1.engine(), rnd2.engine(), - private_constructor_tag() + private_construct_t() ) ); } diff --git a/sprout/random/inversive_congruential.hpp b/sprout/random/inversive_congruential.hpp index 074a1640..2f3c64f1 100644 --- a/sprout/random/inversive_congruential.hpp +++ b/sprout/random/inversive_congruential.hpp @@ -28,7 +28,7 @@ namespace sprout { public: typedef IntType result_type; private: - struct private_constructor_tag {}; + struct private_construct_t {}; public: SPROUT_STATIC_CONSTEXPR IntType multiplier = a; SPROUT_STATIC_CONSTEXPR IntType increment = b; @@ -56,14 +56,14 @@ namespace sprout { private: IntType x_; private: - SPROUT_CONSTEXPR inversive_congruential_engine(IntType const& x, private_constructor_tag) + SPROUT_CONSTEXPR inversive_congruential_engine(IntType const& x, private_construct_t) : x_(x) {} SPROUT_CONSTEXPR sprout::random::random_result generate(result_type result) const { return sprout::random::random_result( result, - inversive_congruential_engine(result, private_constructor_tag()) + inversive_congruential_engine(result, private_construct_t()) ); } public: diff --git a/sprout/random/linear_congruential.hpp b/sprout/random/linear_congruential.hpp index 4607cf7a..8ce5a269 100644 --- a/sprout/random/linear_congruential.hpp +++ b/sprout/random/linear_congruential.hpp @@ -31,7 +31,7 @@ namespace sprout { public: typedef UIntType result_type; private: - struct private_constructor_tag {}; + struct private_construct_t {}; public: SPROUT_STATIC_CONSTEXPR UIntType multiplier = a; SPROUT_STATIC_CONSTEXPR UIntType increment = c; @@ -60,13 +60,13 @@ namespace sprout { private: UIntType x_; private: - SPROUT_CONSTEXPR linear_congruential_engine(UIntType const& x, private_constructor_tag) + SPROUT_CONSTEXPR linear_congruential_engine(UIntType const& x, private_construct_t) : x_(x) {} SPROUT_CONSTEXPR sprout::random::random_result generate(result_type result) const { return sprout::random::random_result( result, - linear_congruential_engine(result, private_constructor_tag()) + linear_congruential_engine(result, private_construct_t()) ); } public: @@ -141,7 +141,7 @@ namespace sprout { public: typedef std::uint32_t result_type; private: - struct private_constructor_tag {}; + struct private_construct_t {}; typedef sprout::random::linear_congruential_engine< std::uint64_t, std::uint64_t(0xDEECE66DUL) | (std::uint64_t(0x5) << 32), @@ -161,7 +161,7 @@ namespace sprout { private: lcf_type lcf_; private: - SPROUT_CONSTEXPR rand48(lcf_type const& lcf, private_constructor_tag) + SPROUT_CONSTEXPR rand48(lcf_type const& lcf, private_construct_t) : lcf_(lcf) {} SPROUT_CONSTEXPR sprout::random::random_result generate( @@ -170,7 +170,7 @@ namespace sprout { { return sprout::random::random_result( lcf_result.result() >> 17, - rand48(lcf_result.engine(), private_constructor_tag()) + rand48(lcf_result.engine(), private_construct_t()) ); } public: diff --git a/sprout/random/linear_feedback_shift.hpp b/sprout/random/linear_feedback_shift.hpp index d488c0b6..507502c4 100644 --- a/sprout/random/linear_feedback_shift.hpp +++ b/sprout/random/linear_feedback_shift.hpp @@ -23,7 +23,7 @@ namespace sprout { public: typedef UIntType result_type; private: - struct private_constructor_tag {}; + struct private_construct_t {}; public: SPROUT_STATIC_CONSTEXPR int word_size = w; SPROUT_STATIC_CONSTEXPR int exponent1 = k; @@ -56,13 +56,13 @@ namespace sprout { private: UIntType x_; private: - SPROUT_CONSTEXPR linear_feedback_shift_engine(UIntType const& x, private_constructor_tag) + SPROUT_CONSTEXPR linear_feedback_shift_engine(UIntType const& x, private_construct_t) : x_(x) {} SPROUT_CONSTEXPR sprout::random::random_result generate(result_type result) const { return sprout::random::random_result( result, - linear_feedback_shift_engine(result, private_constructor_tag()) + linear_feedback_shift_engine(result, private_construct_t()) ); } public: diff --git a/sprout/random/mersenne_twister.hpp b/sprout/random/mersenne_twister.hpp index 3713d5f3..a029f96e 100644 --- a/sprout/random/mersenne_twister.hpp +++ b/sprout/random/mersenne_twister.hpp @@ -31,7 +31,7 @@ namespace sprout { public: typedef UIntType result_type; private: - struct private_constructor_tag {}; + struct private_construct_t {}; public: SPROUT_STATIC_CONSTEXPR std::size_t word_size = w; SPROUT_STATIC_CONSTEXPR std::size_t state_size = n; @@ -86,7 +86,7 @@ namespace sprout { sprout::array x_; std::size_t i_; private: - SPROUT_CONSTEXPR mersenne_twister_engine(sprout::array const& x, std::size_t i, private_constructor_tag) + SPROUT_CONSTEXPR mersenne_twister_engine(sprout::array const& x, std::size_t i, private_construct_t) : x_(x) , i_(i) {} @@ -290,7 +290,7 @@ namespace sprout { mersenne_twister_engine( x_, i_ + 1, - private_constructor_tag() + private_construct_t() ) ); } @@ -301,7 +301,7 @@ namespace sprout { args..., x_[m - 1] ^ ((x_[n - 1] & upper_mask) | (x_[0] & lower_mask) >> 1) ^ ((x_[0] & 1) * a) }}, 0, - private_constructor_tag() + private_construct_t() ); } template diff --git a/sprout/random/normal_distribution.hpp b/sprout/random/normal_distribution.hpp index d908aa96..a12a4f5c 100644 --- a/sprout/random/normal_distribution.hpp +++ b/sprout/random/normal_distribution.hpp @@ -32,7 +32,7 @@ namespace sprout { typedef RealType input_type; typedef RealType result_type; private: - struct private_constructor_tag {}; + struct private_construct_t {}; public: // // param_type @@ -105,7 +105,7 @@ namespace sprout { SPROUT_CONSTEXPR normal_distribution( RealType mean, RealType sigma, RealType r1, RealType r2, RealType cached_rho, bool valid, - private_constructor_tag + private_construct_t ) : mean_(mean) , sigma_(sigma) @@ -132,7 +132,7 @@ namespace sprout { r2, cached_rho, valid, - private_constructor_tag() + private_construct_t() ) ); } diff --git a/sprout/random/shuffle_order.hpp b/sprout/random/shuffle_order.hpp index 08232e3f..26d2c6d3 100644 --- a/sprout/random/shuffle_order.hpp +++ b/sprout/random/shuffle_order.hpp @@ -55,7 +55,7 @@ namespace sprout { typedef UniformRandomNumberGenerator base_type; typedef typename base_type::result_type result_type; private: - struct private_constructor_tag {}; + struct private_construct_t {}; public: SPROUT_STATIC_CONSTEXPR std::size_t buffer_size = k; SPROUT_STATIC_CONSTEXPR std::size_t table_size = k; @@ -97,7 +97,7 @@ namespace sprout { base_type const& rng, sprout::array const& v, result_type const& y, - private_constructor_tag + private_construct_t ) : member_type{rng, v, y} {} @@ -110,7 +110,7 @@ namespace sprout { rnd.engine(), sprout::fixed::set(v_, j, rnd.result()), v_[j], - private_constructor_tag() + private_construct_t() ) ); } diff --git a/sprout/rational/arithmetic.hpp b/sprout/rational/arithmetic.hpp index 886e225e..ddece4c2 100644 --- a/sprout/rational/arithmetic.hpp +++ b/sprout/rational/arithmetic.hpp @@ -26,9 +26,8 @@ namespace sprout { 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() + return sprout::detail::rational_construct_access::raw_construct( + -r.numerator(), r.denominator() ); } @@ -46,9 +45,8 @@ namespace sprout { IntType g, IntType den, IntType num ) { - return sprout::detail::make_rational( - num / g, den * (rhs.denominator() / g), - sprout::detail::rational_private_constructor_tag() + return sprout::detail::rational_construct_access::raw_construct( + num / g, den * (rhs.denominator() / g) ); } template @@ -115,9 +113,8 @@ namespace sprout { IntType g, IntType den, IntType num ) { - return sprout::detail::make_rational( - num / g, den * (rhs.denominator() / g), - sprout::detail::rational_private_constructor_tag() + return sprout::detail::rational_construct_access::raw_construct( + num / g, den * (rhs.denominator() / g) ); } template @@ -184,10 +181,9 @@ namespace sprout { IntType gcd1, IntType gcd2 ) { - return sprout::detail::make_rational( + return sprout::detail::rational_construct_access::raw_construct( (lhs.numerator() / gcd1) * (rhs.numerator() / gcd2), - (lhs.denominator() / gcd2) * (rhs.denominator() / gcd1), - sprout::detail::rational_private_constructor_tag() + (lhs.denominator() / gcd2) * (rhs.denominator() / gcd1) ); } } // namespace detail @@ -215,14 +211,8 @@ namespace sprout { 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() - ) + return den < IntType(0) ? sprout::detail::rational_construct_access::raw_construct(-num, -den) + : sprout::detail::rational_construct_access::raw_construct(num, den) ; } template diff --git a/sprout/rational/rational.hpp b/sprout/rational/rational.hpp index 86b78332..2d835cab 100644 --- a/sprout/rational/rational.hpp +++ b/sprout/rational/rational.hpp @@ -21,15 +21,10 @@ namespace sprout { class rational; namespace detail { - struct rational_private_constructor_tag {}; + struct rational_private_construct_t {}; 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 - ); + class rational_construct_access; } // namespace detail namespace detail { @@ -66,11 +61,11 @@ namespace sprout { : private sprout::detail::rational_impl { static_assert(sprout::numeric_limits::is_specialized, "sprout::numeric_limits::is_specialized"); + friend class sprout::detail::rational_construct_access; 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) { @@ -86,7 +81,7 @@ namespace sprout { using base_type::num_; using base_type::den_; private: - SPROUT_CONSTEXPR rational(param_type n, param_type d, private_constructor_tag) + SPROUT_CONSTEXPR rational(sprout::detail::rational_private_construct_t, param_type n, param_type d) : base_type(n, d) {} public: @@ -198,28 +193,24 @@ namespace sprout { SPROUT_CONSTEXPR operator bool() const SPROUT_NOEXCEPT { 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() - ); - } + class rational_construct_access { + public: + static SPROUT_CONSTEXPR sprout::rational + raw_construct( + typename sprout::detail::call_traits::param_type n, + typename sprout::detail::call_traits::param_type d + ) + { + return sprout::rational( + sprout::detail::rational_private_construct_t(), + n, d + ); + } + }; } // namespace detail } // namespace sprout diff --git a/sprout/rational/values.hpp b/sprout/rational/values.hpp index 1a6394f8..d3d0d803 100644 --- a/sprout/rational/values.hpp +++ b/sprout/rational/values.hpp @@ -20,9 +20,8 @@ namespace sprout { 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() + : sprout::detail::rational_construct_access::raw_construct( + -x.numerator(), x.denominator() ) ; }