| 1 |
#ifndef CBEAR_BERLIOS_DE_RANGE_MOVE_HPP_INCLUDED |
|---|
| 2 |
#define CBEAR_BERLIOS_DE_RANGE_MOVE_HPP_INCLUDED |
|---|
| 3 |
|
|---|
| 4 |
#include <cbear.berlios.de/move/main.hpp> |
|---|
| 5 |
#include <cbear.berlios.de/range/sub_range.hpp> |
|---|
| 6 |
|
|---|
| 7 |
namespace cbear_berlios_de |
|---|
| 8 |
{ |
|---|
| 9 |
namespace range |
|---|
| 10 |
{ |
|---|
| 11 |
|
|---|
| 12 |
namespace detail |
|---|
| 13 |
{ |
|---|
| 14 |
|
|---|
| 15 |
class move_copy_t |
|---|
| 16 |
{ |
|---|
| 17 |
public: |
|---|
| 18 |
|
|---|
| 19 |
template<class Container, class OutputIterator> |
|---|
| 20 |
static OutputIterator do_(Container &From, OutputIterator To) |
|---|
| 21 |
{ |
|---|
| 22 |
return ::std::copy(range::begin(From), range::end(From), To); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
}; |
|---|
| 26 |
|
|---|
| 27 |
class move_common_t |
|---|
| 28 |
{ |
|---|
| 29 |
public: |
|---|
| 30 |
|
|---|
| 31 |
template<class Container, class OutputIterator> |
|---|
| 32 |
static OutputIterator do_(Container &From, OutputIterator To) |
|---|
| 33 |
{ |
|---|
| 34 |
typedef typename sub_range<Container>::type iterator_range_t; |
|---|
| 35 |
for(iterator_range_t R(From); !R.empty(); ++R.begin(), ++To) |
|---|
| 36 |
{ |
|---|
| 37 |
::cbear_berlios_de::move::assign(*To, R.front()); |
|---|
| 38 |
} |
|---|
| 39 |
return To; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
}; |
|---|
| 43 |
|
|---|
| 44 |
template<class Container, class OutputIterator> |
|---|
| 45 |
class move_t: |
|---|
| 46 |
public meta::if_c< |
|---|
| 47 |
!::boost::is_class<typename traits<Container>::value_type>::value, |
|---|
| 48 |
move_copy_t, |
|---|
| 49 |
move_common_t>::type |
|---|
| 50 |
{ |
|---|
| 51 |
}; |
|---|
| 52 |
|
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
template<class Container, class OutputIterator> |
|---|
| 56 |
iterator_range<OutputIterator> move(Container const &From, OutputIterator To) |
|---|
| 57 |
{ |
|---|
| 58 |
return iterator_range<OutputIterator>( |
|---|
| 59 |
To, detail::move_t<Container const, OutputIterator>::do_(From, To)); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
template<class Container, class OutputIterator> |
|---|
| 63 |
iterator_range<OutputIterator> move(Container &From, OutputIterator To) |
|---|
| 64 |
{ |
|---|
| 65 |
return iterator_range<OutputIterator>( |
|---|
| 66 |
To, detail::move_t<Container, OutputIterator>::do_(From, To)); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
#endif |
|---|
| 73 |
|
|---|