LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


View Poll Results: Binary/Unary Functors for Sorting/Finding (C++)?
Unary for Both 0 0%
Binary for Both 3 100.00%
Unary for Sort, Binary for Find 0 0%
Binary for Sort, Unary for Find 0 0%
Voters: 3. You may not vote on this poll

Reply
  Search this Thread
Old 05-25-2005, 01:54 AM   #1
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Question Binary/Unary Functors for Sorting/Finding (C++)?


Just a general preference question; when using a functor/function pointer to sort or find elements in a list, would you rather the functor argument be binary (i.e. take 2 arguments and return true/false for less than/equal), or would you rather the functor argument be unary (i.e. take one argument, return another argument, and let the sort/find function do the comparison)?
Code:
struct Structure
{
	int Value;
};


//...would you want to use this to sort:

	bool
LESS_THAN(Structure A, Structure B)
{ return A.Value < B.Value; }

//and these to find:

	bool
EQUAL(Structure A, Structure B)
{ return A.Value == B.Value; }

	bool
EQUAL(Structure A, int B)
{ return A.Value == B; }


//...or this for everything:

	int
GET_VALUE(Structure A)
{ return A.Value; }

//and then let the find/sort function call the comparison operator?
The reason I ask is because my list class currently takes exclusively unary functors, but if a lot of people would prefer binary functors I will change them. I think I am going to change the sort functors to binary only and provide an adapter for users who want to use unary. I will create an adapter so the other type can be used (unary/binary) either way, but I would like the natural functor type to be that which is preferred most. Thanks for your opinion!
ta0kira

Last edited by ta0kira; 05-25-2005 at 01:59 AM.
 
Old 05-30-2005, 03:12 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Original Poster
Rep: Reputation: Disabled
Binary it is! I really had this decided in my head before I posted, but I was really just looking for objectors. This was a simple change to make, and I think it was better to change it early on. I just posted the updated version of the lib (0.10.0):
http://sourceforge.net/projects/clist-ta0kira/

Thanks for your input and interest.
ta0kira
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wait_event_interruptible - invalid lvalue in unary `&' 7.e.Q Programming 4 11-08-2004 02:00 AM
Finding Image Magick Binary Cyric Slackware 1 10-17-2004 09:28 PM
Finding what processor a binary belongs to. lukebeales Linux - General 0 03-04-2004 09:18 PM
Unary expressions loke137 Programming 1 08-17-2003 02:12 AM
functors guest72485 Programming 1 08-28-2002 07:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration