Skip to content

Commit 9ac0f72

Browse files
Use algorithms for affected operations
1 parent 0afff5d commit 9ac0f72

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

libcxx/include/__locale_dir/num.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef _LIBCPP___LOCALE_DIR_NUM_H
1010
#define _LIBCPP___LOCALE_DIR_NUM_H
1111

12+
#include <__algorithm/copy.h>
1213
#include <__algorithm/find.h>
1314
#include <__algorithm/reverse.h>
1415
#include <__charconv/to_chars_integral.h>
@@ -885,9 +886,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_ty
885886
const numpunct<char_type>& __np = std::use_facet<numpunct<char_type> >(__iob.getloc());
886887
typedef typename numpunct<char_type>::string_type string_type;
887888
string_type __nm = __v ? __np.truename() : __np.falsename();
888-
for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, (void)++__s)
889-
*__s = *__i;
890-
return __s;
889+
return std::copy(__nm.begin(), __nm.end(), __s);
891890
}
892891

893892
template <class _CharT, class _OutputIterator>

libcxx/include/__locale_dir/pad_and_output.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#if _LIBCPP_HAS_LOCALIZATION
1515

16+
# include <__algorithm/copy.h>
17+
# include <__algorithm/fill_n.h>
1618
# include <ios>
1719

1820
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -30,12 +32,9 @@ _LIBCPP_HIDE_FROM_ABI _OutputIterator __pad_and_output(
3032
__ns -= __sz;
3133
else
3234
__ns = 0;
33-
for (; __ob < __op; ++__ob, (void)++__s)
34-
*__s = *__ob;
35-
for (; __ns; --__ns, (void)++__s)
36-
*__s = __fl;
37-
for (; __ob < __oe; ++__ob, (void)++__s)
38-
*__s = *__ob;
35+
__s = std::copy(__ob, __op, __s);
36+
__s = std::fill_n(__s, __ns, __fl);
37+
__s = std::copy(__op, __oe, __s);
3938
__iob.width(0);
4039
return __s;
4140
}

libcxx/include/__random/piecewise_constant_distribution.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <__algorithm/upper_bound.h>
1313
#include <__config>
1414
#include <__cstddef/ptrdiff_t.h>
15+
#include <__iterator/back_insert_iterator.h>
1516
#include <__random/is_valid.h>
1617
#include <__random/uniform_real_distribution.h>
1718
#include <__vector/vector.h>
@@ -190,8 +191,7 @@ piecewise_constant_distribution<_RealType>::param_type::param_type(
190191
__areas_.assign(1, 0.0);
191192
} else {
192193
__densities_.reserve(__b_.size() - 1);
193-
for (size_t __i = 0; __i < __b_.size() - 1; ++__i, (void)++__f_w)
194-
__densities_.push_back(*__f_w);
194+
std::copy_n(__f_w, __b_.size() - 1, std::back_inserter(__densities_));
195195
__init();
196196
}
197197
}

libcxx/include/__random/piecewise_linear_distribution.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <__algorithm/upper_bound.h>
1313
#include <__config>
1414
#include <__cstddef/ptrdiff_t.h>
15+
#include <__iterator/back_insert_iterator.h>
1516
#include <__random/is_valid.h>
1617
#include <__random/uniform_real_distribution.h>
1718
#include <__vector/comparison.h>
@@ -194,8 +195,7 @@ piecewise_linear_distribution<_RealType>::param_type::param_type(
194195
__areas_.assign(1, 0.0);
195196
} else {
196197
__densities_.reserve(__b_.size());
197-
for (size_t __i = 0; __i < __b_.size(); ++__i, (void)++__f_w)
198-
__densities_.push_back(*__f_w);
198+
std::copy_n(__f_w, __b_.size(), std::back_inserter(__densities_));
199199
__init();
200200
}
201201
}

0 commit comments

Comments
 (0)