473,382 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to make a pair structure

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,intdpair; // <data,index>
vector<intdata;
vector<dpairA;

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)
);

}
Nov 21 '07 #1
2 1799
mi*******@gmail.com wrote:
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,intdpair; // <data,index>
vector<intdata;
vector<dpairA;
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
Nov 21 '07 #2
On Tue, 20 Nov 2007 23:43:58 -0800 (PST), mi*******@gmail.com wrote:
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,intdpair; // <data,index>
vector<intdata;
vector<dpairA;

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++ .

--
Joel Yliluoma - http://iki.fi/bisqwit/
Nov 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: pmatos | last post by:
Hi all, Is there a way of (after creating a pair) set its first and second element of not? (pair is definitely a read-only struct)? Cheers, Paulo Matos
4
by: John | last post by:
Can anybody tell me why MS would put such a basic data structure, like System.Web.UI.Pair, into a UI namespace? The Pair class, to me, is something you use just as much at a deeper level as you...
4
by: hufel | last post by:
Hi, I'm doing my first big project in C# and I'm stuck with a problem that I believe has a simple and efficient solution for it (I just haven't bumped into it yet...). The concept is the...
4
by: Florent Garcin | last post by:
Hello! I would like to use the map structure with a key of Pair<string, string> and an int as the value. Pair is defined as: template <class T1, class T2> class Pair {
4
by: onkar | last post by:
#include<iostream> using namespace std; int main(void){ const pair<const char*,const char*arr={ pair<const char*,const char*>("1","1"), pair<const char*,const char*>("12","12"), pair<const...
9
by: xz | last post by:
What sense do h files make in c/cpp? I never thought about this question before. Does the existence of h files make sense at all? Why do we need to declare functions in h files and...
48
by: istillshine | last post by:
When I used gprof to see which function consumed most running time, I identified the following one. sz was less than 5000 on average, but foo had been called about 1,000,000 times. I have tried...
9
by: shaun roe | last post by:
Question about pointer-to-data members I have a deeply nested loop, the innermost bit looks a little like this: for(it(vec.begin(), end(vec.end()), it!=end;++it){ if (global == 0){ myObj =...
82
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.