mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-02-11 10:03:59 +00:00
add constexpr algorithm C++14 version: move, move_backward, swap_ranges, iter_swap
This commit is contained in:
parent
d5c84b07c9
commit
a3427d375f
23 changed files with 430 additions and 47 deletions
|
@ -9,6 +9,43 @@
|
|||
#define SPROUT_ALGORITHM_COPY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
copy(InputIterator first, InputIterator last, OutputIterator result) {
|
||||
while (first != last) {
|
||||
*result++ = *first++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename InputIterator, typename Result,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy(InputIterator first, InputIterator last, Result const& result) {
|
||||
return sprout::fixed::copy(first, last, result);
|
||||
}
|
||||
|
||||
template<typename Result, typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy(InputIterator first, InputIterator last) {
|
||||
return sprout::fixed::copy<Result>(first, last);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
#include <sprout/algorithm/fit/copy.hpp>
|
||||
|
||||
|
|
|
@ -9,6 +9,43 @@
|
|||
#define SPROUT_ALGORITHM_COPY_BACKWARD_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename BidirectionalIterator1, typename BidirectionalIterator2,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<BidirectionalIterator2>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR BidirectionalIterator2
|
||||
copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result) {
|
||||
while (first != last) {
|
||||
*--result = *--first;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename BidirectionalIterator, typename Result,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_backward(BidirectionalIterator first, BidirectionalIterator last, Result const& result) {
|
||||
return sprout::fixed::copy_backward(first, last, result);
|
||||
}
|
||||
|
||||
template<typename Result, typename BidirectionalIterator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_backward(BidirectionalIterator first, BidirectionalIterator last) {
|
||||
return sprout::fixed::copy_backward<Result>(first, last);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
#include <sprout/algorithm/fit/copy_backward.hpp>
|
||||
|
||||
|
|
|
@ -9,6 +9,45 @@
|
|||
#define SPROUT_ALGORITHM_COPY_IF_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator, typename Predicate,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred) {
|
||||
for (; first != last; ++first) {
|
||||
if (pred(*first)) {
|
||||
*result++ = *first;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename InputIterator, typename Result, typename Predicate,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_if(InputIterator first, InputIterator last, Result const& result, Predicate pred) {
|
||||
return sprout::fixed::copy_if(first, last, result, pred);
|
||||
}
|
||||
|
||||
template<typename Result, typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_if(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return sprout::fixed::copy_if<Result>(first, last, pred);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy_if.hpp>
|
||||
#include <sprout/algorithm/fit/copy_if.hpp>
|
||||
|
||||
|
|
|
@ -9,6 +9,43 @@
|
|||
#define SPROUT_ALGORITHM_COPY_N_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy_n.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename Size, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
copy_n(InputIterator first, Size n, OutputIterator result) {
|
||||
for (Size i = 0; i < n; ++i) {
|
||||
*result++ = *first++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename InputIterator, typename Size, typename Result,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_n(InputIterator first, Size n, Result const& result) {
|
||||
return sprout::fixed::copy_n(first, n, result);
|
||||
}
|
||||
|
||||
template<typename Result, typename Size, typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_n(InputIterator first, Size n) {
|
||||
return sprout::fixed::copy_n<Result>(first, n);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy_n.hpp>
|
||||
#include <sprout/algorithm/fit/copy_n.hpp>
|
||||
|
||||
|
|
|
@ -134,8 +134,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy(first, last, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_HPP
|
||||
|
|
|
@ -124,8 +124,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy_backward(first, last, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy_backward;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_BACKWARD_HPP
|
||||
|
|
|
@ -89,8 +89,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy_if(first, last, sprout::pit<Result>(), pred);
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy_if;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_IF_HPP
|
||||
|
|
|
@ -107,8 +107,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy_n(first, n, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy_n;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_N_HPP
|
||||
|
|
25
sprout/algorithm/iter_swap.hpp
Normal file
25
sprout/algorithm/iter_swap.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_ALGORITHM_ITER_SWAP_HPP
|
||||
#define SPROUT_ALGORITHM_ITER_SWAP_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.3 swap
|
||||
//
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
iter_swap(ForwardIterator1 a, ForwardIterator2 b) {
|
||||
sprout::swap(*a, *b);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_ITER_SWAP_HPP
|
|
@ -9,7 +9,71 @@
|
|||
#define SPROUT_ALGORITHM_MODIFYIING_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/fixed.hpp>
|
||||
#include <sprout/algorithm/fit.hpp>
|
||||
#include <sprout/algorithm/copy.hpp>
|
||||
#include <sprout/algorithm/copy_n.hpp>
|
||||
#include <sprout/algorithm/copy_if.hpp>
|
||||
#include <sprout/algorithm/copy_backward.hpp>
|
||||
#include <sprout/algorithm/move.hpp>
|
||||
#include <sprout/algorithm/move_backward.hpp>
|
||||
#include <sprout/algorithm/swap_ranges.hpp>
|
||||
#include <sprout/algorithm/iter_swap.hpp>
|
||||
#include <sprout/algorithm/transform.hpp>
|
||||
#include <sprout/algorithm/replace.hpp>
|
||||
#include <sprout/algorithm/replace_if.hpp>
|
||||
#include <sprout/algorithm/replace_copy.hpp>
|
||||
#include <sprout/algorithm/replace_copy_if.hpp>
|
||||
#include <sprout/algorithm/fill.hpp>
|
||||
#include <sprout/algorithm/fill_n.hpp>
|
||||
#include <sprout/algorithm/generate.hpp>
|
||||
#include <sprout/algorithm/generate_n.hpp>
|
||||
#include <sprout/algorithm/unfold.hpp>
|
||||
#include <sprout/algorithm/unfold_n.hpp>
|
||||
#include <sprout/algorithm/recurrence.hpp>
|
||||
#include <sprout/algorithm/recurrence_n.hpp>
|
||||
#include <sprout/algorithm/remove.hpp>
|
||||
#include <sprout/algorithm/remove_if.hpp>
|
||||
#include <sprout/algorithm/remove_copy.hpp>
|
||||
#include <sprout/algorithm/remove_copy_if.hpp>
|
||||
#include <sprout/algorithm/unique.hpp>
|
||||
#include <sprout/algorithm/unique_copy.hpp>
|
||||
#include <sprout/algorithm/reverse.hpp>
|
||||
#include <sprout/algorithm/reverse_copy.hpp>
|
||||
#include <sprout/algorithm/rotate.hpp>
|
||||
#include <sprout/algorithm/rotate_copy.hpp>
|
||||
#include <sprout/algorithm/shuffle.hpp>
|
||||
#include <sprout/algorithm/shuffle_result.hpp>
|
||||
#include <sprout/algorithm/partition.hpp>
|
||||
#include <sprout/algorithm/partition_copy.hpp>
|
||||
#include <sprout/algorithm/stable_partition.hpp>
|
||||
#include <sprout/algorithm/stable_partition_copy.hpp>
|
||||
#include <sprout/algorithm/sort.hpp>
|
||||
#include <sprout/algorithm/stable_sort.hpp>
|
||||
#include <sprout/algorithm/partial_sort.hpp>
|
||||
#include <sprout/algorithm/nth_element.hpp>
|
||||
#include <sprout/algorithm/merge.hpp>
|
||||
#include <sprout/algorithm/inplace_merge.hpp>
|
||||
#include <sprout/algorithm/set_union.hpp>
|
||||
#include <sprout/algorithm/set_intersection.hpp>
|
||||
#include <sprout/algorithm/set_difference.hpp>
|
||||
#include <sprout/algorithm/set_symmetric_difference.hpp>
|
||||
#include <sprout/algorithm/push_heap.hpp>
|
||||
#include <sprout/algorithm/pop_heap.hpp>
|
||||
#include <sprout/algorithm/make_heap.hpp>
|
||||
#include <sprout/algorithm/make_partial_heap.hpp>
|
||||
#include <sprout/algorithm/sort_heap.hpp>
|
||||
#include <sprout/algorithm/next_permutation.hpp>
|
||||
#include <sprout/algorithm/prev_permutation.hpp>
|
||||
#include <sprout/algorithm/copy_while.hpp>
|
||||
#include <sprout/algorithm/copy_until.hpp>
|
||||
#include <sprout/algorithm/clamp_range.hpp>
|
||||
#include <sprout/algorithm/clamp_range_copy.hpp>
|
||||
#include <sprout/algorithm/swap_element.hpp>
|
||||
#include <sprout/algorithm/swap_element_copy.hpp>
|
||||
#include <sprout/algorithm/random_swap.hpp>
|
||||
#include <sprout/algorithm/random_swap_result.hpp>
|
||||
#include <sprout/algorithm/bogo_sort.hpp>
|
||||
#include <sprout/algorithm/bogo_sort_result.hpp>
|
||||
#include <sprout/algorithm/bozo_sort.hpp>
|
||||
#include <sprout/algorithm/bozo_sort_result.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_MODIFYIING_HPP
|
||||
|
|
33
sprout/algorithm/move.hpp
Normal file
33
sprout/algorithm/move.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_ALGORITHM_MOVE_HPP
|
||||
#define SPROUT_ALGORITHM_MOVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.2 Move
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
move(InputIterator first, InputIterator last, OutputIterator result) {
|
||||
while (first != last) {
|
||||
*result++ = sprout::move(*first++);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_MOVE_HPP
|
33
sprout/algorithm/move_backward.hpp
Normal file
33
sprout/algorithm/move_backward.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_ALGORITHM_MOVE_BACKWARD_HPP
|
||||
#define SPROUT_ALGORITHM_MOVE_BACKWARD_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.2 Move
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
move_backward(InputIterator first, InputIterator last, OutputIterator result) {
|
||||
while (first != last) {
|
||||
*--result = sprout::move(*--first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_MOVE_BACKWARD_HPP
|
28
sprout/algorithm/swap_ranges.hpp
Normal file
28
sprout/algorithm/swap_ranges.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_ALGORITHM_SWAP_RANGES_HPP
|
||||
#define SPROUT_ALGORITHM_SWAP_RANGES_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/iter_swap.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.3 swap
|
||||
//
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CXX14_CONSTEXPR ForwardIterator2
|
||||
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) {
|
||||
while (first1 != last1) {
|
||||
sprout::iter_swap(*first1++, *first2++);
|
||||
}
|
||||
return first2;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_SWAP_RANGES_HPP
|
|
@ -63,6 +63,9 @@ namespace sprout {
|
|||
container->push_back(sprout::move(value));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR back_insert_iterator& operator*() const {
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR back_insert_iterator& operator*() {
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -63,6 +63,9 @@ namespace sprout {
|
|||
container->push_front(sprout::move(value));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR front_insert_iterator& operator*() const {
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR front_insert_iterator& operator*() {
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,9 @@ namespace sprout {
|
|||
container->insert(iter, sprout::move(value));
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR insert_iterator& operator*() const {
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR insert_iterator& operator*() {
|
||||
return *this;
|
||||
}
|
||||
|
|
28
sprout/utility/exchange.hpp
Normal file
28
sprout/utility/exchange.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_UTILITY_EXCAHNGE_HPP
|
||||
#define SPROUT_UTILITY_EXCAHNGE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 20.2.3 exchange
|
||||
//
|
||||
template<typename T, typename U = T>
|
||||
inline SPROUT_CXX14_CONSTEXPR T
|
||||
exchange(T& obj, U&& new_val) {
|
||||
T old_val = sprout::move(obj);
|
||||
obj = sprout::forward<U>(new_val);
|
||||
return old_val;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_EXCAHNGE_HPP
|
|
@ -13,5 +13,6 @@
|
|||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/exchange.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_OPERATION_HPP
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace sprout {
|
|||
typename U, typename V,
|
||||
typename
|
||||
>
|
||||
inline sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(sprout::tuples::tuple<U, V> const& rhs) {
|
||||
inline SPROUT_CXX14_CONSTEXPR sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(sprout::tuples::tuple<U, V> const& rhs) {
|
||||
first = sprout::tuples::get<0>(rhs);
|
||||
second = sprout::tuples::get<0>(rhs);
|
||||
return *this;
|
||||
|
@ -83,7 +83,7 @@ namespace sprout {
|
|||
typename U, typename V,
|
||||
typename
|
||||
>
|
||||
inline sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(sprout::tuples::tuple<U, V>&& rhs) {
|
||||
inline SPROUT_CXX14_CONSTEXPR sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(sprout::tuples::tuple<U, V>&& rhs) {
|
||||
first = sprout::forward<U>(sprout::tuples::get<0>(rhs));
|
||||
second = sprout::forward<V>(sprout::tuples::get<1>(rhs));
|
||||
return *this;
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR pair(sprout::tuples::tuple<U, V>&& other);
|
||||
|
||||
pair& operator=(pair const& rhs) = default;
|
||||
pair& operator=(pair&& rhs)
|
||||
SPROUT_CXX14_CONSTEXPR pair& operator=(pair&& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable<T1>::value && std::is_nothrow_move_assignable<T2>::value)
|
||||
{
|
||||
first = sprout::forward<T1>(rhs.first);
|
||||
|
@ -116,7 +116,7 @@ namespace sprout {
|
|||
std::is_assignable<first_type&, U const&>::value && std::is_assignable<second_type&, V const&>::value
|
||||
>::type
|
||||
>
|
||||
pair& operator=(sprout::pair<U, V> const& rhs) {
|
||||
SPROUT_CXX14_CONSTEXPR pair& operator=(sprout::pair<U, V> const& rhs) {
|
||||
first = rhs.first;
|
||||
second = rhs.second;
|
||||
return *this;
|
||||
|
@ -127,7 +127,7 @@ namespace sprout {
|
|||
std::is_assignable<first_type&, U&&>::value && std::is_assignable<second_type&, V&&>::value
|
||||
>::type
|
||||
>
|
||||
pair& operator=(sprout::pair<U, V>&& rhs) {
|
||||
SPROUT_CXX14_CONSTEXPR pair& operator=(sprout::pair<U, V>&& rhs) {
|
||||
first = sprout::forward<U>(rhs.first);
|
||||
second = sprout::forward<V>(rhs.second);
|
||||
return *this;
|
||||
|
@ -138,16 +138,16 @@ namespace sprout {
|
|||
std::is_assignable<first_type&, U const&>::value && std::is_assignable<second_type&, V const&>::value
|
||||
>::type
|
||||
>
|
||||
pair& operator=(sprout::tuples::tuple<U, V> const& rhs);
|
||||
SPROUT_CXX14_CONSTEXPR pair& operator=(sprout::tuples::tuple<U, V> const& rhs);
|
||||
template<
|
||||
typename U, typename V,
|
||||
typename = typename std::enable_if<
|
||||
std::is_assignable<first_type&, U&&>::value && std::is_assignable<second_type&, V&&>::value
|
||||
>::type
|
||||
>
|
||||
pair& operator=(sprout::tuples::tuple<U, V>&& rhs);
|
||||
SPROUT_CXX14_CONSTEXPR pair& operator=(sprout::tuples::tuple<U, V>&& rhs);
|
||||
|
||||
void swap(pair& other)
|
||||
SPROUT_CXX14_CONSTEXPR void swap(pair& 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);
|
||||
|
@ -158,7 +158,7 @@ namespace sprout {
|
|||
// swap
|
||||
//
|
||||
template<typename T1, typename T2>
|
||||
inline void
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::pair<T1, T2>& lhs, sprout::pair<T1, T2>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
|
|
|
@ -77,6 +77,7 @@ namespace sprout {
|
|||
private:
|
||||
const_pointer ptr_;
|
||||
size_type len_;
|
||||
private:
|
||||
public:
|
||||
// construct/copy/destroy:
|
||||
SPROUT_CONSTEXPR basic_string_ref()
|
||||
|
@ -100,7 +101,7 @@ namespace sprout {
|
|||
{}
|
||||
// iterators:
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
iterator
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
begin() SPROUT_NOEXCEPT {
|
||||
return iterator(*this, 0);
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ namespace sprout {
|
|||
begin() const SPROUT_NOEXCEPT {
|
||||
return const_iterator(*this, 0);
|
||||
}
|
||||
iterator
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
end() SPROUT_NOEXCEPT {
|
||||
return iterator(*this, size());
|
||||
}
|
||||
|
@ -117,10 +118,18 @@ namespace sprout {
|
|||
return const_iterator(*this, size());
|
||||
}
|
||||
#else
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
begin() SPROUT_NOEXCEPT {
|
||||
return data();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
begin() const SPROUT_NOEXCEPT {
|
||||
return data();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
end() SPROUT_NOEXCEPT {
|
||||
return data() + size();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
end() const SPROUT_NOEXCEPT {
|
||||
return data() + size();
|
||||
|
@ -174,7 +183,7 @@ namespace sprout {
|
|||
max_size() const SPROUT_NOEXCEPT {
|
||||
return size();
|
||||
}
|
||||
void
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
clear() {
|
||||
len_ = 0;
|
||||
}
|
||||
|
@ -202,14 +211,14 @@ namespace sprout {
|
|||
return ptr_[size() - 1];
|
||||
}
|
||||
// modifiers:
|
||||
void
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
swap(basic_string_ref& other)
|
||||
SPROUT_NOEXCEPT
|
||||
{
|
||||
sprout::swap(ptr_, other.ptr_);
|
||||
sprout::swap(len_, other.len_);
|
||||
}
|
||||
void
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
remove_prefix(size_type n) {
|
||||
if (n > size()) {
|
||||
n = size();
|
||||
|
@ -223,7 +232,7 @@ namespace sprout {
|
|||
: basic_string_ref(data() + n, size() - n)
|
||||
;
|
||||
}
|
||||
void
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
remove_suffix(size_type n) {
|
||||
if (n > size()) {
|
||||
n = size();
|
||||
|
@ -401,20 +410,21 @@ namespace sprout {
|
|||
SPROUT_EXPLICIT_CONVERSION operator std::basic_string<T, Traits, Allocator>() const {
|
||||
return std::basic_string<T, Traits, Allocator>(data(), size());
|
||||
}
|
||||
pointer
|
||||
SPROUT_CONSTEXPR const_pointer
|
||||
c_array() const SPROUT_NOEXCEPT {
|
||||
return data();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR pointer
|
||||
c_array() SPROUT_NOEXCEPT {
|
||||
return data();
|
||||
}
|
||||
void
|
||||
// others:
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
rangecheck(size_type i) const {
|
||||
if (i >= size()) {
|
||||
throw std::out_of_range("basic_string_ref<>: index out of range");
|
||||
}
|
||||
}
|
||||
void
|
||||
maxcheck(size_type n) const {
|
||||
rangecheck(n);
|
||||
}
|
||||
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
template<typename ConstIterator>
|
||||
|
@ -549,7 +559,7 @@ namespace sprout {
|
|||
// swap
|
||||
//
|
||||
template<typename T, typename Traits>
|
||||
inline void
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::basic_string_ref<T, Traits>& lhs, sprout::basic_string_ref<T, Traits>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#ifndef SPROUT_UTILITY_SWAP_HPP
|
||||
#define SPROUT_UTILITY_SWAP_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
|
@ -15,20 +16,29 @@ namespace sprout_swap_detail {
|
|||
using std::swap;
|
||||
|
||||
template<typename T>
|
||||
inline void
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap_impl(T& a, T& b)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(a, b)))
|
||||
{
|
||||
return swap(a, b);
|
||||
swap(a, b);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap_impl(T (& a)[N], T (& b)[N])
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(*a, *b)))
|
||||
{
|
||||
for (std::size_t i = 0; i < N; ++i) {
|
||||
swap(a[i], b[i]);
|
||||
}
|
||||
}
|
||||
} // namespace sprout_swap_detail
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// swap
|
||||
// 20.2.2 swap
|
||||
//
|
||||
template<typename T1, typename T2>
|
||||
inline void
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(T1& lhs, T2& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_swap_detail::swap_impl(lhs, rhs)))
|
||||
{
|
||||
|
|
|
@ -236,61 +236,61 @@ namespace sprout {
|
|||
|
||||
value_holder& operator=(value_holder const&) = default;
|
||||
value_holder& operator=(value_holder&&) = default;
|
||||
value_holder& operator=(argument_type p) {
|
||||
SPROUT_CXX14_CONSTEXPR value_holder& operator=(argument_type p) {
|
||||
value_holder temp(p);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
value_holder& operator=(movable_argument_type p) {
|
||||
SPROUT_CXX14_CONSTEXPR value_holder& operator=(movable_argument_type p) {
|
||||
value_holder temp(sprout::move(p));
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(value_holder& other)
|
||||
SPROUT_CXX14_CONSTEXPR void swap(value_holder& other)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(holder_, other.holder_)))
|
||||
{
|
||||
sprout::swap(holder_, other.holder_);
|
||||
}
|
||||
|
||||
operator reference() {
|
||||
SPROUT_CXX14_CONSTEXPR operator reference() {
|
||||
return helper_type::ref(holder_);
|
||||
}
|
||||
SPROUT_CONSTEXPR operator mutable_or_const_reference() const {
|
||||
return helper_type::ref(holder_);
|
||||
}
|
||||
reference operator*() {
|
||||
SPROUT_CXX14_CONSTEXPR reference operator*() {
|
||||
return helper_type::ref(holder_);
|
||||
}
|
||||
SPROUT_CONSTEXPR mutable_or_const_reference operator*() const {
|
||||
return helper_type::ref(holder_);
|
||||
}
|
||||
reference get() {
|
||||
SPROUT_CXX14_CONSTEXPR reference get() {
|
||||
return helper_type::ref(holder_);
|
||||
}
|
||||
SPROUT_CONSTEXPR mutable_or_const_reference get() const {
|
||||
return helper_type::ref(holder_);
|
||||
}
|
||||
reference value() {
|
||||
SPROUT_CXX14_CONSTEXPR reference value() {
|
||||
return get();
|
||||
}
|
||||
SPROUT_CONSTEXPR mutable_or_const_reference value() const {
|
||||
return get();
|
||||
}
|
||||
|
||||
pointer operator->() SPROUT_NOEXCEPT {
|
||||
SPROUT_CXX14_CONSTEXPR pointer operator->() SPROUT_NOEXCEPT {
|
||||
return helper_type::ptr(holder_);
|
||||
}
|
||||
SPROUT_CONSTEXPR mutable_or_const_pointer operator->() const SPROUT_NOEXCEPT {
|
||||
return helper_type::ptr(holder_);
|
||||
}
|
||||
pointer get_pointer() SPROUT_NOEXCEPT {
|
||||
SPROUT_CXX14_CONSTEXPR pointer get_pointer() SPROUT_NOEXCEPT {
|
||||
return helper_type::ptr(holder_);
|
||||
}
|
||||
SPROUT_CONSTEXPR mutable_or_const_pointer get_pointer() const SPROUT_NOEXCEPT {
|
||||
return helper_type::ptr(holder_);
|
||||
}
|
||||
pointer get_ptr() SPROUT_NOEXCEPT {
|
||||
SPROUT_CXX14_CONSTEXPR pointer get_ptr() SPROUT_NOEXCEPT {
|
||||
return get_pointer();
|
||||
}
|
||||
SPROUT_CONSTEXPR mutable_or_const_pointer get_ptr() const SPROUT_NOEXCEPT {
|
||||
|
@ -305,7 +305,7 @@ namespace sprout {
|
|||
// swap
|
||||
//
|
||||
template<typename T>
|
||||
inline void
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::value_holder<T>& lhs, sprout::value_holder<T>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue