#include <iostream>
#include <set>
#include <vector>
struct A
{
int member[10] {1,5,7,2,3,8,4,9,6,0};
std::vector<std::size_t> another_member {5,6,7,8,9,0,1,2,3,4} ;
};
template < typename ORDER > struct order_compare
{
order_compare( const ORDER& a ) : order(a) {}
bool operator() (const int lhs, const int rhs) const
{ return order[lhs] < order[rhs] ; }
const ORDER& order ;
};
int main()
{
A object ;
{
std::set< int, order_compare< int[10] > > s( object.member ) ;
for( int i=0 ; i<10 ; ++i ) s.insert(i);
for( int v : s ) std::cout << v << ' ' ;
std::cout << '\n' ;
}
{
std::set< int, order_compare< std::vector<std::size_t> > > s( object.another_member ) ;
for( int i=0 ; i<10 ; ++i ) s.insert(i);
for( int v : s ) std::cout << v << ' ' ;
std::cout << '\n' ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8dmVjdG9yPgoKc3RydWN0IEEKewogICAgaW50IG1lbWJlclsxMF0gezEsNSw3LDIsMyw4LDQsOSw2LDB9OwogICAgc3RkOjp2ZWN0b3I8c3RkOjpzaXplX3Q+IGFub3RoZXJfbWVtYmVyIHs1LDYsNyw4LDksMCwxLDIsMyw0fSA7Cn07Cgp0ZW1wbGF0ZSA8IHR5cGVuYW1lIE9SREVSID4gc3RydWN0IG9yZGVyX2NvbXBhcmUKewogICAgb3JkZXJfY29tcGFyZSggY29uc3QgT1JERVImIGEgKSA6IG9yZGVyKGEpIHt9CgogICAgYm9vbCBvcGVyYXRvcigpIChjb25zdCBpbnQgbGhzLCBjb25zdCBpbnQgcmhzKSBjb25zdAogICAgeyByZXR1cm4gb3JkZXJbbGhzXSA8IG9yZGVyW3Joc10gOyB9CgogICAgY29uc3QgT1JERVImIG9yZGVyIDsKfTsKCmludCBtYWluKCkKewogICAgQSBvYmplY3QgOwoKICAgIHsKICAgICAgICBzdGQ6OnNldDwgaW50LCBvcmRlcl9jb21wYXJlPCBpbnRbMTBdID4gPiBzKCBvYmplY3QubWVtYmVyICk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