473,763 Members | 5,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

std::sort std::vector predicate problem

How can I make this construction valid? It still gives me error about
no matching function std::sort(...). I made a little search and wrong
thing is probably the predicate...

template <typename TT Polygon<T::
Height() const
{
class BinPred : public std::binary_fun ction< Vector2D<T>,
Vector2D<T>, bool >
{
bool operator() ( Vector2D<Trhs, Vector2D<Tlhs )
{
return rhs.Y() < lhs.Y;
}
};

// vertices_ is structure already filled with Vector2D's
std::vector< Vector2D<T tmp = vertices_;
std::sort( tmp.begin(), tmp.end(), BinPred() );

return std::abs( tmp.front().Y() - tmp.back().Y() );
}

Apr 6 '07 #1
1 5169
ms****@gmail.co m wrote:
How can I make this construction valid? It still gives me error about
no matching function std::sort(...). I made a little search and wrong
thing is probably the predicate...

template <typename TT Polygon<T::
Height() const
{
class BinPred : public std::binary_fun ction< Vector2D<T>,
Vector2D<T>, bool >
{
bool operator() ( Vector2D<Trhs, Vector2D<Tlhs )
{
return rhs.Y() < lhs.Y;
}
};
IIUC local classes do not have external linkage and therefore cannot be
used as template arguments.
// vertices_ is structure already filled with Vector2D's
std::vector< Vector2D<T tmp = vertices_;
std::sort( tmp.begin(), tmp.end(), BinPred() );
See above. Also, make sure you #include <algorithm>.
return std::abs( tmp.front().Y() - tmp.back().Y() );
}
--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Apr 6 '07 #2

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

Similar topics

8
3503
by: lok | last post by:
i have a class: template <class T1, class T2> class CPairMapping { public: typedef std::pair<T1, T2> ValuePair_t; typedef std::vector<ValuePair_t> ValueList_t; typedef std::binary_function< ValuePair_t, ValuePair_t, bool> ValuePair_IsLess; void SortAscend(const ValuePair_IsLess& isLess_) {
4
3349
by: hall | last post by:
I accidently overloaded a static member function that I use as predicate in the std::sort() for a vector and ended up with a compiler error. Is this kind of overload not allowed for predicates and if so, why not? Shouldn the compiler be able to tell which of he overloaded functions to use? The second A::comp() is the one I accidently added and gives the error message (in Borland C++Builder 6) Unit1.cpp E2285 Could not find a match for
7
3546
by: Ireneusz SZCZESNIAK | last post by:
I want to sort a vector with the std::sort function. There are two functions: one with two arguments, the other with three arguments. I am using the one with three arguments. I noticed that there is a huge overhead of using this function, which comes from copying the function object, i.e., the object that compares the elements of the vector, which is passed to the function not by reference but by value. Now, at the end of this mail...
6
8027
by: Jason Heyes | last post by:
What is a good way of removing elements from std::vector so that the elements removed satisfy a predicate and end up stored in another std::vector. It seems as though the algorithm std::remove_if only achieves half the job. Here is how I would use std::remove_if to remove elements from std::vector based on predicate: v.erase(std::remove_if(v.begin(), v.end(), pred), v.end()); After that line is executed I cannot get back the elements...
4
1916
by: Johan | last post by:
Hi, Why does my vector not sort. What I understand is you have to overload the < operator, but that does not work. see code below Thanks Johan
10
4082
by: eiji | last post by:
Hi folks, I have a problem compiling this under VC6! Maybe someone has some minutes to look at this: template<class T> class Compare { public: Compare(){}; virtual ~Compare(){};
5
3909
by: fade | last post by:
Good afternoon, I need some advice on the following: I've got a class that has a member std::vector<CStringm_vFileName and a member CString m_path; The vector contains a bunch of filenames with no path included (no C:\...) eg: my_file2.jpg, my_file1.bmp, etc... and m_path stores the path, eg: C:\folder1 I want to sort this vector according to different criterion, such as
5
6054
by: jeremit0 | last post by:
I'm trying to sort a vector<complex<double and can't figure it out. I recognize the problem is that there isn't a default operator< for complex data types. I have written my own operator and can use it, but std::sort doesn't seem to find it. I have copied a very simple example below. Everything compiles just fine when the line with std::sort function is commented out, but with that line included a whole slew of errors are given like: ...
5
3184
by: Ganesh | last post by:
hi ! Can the predicate function used in std::sort take optional arguments ? For instance. I have a class Point. I create a vector of this and then want to compare the slopes of these points with respect to another point of the same class (Graham's convex hull algorithm anyone ?) ganesh
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.