1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
// in #include "until.h"
namespace userTools
{
inline void array_until_ptr_size(const int* pdata, size_t count)
{
for(size_t i = 0; i < count; ++i)
{
std::cout << " " << pdata[i];
}
}
inline void array_until_ptr_ptr(const int* pbegin, const int* pend)
{
for( ; pbegin < pend; ++pbegin)
{
std::cout << " " << *pbegin;
}
}
}
using namespace std;
using namespace userTools;
/*Until Keyword
//
//The until keyword will loop through and output a
//vector or array from the first element all the way
//to the last element. If used with an integer it
//will output all the numbers from 0 to the last number.
*/
int main()
{
int array_numbers[6] = {3, 6, 1, 2, 9, 15};
const size_t size = sizeof(array_numbers) / sizeof(array_numbers[0]);
cout << "array_until_ptr_size =";
array_until_ptr_size(array_numbers, size);
cout << endl;
cout << "array_until_ptr_ptr =";
array_until_ptr_ptr(array_numbers, array_numbers + size);
cout << endl;
cout << endl;
cout << "array_until_ptr_size:" << endl;
for(int i = 0, s = (int)size; 0 < s; ++i, s -= 2)
{
cout << "i=" << i << ",s=" << s << " = ";
array_until_ptr_size(&array_numbers[i], s);
cout << endl;
}
cout << endl;
cout << "array_until_ptr_ptr:" << endl;
for(const int *b = array_numbers, *e = (b + size); b < e; ++b, --e)
{
cout << "b=" << b << ",e=" << e << " = ";
array_until_ptr_ptr(b, e);
cout << endl;
}
cout << endl;
return 0;
}
|