473,399 Members | 2,478 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,399 software developers and data experts.

What does this class do?

I found this class at:

http://www.icce.rug.nl/documents/cpl...7.html#FINDEND

class Twice
{
public:
bool operator()(size_t first, size_t second) const
{
return first == (second << 1);
}
};

it is used as the last argument to find_end() but I don't understand
what it does and why it is needed.

I have tried calling it with various integers but it always outputs 0:

Twice t = Twice();
bool t_bool = t.operator ()(4,8);
std::cout << t_bool << std::endl;
Apr 24 '07 #1
4 2243
desktop wrote:
I found this class at:

http://www.icce.rug.nl/documents/cpl...7.html#FINDEND

class Twice
{
public:
bool operator()(size_t first, size_t second) const
{
return first == (second << 1);
}
};

it is used as the last argument to find_end() but I don't understand
what it does and why it is needed.

I have tried calling it with various integers but it always outputs 0:

Twice t = Twice();
bool t_bool = t.operator ()(4,8);
t_bool = t(8,4); // should return true;
std::cout << t_bool << std::endl;
Apr 24 '07 #2
desktop wrote:
I found this class at:

http://www.icce.rug.nl/documents/cpl...7.html#FINDEND

class Twice
{
public:
bool operator()(size_t first, size_t second) const
{
return first == (second << 1);
}
};

it is used as the last argument to find_end() but I don't understand
what it does and why it is needed.

I have tried calling it with various integers but it always outputs 0:

Twice t = Twice();
bool t_bool = t.operator ()(4,8);
std::cout << t_bool << std::endl;
Try this instead:

#include <iostream>
using namespace std;

class Twice
{
public:
bool operator()(size_t first, size_t second) const
{
return first == (second << 1);
}
};

int main(){
Twice t = Twice();
bool t_bool = t.operator ()(8, 4);
std::cout << t_bool << std::endl;
}

I suppose you need to look up how '<<' works.
Apr 24 '07 #3
"desktop" <ff*@sss.comwrote in message
news:f0**********@news.net.uni-c.dk...
>I found this class at:

http://www.icce.rug.nl/documents/cpl...7.html#FINDEND

class Twice
{
public:
bool operator()(size_t first, size_t second) const
{
return first == (second << 1);
}
};

it is used as the last argument to find_end() but I don't understand what
it does and why it is needed.

I have tried calling it with various integers but it always outputs 0:

Twice t = Twice();
bool t_bool = t.operator ()(4,8);
std::cout << t_bool << std::end;
When you shift left by 1 (( << 1 )) you in effect mulitply times two. It
simply seems to be checking if the first parameter is twice the second. So
try with 8,4 since the second parm is being multiplied, not the first.
Apr 25 '07 #4
On Apr 25, 9:26 am, desktop <f...@sss.comwrote:
I found this class at:

http://www.icce.rug.nl/documents/cpl...7.html#FINDEND

class Twice
{
public:
bool operator()(size_t first, size_t second) const
{
return first == (second << 1);
}
};

it is used as the last argument to find_end() but I don't understand
what it does and why it is needed.
It's an obfuscated way of writing:
bool Twice(size_t first, size_t second)
{
return first == second * 2;
}
I have tried calling it with various integers but it always outputs 0:

Twice t = Twice();
bool t_bool = t.operator ()(4,8);
std::cout << t_bool << std::endl;
Your code has a lot of redundancy:
Twice t;
std::cout << t(4,8) << std::endl;

or even:
std::cout << Twice()(4,8) << std::endl;

If you want to output 1 then pass in a first argument
that is twice the second one.

Apr 26 '07 #5

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
19
by: Charles Law | last post by:
Take a solution with a project hierarchy along the lines of an n-tier system, so that we have a data layer, business layer and presentation layer. The presentation layer is coupled to the business...
18
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.