#include <climits>
struct counter_object
{
typedef int value_type;
private:
int m_current_value;
public:
counter_object()
: m_current_value(1)
{ }
const value_type& operator * () const
{
return m_current_value;
}
{
++m_current_value;
return *this;
}
bool empty() const
{
return (m_current_value > 1000);
}
};
template <typename InputStream>
struct squaring_object
{
typedef int value_type;
private:
InputStream& m_input_stream;
value_type m_current_value;
public:
squaring_object(InputStream& input_stream)
: m_input_stream(input_stream)
{
if (!m_input_stream.empty())
{
m_current_value = *m_input_stream;
m_current_value = m_current_value * m_current_value;
}
}
const value_type& operator * () const
{
return m_current_value;
}
{
++m_input_stream;
if (!m_input_stream.empty())
{
m_current_value = *m_input_stream;
m_current_value = m_current_value * m_current_value;
}
return *this;
}
bool empty() const
{
return m_input_stream.empty();
}
};
struct CompareMod10
{
inline bool operator () (int a, int b) const
{
if ((a % 10) == (b % 10))
return a < b;
else
return (a % 10) < (b % 10);
}
int min_value() const { return INT_MIN; }
int max_value() const { return INT_MAX; }
};
int main()
{
{
counter_object counter;
while (!counter.empty())
{
std::cout << *counter << " ";
++counter;
}
std::cout << std::endl;
}
{
for (counter_object cnt; !cnt.empty(); ++cnt)
{
std::cout << *cnt << " ";
}
std::cout << std::endl;
}
{
counter_object counter;
squaring_object<counter_object> squares(counter);
while (!squares.empty())
{
std::cout << *squares << " ";
++squares;
}
std::cout << std::endl;
}
{
std::vector<int> intvector;
intstream_type intstream(intvector.begin(), intvector.end());
squaring_object<intstream_type> squares(intstream);
}
{
intstream_type intstream(intvector.
begin(), intvector.
end());
squaring_object<intstream_type> squares(intstream);
}
{
counter_object counter;
squaring_object<counter_object> squares(counter);
std::vector<int> intvector(100);
}
{
counter_object counter;
squaring_object<counter_object> squares(counter);
}
{
static const int ram_use = 10 * 1024 * 1024;
counter_object counter;
CompareMod10 comparemod10;
rc_counter_type rc_counter(counter, comparemod10, ram_use);
rm_counter_type rm_counter(rc_counter.result(), comparemod10, ram_use);
while (!rm_counter.empty())
{
std::cout << *rm_counter << " ";
++rm_counter;
}
std::cout << std::endl;
}
{
static const int ram_use = 10 * 1024 * 1024;
CompareMod10 comparemod10;
rc_counter_type rc_counter(comparemod10, ram_use);
for (int i = 1; i <= 1000; ++i)
rc_counter.push(i);
rm_counter_type rm_counter(rc_counter.result(), comparemod10, ram_use);
while (!rm_counter.empty())
{
std::cout << *rm_counter << " ";
++rm_counter;
}
std::cout << std::endl;
}
{
static const int ram_use = 10 * 1024 * 1024;
CompareMod10 comparemod10;
sr_counter_type sr_counter(comparemod10, ram_use);
for (int i = 1; i <= 1000; ++i)
sr_counter.push(i);
sr_counter.sort();
while (!sr_counter.empty())
{
std::cout << *sr_counter << " ";
++sr_counter;
}
std::cout << std::endl;
}
}