#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/ptr_container/indirect_fun.hpp>
#include <functional>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
struct photon
{
photon() : color( rand() ),
direction( rand() ),
power( rand() )
{ }
int color;
int direction;
int power;
};
typedef std::vector<photon> vector_type;
typedef boost::ptr_vector<photon,boost::view_clone_allocator> view_type;
struct sort_by_color
{
typedef photon first_argument_type;
typedef photon second_argument_type;
typedef bool result_type;
bool operator()( const photon& l, const photon& r ) const
{
return l.color < r.color;
}
};
struct sort_by_direction
{
typedef photon first_argument_type;
typedef photon second_argument_type;
typedef bool result_type;
bool operator()( const photon& l, const photon& r ) const
{
return l.direction < r.direction;
}
};
struct sort_by_power
{
typedef photon first_argument_type;
typedef photon second_argument_type;
typedef bool result_type;
bool operator()( const photon& l, const photon& r ) const
{
return l.power < r.power;
}
};
void insert( vector_type& from, view_type& to )
{
to.insert( to.end(),
from.begin(),
from.end() );
}
int main()
{
enum { sz = 10, count = 500 };
std::vector<vector_type> photons;
view_type color_view;
view_type direction_view;
for( int i = 0; i != sz; ++i )
{
photons.push_back( vector_type() );
for( int j = 0; j != count; ++j )
photons[i].push_back( photon() );
}
for( int i = 0; i != sz; ++i )
{
insert( photons[i], color_view );
insert( photons[i], direction_view );
}
std::sort( color_view.begin(), color_view.end(), sort_by_power() );
color_view.sort( sort_by_color() );
direction_view.sort( sort_by_direction() );
return 0;
}