[ create a new paste ] login | about

Link: http://codepad.org/sJW7FGfg    [ raw code | output | fork ]

C++, pasted on May 29:
#include <vector>
#include <algorithm>

using namespace std;

struct minimum
{
  template<class T> T operator()(T const& a, T const& b )
  {
     return std::min<T>(a,b);
  }
};

template<class Container>
  Container minValues(const Container& c1, const Container& c2){
    Container tmp(c1.size());
    std::transform(c1.begin(), c1.end(), c2.begin(), tmp.begin(), minimum() );
    return tmp;
  }

int main()
{
  std::vector<float> a(4);
  std::vector<float> b(4);

  for(int i=0;i<4;i++)
  {
    a[i] = i*3 % 2;
    b[i] = a[i]+1 % 3;
  }
  
  std::vector<float> x;

  x = minValues(a,b);

  for(int i=0;i<4;++i)  cout << a[i] << " ";
  cout << endl;
  for(int i=0;i<4;++i)  cout << b[i] << " ";
  cout << endl;
  for(int i=0;i<4;++i)  cout << x[i] << " ";
  cout << endl;
}


Output:
1
2
3
0 1 0 1 
1 2 1 2 
0 1 0 1 


Create a new paste based on this one


Comments: