diff --git a/sprout/pit/pit.hpp b/sprout/pit/pit.hpp index 1f1eb599..2afb51f8 100644 --- a/sprout/pit/pit.hpp +++ b/sprout/pit/pit.hpp @@ -47,31 +47,31 @@ namespace sprout { value_type elem; public: pit() = default; - void swap(pit& other) + SPROUT_CXX14_CONSTEXPR void swap(pit& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(elem, other.elem))) { sprout::swap(elem, other.elem); } // iterators: - iterator begin() { + SPROUT_CXX14_CONSTEXPR iterator begin() { return iterator(elem, enumerable_size); } SPROUT_CONSTEXPR const_iterator begin() const { return const_iterator(elem, enumerable_size); } - iterator end() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR iterator end() SPROUT_NOEXCEPT { return iterator(elem, 0); } SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT { return const_iterator(elem, 0); } - reverse_iterator rbegin() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR reverse_iterator rbegin() SPROUT_NOEXCEPT { return reverse_iterator(end()); } SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT { return const_reverse_iterator(end()); } - reverse_iterator rend() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR reverse_iterator rend() SPROUT_NOEXCEPT { return reverse_iterator(begin()); } SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT { @@ -100,13 +100,13 @@ namespace sprout { return enumerable_size == 0; } // element access: - reference operator[](size_type) { + SPROUT_CXX14_CONSTEXPR reference operator[](size_type) { return elem; } SPROUT_CONSTEXPR const_reference operator[](size_type) const { return elem; } - reference at(size_type i) { + SPROUT_CXX14_CONSTEXPR reference at(size_type i) { return i < size() ? elem : (throw std::out_of_range("pit<>: index out of range"), elem) @@ -118,20 +118,20 @@ namespace sprout { : (throw std::out_of_range("pit<>: index out of range"), elem) ; } - reference front() { + SPROUT_CXX14_CONSTEXPR reference front() { return elem; } SPROUT_CONSTEXPR const_reference front() const { return elem; } - reference back() { + SPROUT_CXX14_CONSTEXPR reference back() { return elem; } SPROUT_CONSTEXPR const_reference back() const { return elem; } // others: - void rangecheck(size_type i) const { + SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const { if (i >= size()) { throw std::out_of_range("pit<>: index out of range"); } @@ -144,7 +144,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::pit& lhs, sprout::pit& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index b6a17042..2ca8701a 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -84,31 +84,31 @@ namespace sprout { SPROUT_CONSTEXPR random_result operator()() const { return distribution_(engine_); } - result_type& result() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR result_type& result() SPROUT_NOEXCEPT { return result_; } SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT { return result_; } - result_type& generated_value() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR result_type& generated_value() SPROUT_NOEXCEPT { return result_; } SPROUT_CONSTEXPR result_type const& generated_value() const SPROUT_NOEXCEPT { return result_; } - engine_type& engine() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT { return engine_; } SPROUT_CONSTEXPR engine_type const& engine() const SPROUT_NOEXCEPT { return engine_; } - random_result& next_generator() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR random_result& next_generator() SPROUT_NOEXCEPT { return *this; } SPROUT_CONSTEXPR random_result const& next_generator() const SPROUT_NOEXCEPT { return *this; } - distribution_type& distribution() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR distribution_type& distribution() SPROUT_NOEXCEPT { return distribution_; } SPROUT_CONSTEXPR distribution_type const& distribution() const SPROUT_NOEXCEPT { @@ -126,7 +126,7 @@ namespace sprout { SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return distribution_.max(); } - void swap(random_result& other) + SPROUT_CXX14_CONSTEXPR void swap(random_result& other) SPROUT_NOEXCEPT_EXPR( SPROUT_NOEXCEPT_EXPR(sprout::swap(result_, other.result_)) && SPROUT_NOEXCEPT_EXPR(sprout::swap(engine_, other.engine_)) @@ -152,12 +152,12 @@ namespace sprout { SPROUT_CONSTEXPR pointer operator->() const SPROUT_NOEXCEPT { return &result_; } - random_result& operator++() { + SPROUT_CXX14_CONSTEXPR random_result& operator++() { random_result temp((*this)()); temp.swap(*this); return *this; } - random_result operator++(int) { + SPROUT_CXX14_CONSTEXPR random_result operator++(int) { random_result result(*this); ++*this; return result; @@ -215,25 +215,25 @@ namespace sprout { SPROUT_CONSTEXPR random_result operator()() const { return engine_(); } - result_type& result() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR result_type& result() SPROUT_NOEXCEPT { return result_; } SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT { return result_; } - result_type& generated_value() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR result_type& generated_value() SPROUT_NOEXCEPT { return result_; } SPROUT_CONSTEXPR result_type const& generated_value() const SPROUT_NOEXCEPT { return result_; } - engine_type& engine() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT { return engine_; } SPROUT_CONSTEXPR engine_type const& engine() const SPROUT_NOEXCEPT { return engine_; } - random_result& next_generator() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR random_result& next_generator() SPROUT_NOEXCEPT { return *this; } SPROUT_CONSTEXPR random_result const& next_generator() const SPROUT_NOEXCEPT { @@ -274,12 +274,12 @@ namespace sprout { SPROUT_CONSTEXPR pointer operator->() const SPROUT_NOEXCEPT { return &result_; } - random_result& operator++() { + SPROUT_CXX14_CONSTEXPR random_result& operator++() { random_result temp((*this)()); temp.swap(*this); return *this; } - random_result operator++(int) { + SPROUT_CXX14_CONSTEXPR random_result operator++(int) { random_result result(*this); random_result temp((*this)()); temp.swap(*this); @@ -291,7 +291,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::random::random_result& lhs, sprout::random::random_result& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/rational/rational.hpp b/sprout/rational/rational.hpp index 2d835cab..3792b1c1 100644 --- a/sprout/rational/rational.hpp +++ b/sprout/rational/rational.hpp @@ -96,11 +96,15 @@ namespace sprout { : base_type(n, d, normalize_g(n, d)) {} - rational& operator=(rational const&) = default; - rational& operator=(param_type n) SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR rational& operator=(rational const& rhs) SPROUT_NOEXCEPT { + rational temp(rhs); + sprout::swap(temp, *this); + return *this; + } + SPROUT_CXX14_CONSTEXPR rational& operator=(param_type n) SPROUT_NOEXCEPT { return assign(n, 1); } - rational& assign(param_type n, param_type d) { + SPROUT_CXX14_CONSTEXPR rational& assign(param_type n, param_type d) { rational temp(n, d); sprout::swap(temp, *this); return *this; @@ -113,7 +117,7 @@ namespace sprout { return den_; } - rational& operator+=(rational const& rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator+=(rational const& rhs) { IntType g = sprout::gcd(den_, rhs.den_); den_ /= g; num_ = num_ * (rhs.den_ / g) + rhs.num_ * den_; @@ -122,7 +126,7 @@ namespace sprout { den_ *= rhs.den_ / g; return *this; } - rational& operator-=(rational const& rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator-=(rational const& rhs) { IntType g = sprout::gcd(den_, rhs.den_); den_ /= g; num_ = num_ * (rhs.den_ / g) - rhs.num_ * den_; @@ -131,14 +135,14 @@ namespace sprout { den_ *= rhs.den_ / g; return *this; } - rational& operator*=(rational const& rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator*=(rational const& rhs) { IntType gcd1 = sprout::gcd(num_, rhs.den_); IntType gcd2 = sprout::gcd(rhs.num_, den_); num_ =(num_ / gcd1) * (rhs.num_ / gcd2); den_ =(den_ / gcd2) * (rhs.den_ / gcd1); return *this; } - rational& operator/=(rational const& rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator/=(rational const& rhs) { if (rhs.num_ == IntType(0)) { throw sprout::bad_rational(); } @@ -155,33 +159,33 @@ namespace sprout { } return *this; } - rational& operator+=(param_type rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator+=(param_type rhs) { return *this += rational(rhs); } - rational& operator-=(param_type rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator-=(param_type rhs) { return *this -= rational(rhs); } - rational& operator*=(param_type rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator*=(param_type rhs) { return *this *= rational(rhs); } - rational& operator/=(param_type rhs) { + SPROUT_CXX14_CONSTEXPR rational& operator/=(param_type rhs) { return *this /= rational(rhs); } - rational& operator++() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR rational& operator++() SPROUT_NOEXCEPT { num_ += den_; return *this; } - rational& operator--() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR rational& operator--() SPROUT_NOEXCEPT { num_ -= den_; return *this; } - rational operator++(int) SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR rational operator++(int) SPROUT_NOEXCEPT { rational result(*this); ++*this; return result; } - rational operator--(int) SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR rational operator--(int) SPROUT_NOEXCEPT { rational result(*this); --*this; return result; diff --git a/sprout/sub_array/sub_array.hpp b/sprout/sub_array/sub_array.hpp index 5d52ac5f..ac998241 100644 --- a/sprout/sub_array/sub_array.hpp +++ b/sprout/sub_array/sub_array.hpp @@ -243,11 +243,11 @@ namespace sprout { ) {} - void fill(const_reference value) { + SPROUT_CXX14_CONSTEXPR void fill(const_reference value) { std::fill_n(begin(), size(), value); } template - void swap(sub_array& other) + SPROUT_CXX14_CONSTEXPR void swap(sub_array& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(other.array_, array_))) { sprout::swap(other.array_, array_); @@ -255,13 +255,13 @@ namespace sprout { sprout::swap(other.to_last_, to_last_); } // iterators: - iterator begin() { + SPROUT_CXX14_CONSTEXPR iterator begin() { return sprout::next(sprout::begin(get_array()), to_first_); } SPROUT_CONSTEXPR const_iterator begin() const { return sprout::next(sprout::begin(get_array()), to_first_); } - iterator end() { + SPROUT_CXX14_CONSTEXPR iterator end() { return sprout::next(sprout::begin(get_array()), to_last_); } SPROUT_CONSTEXPR const_iterator end() const { @@ -284,13 +284,13 @@ namespace sprout { return to_first_ == to_last_; } // element access: - reference operator[](size_type i) { + SPROUT_CXX14_CONSTEXPR reference operator[](size_type i) { return *sprout::next(sprout::begin(get_array()), to_first_ + i); } SPROUT_CONSTEXPR const_reference operator[](size_type i) const { return *sprout::next(sprout::begin(get_array()), to_first_ + i); } - reference at(size_type i) { + SPROUT_CXX14_CONSTEXPR reference at(size_type i) { return i < size() ? *sprout::next(sprout::begin(get_array()), to_first_ + i) : (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), to_first_ + i)) ; @@ -300,20 +300,20 @@ namespace sprout { : (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), to_first_ + i)) ; } - reference front() { + SPROUT_CXX14_CONSTEXPR reference front() { return *sprout::next(sprout::begin(get_array()), to_first_); } SPROUT_CONSTEXPR const_reference front() const { return *sprout::next(sprout::begin(get_array()), to_first_); } - reference back() { + SPROUT_CXX14_CONSTEXPR reference back() { return *sprout::next(sprout::begin(get_array()), to_last_ - 1); } SPROUT_CONSTEXPR const_reference back() const { return *sprout::next(sprout::begin(get_array()), to_last_ - 1); } - pointer data() { + SPROUT_CXX14_CONSTEXPR pointer data() { return get_array().data() + to_first_; } SPROUT_CONSTEXPR const_pointer data() const { @@ -321,32 +321,35 @@ namespace sprout { } // others: template - sub_array& operator=(sub_array const& rhs) { + SPROUT_CXX14_CONSTEXPR sub_array& operator=(sub_array const& rhs) { array_ = rhs.array_; to_first_ = rhs.to_first_; to_last_ = rhs.to_last_; return *this; } template - sub_array& operator=(sub_array&& rhs) { + SPROUT_CXX14_CONSTEXPR sub_array& operator=(sub_array&& rhs) { array_ = std::move(rhs.array_); to_first_ = std::move(rhs.to_first_); to_last_ = std::move(rhs.to_last_); return *this; } - pointer c_array() { + SPROUT_CXX14_CONSTEXPR pointer c_array() { return data(); } - void assign(const_reference value) { + SPROUT_CONSTEXPR const_pointer c_array() const { + return data(); + } + SPROUT_CXX14_CONSTEXPR void assign(const_reference value) { fill(value); } - void rangecheck(size_type i) const { + SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const { if (i >= size()) { throw std::out_of_range("sub_array<>: index out of range"); } } - param_type get_internal() { + SPROUT_CXX14_CONSTEXPR param_type get_internal() { return impl_type::template to_param(array_); } SPROUT_CONSTEXPR const_param_type get_internal() const { @@ -378,7 +381,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::sub_array& lhs, sprout::sub_array& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/uuid/uuid.hpp b/sprout/uuid/uuid.hpp index 2350992c..399db609 100644 --- a/sprout/uuid/uuid.hpp +++ b/sprout/uuid/uuid.hpp @@ -81,47 +81,47 @@ namespace sprout { public: value_type elems[static_size]; public: - void fill(const_reference value) { + SPROUT_CXX14_CONSTEXPR void fill(const_reference value) { std::fill_n(begin(), size(), value); } - void swap(uuid& other) SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR void swap(uuid& other) SPROUT_NOEXCEPT { std::swap_ranges(other.begin(), other.end(), begin()); } // iterators: #if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION - iterator begin() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR iterator begin() SPROUT_NOEXCEPT { return iterator(*this, 0); } SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT { return const_iterator(*this, 0); } - iterator end() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR iterator end() SPROUT_NOEXCEPT { return iterator(*this, size()); } SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT { return const_iterator(*this, size()); } #else - iterator begin() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR iterator begin() SPROUT_NOEXCEPT { return &elems[0]; } SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT { return &elems[0]; } - iterator end() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR iterator end() SPROUT_NOEXCEPT { return &elems[0] + size(); } SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT { return &elems[0] + size(); } #endif - reverse_iterator rbegin() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR reverse_iterator rbegin() SPROUT_NOEXCEPT { return reverse_iterator(end()); } SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT { return const_reverse_iterator(end()); } - reverse_iterator rend() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR reverse_iterator rend() SPROUT_NOEXCEPT { return reverse_iterator(begin()); } SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT { @@ -159,13 +159,13 @@ namespace sprout { return size() == 0; } // element access: - reference operator[](size_type i) { + SPROUT_CXX14_CONSTEXPR reference operator[](size_type i) { return elems[i]; } SPROUT_CONSTEXPR const_reference operator[](size_type i) const { return elems[i]; } - reference at(size_type i) { + SPROUT_CXX14_CONSTEXPR reference at(size_type i) { return i < size() ? elems[i] : (throw std::out_of_range("uuid: index out of range"), elems[i]) @@ -177,20 +177,20 @@ namespace sprout { : (throw std::out_of_range("uuid: index out of range"), elems[i]) ; } - reference front() { + SPROUT_CXX14_CONSTEXPR reference front() { return elems[0]; } SPROUT_CONSTEXPR const_reference front() const { return elems[0]; } - reference back() { + SPROUT_CXX14_CONSTEXPR reference back() { return elems[size() - 1]; } SPROUT_CONSTEXPR const_reference back() const { return elems[size() - 1]; } - pointer data() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR pointer data() SPROUT_NOEXCEPT { return &elems[0]; } SPROUT_CONSTEXPR const_pointer data() const SPROUT_NOEXCEPT { @@ -198,13 +198,16 @@ namespace sprout { } // others: - pointer c_array() SPROUT_NOEXCEPT { + SPROUT_CXX14_CONSTEXPR pointer c_array() SPROUT_NOEXCEPT { return &elems[0]; } - void assign(const_reference value) { + SPROUT_CONSTEXPR const_pointer c_array() SPROUT_NOEXCEPT { + return &elems[0]; + } + SPROUT_CXX14_CONSTEXPR void assign(const_reference value) { fill(value); } - void rangecheck(size_type i) const { + SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const { if (i >= size()) { throw std::out_of_range("uuid: index out of range"); } @@ -267,7 +270,7 @@ namespace sprout { // // swap // - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::uuids::uuid& lhs, sprout::uuids::uuid& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { diff --git a/sprout/variant/variant.hpp b/sprout/variant/variant.hpp index 729c7c21..d310f800 100644 --- a/sprout/variant/variant.hpp +++ b/sprout/variant/variant.hpp @@ -63,7 +63,7 @@ namespace sprout { static_assert(Index::value < sizeof...(Types), "variant<>: invalid operand"); } public: - void swap(variant_impl& other) + SPROUT_CXX14_CONSTEXPR void swap(variant_impl& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(tuple_, other.tuple_))) { sprout::swap(tuple_, other.tuple_); @@ -238,23 +238,23 @@ namespace sprout { ) {} // modifiers - void swap(variant& other) + SPROUT_CXX14_CONSTEXPR void swap(variant& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval().swap(other))) { impl_type::swap(other); } - variant& operator=(variant const& rhs) { + SPROUT_CXX14_CONSTEXPR variant& operator=(variant const& rhs) { static_cast(*this) = rhs; return *this; } - variant& operator=(variant&& rhs) + SPROUT_CXX14_CONSTEXPR variant& operator=(variant&& rhs) SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value) { static_cast(*this) = sprout::move(rhs); return *this; } template - variant& operator=(T&& rhs) { + SPROUT_CXX14_CONSTEXPR variant& operator=(T&& rhs) { static_cast(*this) = variant(sprout::forward(rhs)); return *this; } @@ -302,7 +302,7 @@ namespace sprout { ; } template - typename std::enable_if< + SPROUT_CXX14_CONSTEXPR typename std::enable_if< I != sizeof...(Types), typename sprout::tuples::tuple_element::type& >::type get_at() { @@ -318,7 +318,7 @@ namespace sprout { return get_at::value>(); } template - typename std::enable_if< + SPROUT_CXX14_CONSTEXPR typename std::enable_if< sprout::types::find_index::value != sizeof...(Types), U& >::type get() { @@ -334,7 +334,7 @@ namespace sprout { ; } template - typename visitor_result::type, variant>::type + SPROUT_CXX14_CONSTEXPR typename visitor_result::type, variant>::type apply_visitor(Visitor&& visitor) { typedef typename visitor_result::type, variant>::type result_type; return SPROUT_ASSERT(0 <= which_ && sprout::math::less(which_, sizeof...(Types))), @@ -347,7 +347,7 @@ namespace sprout { // swap // template - inline void + inline SPROUT_CXX14_CONSTEXPR void swap(sprout::variant& lhs, sprout::variant& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {