473,396 Members | 1,924 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,396 software developers and data experts.

generate

I totally messed up with this:

We have
--------------------------------------
generate(v.begin(), v.end(), my_func);
--------------------------------------

and my_func:
-----------
int my_func();
-----------

So, if my_func() does not take parameters, how can generate data?
I see in examples, it uses static variables, but it isn't thread-safe.

I have a class, and I want from data of class produce values to fill
vector v. But in my case my_func() MUST NOT be static. How can I pass a
non-static member function to generate()?

------------------------------------------------
template<class ForwardIterator, class Generator>
void generate(
ForwardIterator _First,
ForwardIterator _Last,
Generator _Gen
);
------------------------------------------------
What is "class Generator"?
Is something like "Interface" in Java?
I must implement a specific method in my class, and my class must derive
from Generator?

thanks and sorry for my bombing (3 questions in a day)
Feb 1 '06 #1
5 1827
* Chameleon:
I totally messed up with this:

We have
--------------------------------------
generate(v.begin(), v.end(), my_func);
--------------------------------------

and my_func:
-----------
int my_func();
-----------

So, if my_func() does not take parameters, how can generate data?
I see in examples, it uses static variables, but it isn't thread-safe.

I have a class, and I want from data of class produce values to fill
vector v. But in my case my_func() MUST NOT be static. How can I pass a
non-static member function to generate()?


I'd recommend using a simple loop instead of std::generate.

But if you feel you absolutely must use std::generate, pass it a functor
object.

That's an object that provides an operator(); see the FAQ for more
information.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 1 '06 #2
Chameleon wrote:
What is "class Generator"?
Is something like "Interface" in Java?
I must implement a specific method in my class, and my class must derive
from Generator?

First off, in a template definition, the word "class" in the argument
just means any type (doesn't necessarily have to be a class).

The function class in the template, doesn't have to be a function.
It can be a object of a class that implements operator(). That
object can keep track in it's own member variables.

Feb 1 '06 #3
Chameleon wrote:
I totally messed up with this:

We have
--------------------------------------
generate(v.begin(), v.end(), my_func);
--------------------------------------

and my_func:
-----------
int my_func();
-----------

So, if my_func() does not take parameters, how can generate data?
It could be just 'rand', right?
I see in examples, it uses static variables, but it isn't thread-safe.
No, I suppose not. Threads are not part of the language, though.
I have a class, and I want from data of class produce values to fill
vector v. But in my case my_func() MUST NOT be static. How can I pass a
non-static member function to generate()?
You don't pass a member. You pass an object of your class.
------------------------------------------------
template<class ForwardIterator, class Generator>
void generate(
ForwardIterator _First,
ForwardIterator _Last,
Generator _Gen
);
------------------------------------------------
What is "class Generator"?
A functor.
Is something like "Interface" in Java?
No. The whole idea is that it should have data members.
I must implement a specific method in my class, and my class must derive
from Generator?
Yes, you need to implement a function call operator.
thanks and sorry for my bombing (3 questions in a day)


Don't be sorry, the more you ask, the more you learn (hopefully).

BTW, what book on the Standard library are you currently reading that does
not answer those concerns/questions?

V
--
Please remove capital As from my address when replying by mail
Feb 1 '06 #4
Victor Bazarov wrote:
Chameleon wrote:
I totally messed up with this:

We have
--------------------------------------
generate(v.begin(), v.end(), my_func);
--------------------------------------

and my_func:
-----------
int my_func();
-----------

So, if my_func() does not take parameters, how can generate data?


It could be just 'rand', right?
I see in examples, it uses static variables, but it isn't thread-safe.


No, I suppose not. Threads are not part of the language, though.
I have a class, and I want from data of class produce values to fill
vector v. But in my case my_func() MUST NOT be static. How can I pass
a non-static member function to generate()?


You don't pass a member. You pass an object of your class.
------------------------------------------------
template<class ForwardIterator, class Generator>
void generate(
ForwardIterator _First,
ForwardIterator _Last,
Generator _Gen
);
------------------------------------------------
What is "class Generator"?


A functor.
Is something like "Interface" in Java?


No. The whole idea is that it should have data members.
I must implement a specific method in my class, and my class must
derive from Generator?


Yes, you need to implement a function call operator.
thanks and sorry for my bombing (3 questions in a day)


Don't be sorry, the more you ask, the more you learn (hopefully).

BTW, what book on the Standard library are you currently reading that does
not answer those concerns/questions?


I read Thinking in C++ but about 4 years before and until now, I used
C++ like a C with classes, (multiple) inheritance, string, vector, map
and other goodies. For instance I NEVER used iterators before. Only to
have access in algorithm members like:
sort(v.begin() + index_start, v.begin() + index_end);
Feb 2 '06 #5
Chameleon wrote:
[..]
I read Thinking in C++ but about 4 years before and until now, I used
C++ like a C with classes, (multiple) inheritance, string, vector, map
and other goodies. For instance I NEVER used iterators before. Only to
have access in algorithm members like:
sort(v.begin() + index_start, v.begin() + index_end);


Well, that's a good start. Now you need to add your own predicate.
Both a function and a class. Should make you learn a tad.

With all due respect to Bruce Eckel, you need to get yourself a copy
on the Standard Library (Josuttis is the best) and I also recommend
"C++ Templates" by Vandevoorde and Josuttis.

V
--
Please remove capital As from my address when replying by mail
Feb 2 '06 #6

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

Similar topics

0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
3
by: Garry Dawkins | last post by:
Hey Frank, I'm a novice with this taking over someone elses application. I'm attempting to add a dataset to a page. I have the query to populate the page and I have the walkthrough instructions. ...
1
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging...
9
by: Henk Verhoeven | last post by:
We are not alone! "Where other MDA tools are generating programmingcode, Codeless chooses not to generate code at all". OK, phpPeanuts is not an MDA tool (it has no fancy modeling GUI). But it...
4
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather...
10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
5
by: pete | last post by:
Help, I can not find this data wizard in my toolbox under data. To generate a dataset 1.. From the Data menu, choose Generate DataSet. Tip If you do not see the Data menu, click in the...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: bthubbard | last post by:
This may not be the best group in which to post this. If there is a better location please direct me there. I have been experimenting with Sandcastle to generate CHM help file documentation for...
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
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
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...
0
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,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.