#include <vector>
#include <boost/array.hpp>
#include <iostream>
__declspec(noinline) void f()
{
// Regular array
int a[10] = {};
// Value
NN_FOREACH(int i, a)
std::cout << i;
// Reference to const
NN_FOREACH(int const& i, a)
std::cout << i;
// Reference to non Const
NN_FOREACH(int& i, a)
i = 1;
assert(std::find(boost::begin(a), boost::end(a), 0) == boost::end(a));
}
__declspec(noinline) void g()
{
// Boost.Array
boost::array<int, 10> a = {};
// Value
NN_FOREACH(int i, a)
std::cout << i;
// Reference to const
NN_FOREACH(int const& i, a)
std::cout << i;
// Reference to non Const
NN_FOREACH(int& i, a)
i = 1;
assert(std::find(boost::begin(a), boost::end(a), 0) == boost::end(a));
}
__declspec(noinline) void h()
{
// Std.Vector
std::vector<int> a(10);
// Value
NN_FOREACH(int i, a)
std::cout << i;
// Reference to const
NN_FOREACH(int const& i, a)
std::cout << i;
// Reference to non Const
NN_FOREACH(int& i, a)
i = 1;
assert(std::find(boost::begin(a), boost::end(a), 0) == boost::end(a));
}
__declspec(noinline) void i()
{
// Std.Vector
std::vector<int> a(10);
// Value
for(std::vector<int>::const_iterator it = a.begin(), it_end = a.end();
it != it_end;
++it)
std::cout << *it;
// Reference to const
for(std::vector<int>::const_iterator it = a.begin(), it_end = a.end();
it != it_end;
++it)
std::cout << i;
// Reference to non Const
for(std::vector<int>::iterator it = a.begin(), it_end = a.end();
it != it_end;
++it)
*it = 1;
assert(std::find(boost::begin(a), boost::end(a), 0) == boost::end(a));
}
__declspec(noinline) void j()
{
// Char pointer
char a[] = "aaaaaaaaaa";
char* p = a;
// Value
NN_FOREACH(char i, p)
std::cout << i;
// Reference to const
NN_FOREACH(char const& i, p)
std::cout << i;
// Reference
NN_FOREACH(char& i, a)
i = 'a';
assert(std::find(boost::begin(a), boost::end(boost::as_literal(a)), 0) == boost::end(boost::as_literal(a)));
}
int main()
{
f();g();h();i();j();
} |