mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-19 09:35:15 -04:00
Update algorithms
This commit is contained in:
parent
e46b1fc015
commit
98d724fad4
@ -26,55 +26,69 @@ constexpr T&& forward(typename remove_reference<T>::type& t ){
|
||||
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
void copy(OutputIterator out, InputIterator it, InputIterator end){
|
||||
while(it != end){
|
||||
if(it != end){
|
||||
*out = *it;
|
||||
++out;
|
||||
++it;
|
||||
|
||||
while(++it != end){
|
||||
*++out = *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
void copy_n(OutputIterator out, InputIterator in, size_t n){
|
||||
while(n--){
|
||||
if(n > 0){
|
||||
*out = *in;
|
||||
++out;
|
||||
++in;
|
||||
|
||||
while(--n){
|
||||
*++out = *++in;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
void move_n(OutputIterator out, InputIterator in, size_t n){
|
||||
while(n--){
|
||||
if(n > 0){
|
||||
*out = std::move(*in);
|
||||
++out;
|
||||
++in;
|
||||
|
||||
while(--n){
|
||||
*++out = std::move(*++in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ForwardIterator, typename T>
|
||||
void fill(ForwardIterator it, ForwardIterator end, const T& value){
|
||||
while(it != end){
|
||||
if(it != end){
|
||||
*it = value;
|
||||
++it;
|
||||
|
||||
while(++it != end){
|
||||
*it = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ForwardIterator, typename T>
|
||||
void fill_n(ForwardIterator it, size_t n, const T& value){
|
||||
while(n--){
|
||||
if(n > 0){
|
||||
*it = value;
|
||||
++it;
|
||||
|
||||
while(--n){
|
||||
*++it = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Iterator1, typename Iterator2>
|
||||
size_t compare_n(Iterator1 it1, Iterator2 it2, size_t n){
|
||||
while(n--){
|
||||
if(*it1 != *it2){
|
||||
return *it1- *it2;
|
||||
} else {
|
||||
++it1;
|
||||
++it2;
|
||||
if(n > 0){
|
||||
while(n--){
|
||||
if(*it1 != *it2){
|
||||
return *it1- *it2;
|
||||
} else {
|
||||
++it1;
|
||||
++it2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user