-2

I am trying to sort and copy an array using only <algorithm>, but cannot figure out how to accomplish either. This is the code I have been trying to make work, but with no success. What am I missing?

sorted_sc_array(const sorted_sc_array& A);          
template< sorted_sc_array& A, sorted_sc_array& T>   
auto Copy(sorted_sc_array& A, sorted_sc_array& T)   
    ->signed char*(T.begin())   
{  
  auto it1=std::begin(A);  
  auto it2=std::begin(T);

  while(it1 != std::end(A)){
    *it2++ = *it1++;
  }
  return it2;
}
Angew is no longer proud of SO
  • 161,995
  • 14
  • 331
  • 433
Chief
  • 39
  • 8

1 Answers1

1

To sort an array:

const unsigned int CAPACITY = 1024;
int array[CAPACITY];
//...
std::sort(&array[0], &array[CAPACITY]);

To copy an array:

int destination[CAPACITY];
//...
std::copy(&array[0], &array[CAPACITY], &destination[0]);

Addresses can be substituted for pointers or iterators in most functions in <algorithm>.

With Pointers

int * p_begin = &array[0];
int * p_end   = &array[CAPACITY];
//...
std::sort(p_begin, p_end);
//...
int * p_dest_begin = &destination[0];
std::copy(p_begin, p_end, p_dest_begin);
Thomas Matthews
  • 54,980
  • 14
  • 94
  • 148