0

How could i sort vector of structures right after creating them by their int value using lower_bound function combined with lambda ? ( 1 line function )

vector<test*> v;
val = 10;
test * tmp = new test ( val, "Alex" );
/* something like this : 
 * auto it = lower_bound ( v . begin (), v . end (), val , [&] ( ) -> bool {} );
 */
v . insert ( it, tmp );

Structure:

class test
{
  test ( int val , string name ) : val ( val ), name ( name ) { }
  int val;
  string name;
};
kvway
  • 494
  • 4
  • 16
  • 1
    You are using too many pointers, no good. And sorting would be std::sort or std::stable_sort –  Mar 31 '16 at 19:34
  • 1
    try such lambda: `auto sortOrder = [](auto* lhs, auto* rhs) { return lhs->val < rhs->val;}` – PiotrNycz Mar 31 '16 at 19:39

0 Answers0