Skip to main content
added 2 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
    Value max   = values[0];
    int   index = 0;
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max   = values[0];
    int   index = 0;
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }

If The type of Value (which holds your int/float) pair is actualy typedefed to std::pair<int, float>std::pair<int, float> then this is the default behavior.

    Value max   = values[0];
    int   index = 0;
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }

If The type of Value (which holds your int/float) pair is actualy typedefed to std::pair<int, float> then this is the default behavior.

    Value max   = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max   = values[0];
    int   index = 0;
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }

If The type of Value (which holds your int/float) pair is actualy typedefed to std::pair<int, float> then this is the default behavior.

added 2591 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Values   values;
// Initialize all values;

// Then.
Values::const_iterator find = std::max_element(values.begin(), values.end());

// Want the raw index number for some strange reason.
int     index = std::distance(values.begin(), find); 

// Note if you insist on using arrays rather than vectors then the C++11 version
//      works with vectors and arrays exactly the same way:
Value* find = std::max_element(std::begin(values), std::end(values));

// But if you insist on using arrays but are stuck with C++03
Value* find = std::max_element(&values[0], &values[size]);
    Value max   = values[0];
    int   index = 0;
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }
Values   values;
// Initialize all values;

// Then.
Values::const_iterator find = std::max_element(values.begin(), values.end());

// Want the raw index number for some strange reason.
int     index = std::distance(values.begin(), find);
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }
Values   values;
// Initialize all values;

// Then.
Values::const_iterator find = std::max_element(values.begin(), values.end());

// Want the raw index number for some strange reason.
int     index = std::distance(values.begin(), find); 

// Note if you insist on using arrays rather than vectors then the C++11 version
//      works with vectors and arrays exactly the same way:
Value* find = std::max_element(std::begin(values), std::end(values));

// But if you insist on using arrays but are stuck with C++03
Value* find = std::max_element(&values[0], &values[size]);
    Value max   = values[0];
    int   index = 0;
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }
added 2591 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Values   values;
// Initialize all values;

// Then.
std::vector<Value>Values::const_iterator find = std::max_element(values.begin(), values.end());

// Want the raw index number for some strange reason.
int     index = std::distance(values.begin(), find);
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }
Values   values;
// Initialize all values;

// Then.
std::vector<Value>::const_iterator = std::max_element(values.begin(), values.end());
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
Values   values;
// Initialize all values;

// Then.
Values::const_iterator find = std::max_element(values.begin(), values.end());

// Want the raw index number for some strange reason.
int     index = std::distance(values.begin(), find);
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        max = std::max(max, values[loop]);
    }
    // Modified based on comments. To get index use:
    Value max = values[0];
    for(int loop = 1; loop < size; ++loop)
    {
        if (max < values[loop])
        {
             index = loop; 
             max   = values[loop];
        }
    }
added 2591 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading