How to make a pair structure

M

mitmaxtor

Hi everyone,
I am working on to implement Matlab sort function in C++ and I used
the following code. But, it seems it does not work for me. Any idea
about how to modify the code or any idea to make it work? thanks a lot

#include <vector>
#include <map>
#include <boost/bind.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <algorithm>

void main()
{
using std::vector;
typedef std::pair<double,int> dpair; // <data,index>
vector<int> data;
vector<dpair> A;

std::transform(&A[0], &A[2]
, boost::counting_iterator<int>(1)
, std::inserter(A,data.begin())
, boost::bind(std::make_pair<double,int>, _1, _2)
);

}
 
K

Kai-Uwe Bux

Hi everyone,
I am working on to implement Matlab sort function in C++ and I used
the following code. But, it seems it does not work for me. Any idea
about how to modify the code or any idea to make it work?

That would require us to know what the code is supposed to accomplish.

thanks a lot

#include <vector>
#include <map>
#include <boost/bind.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <algorithm>

void main()

int main ()
{
using std::vector;
typedef std::pair<double,int> dpair; // <data,index>
vector<int> data;
vector<dpair> A;

This vector A is empty.

std::transform(&A[0], &A[2]

Neither A[0] nor A[2] exist. You have undefined behavior.

, boost::counting_iterator<int>(1)
, std::inserter(A,data.begin())
, boost::bind(std::make_pair<double,int>, _1, _2)
);

}


Best

Kai-Uwe Bux
 
J

Joel Yliluoma

Hi everyone,
I am working on to implement Matlab sort function in C++ and I used
the following code. But, it seems it does not work for me. Any idea
about how to modify the code or any idea to make it work? thanks a lot

#include <vector>
#include <map>
#include <boost/bind.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <algorithm>

void main()
{
using std::vector;
typedef std::pair<double,int> dpair; // <data,index>
vector<int> data;
vector<dpair> A;

std::transform(&A[0], &A[2]
, boost::counting_iterator<int>(1)
, std::inserter(A,data.begin())
, boost::bind(std::make_pair<double,int>, _1, _2)
);
}

A couple of issues.

1. main() should return an int, not a void. As such, your code
contains undefined behavior and cannot be expected to work.
2. What does "Matlab sort function" do? Such knowledge is crucial
for understanding how your code is supposed to work and how it
does not work.
3. What do boost::counting_iterator and boost::bind do? These
are relevant to libboost, not the C++ language itself. As such,
your code is off-topic in this group, comp.lang.c++ .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top