Hello
Is it correct to use
string s = "lower case";
transform(s.beg in(),s.end(),s. begin(),toupper );
to make s uppercase ??
this was working before but it doesnt work with gcc 3
thanks 6 3207
Babis Haldas wrote: Is it correct to use
string s = "lower case"; transform(s.beg in(),s.end(),s. begin(),toupper );
to make s uppercase ??
Seems fine. I checked with a couple other compilers, they like it.
Did you provide all the necessary headers?
this was working before but it doesnt work with gcc 3
Read FAQ 5.8, then.
V
What is wrong with for_each? Josuttis has it in his table of modifying
algorithms.
Fraser.
Fraser Ross wrote: What is wrong with for_each? Josuttis has it in his table of modifying algorithms.
'for_each' is designed for calling essentially a 'void' function. That
function can modify its argument, but the return value of that function
is not used by 'for_each'. 'transform', OTOH, takes the functor and
uses the return value of each invocation to assign to the object from
the other sequence.
Just try writing the uppercasing using for_each, you will have to create
a modifying functor for that.
V
Babis Haldas wrote: Hello
Is it correct to use
string s = "lower case"; transform(s.beg in(),s.end(),s. begin(),toupper );
to make s uppercase ??
this was working before but it doesnt work with gcc 3
thanks
hello, what's the error? we're not psychic. well, maybe. i would guess
that you have multiple overloads of toupper in scope and the compiler
doesn't know which one to choose.
static_cast<int (*)(int)>(toupp er) or std::ptr_fun<in t, int>(toupper)
"Victor Bazarov" Fraser Ross wrote: What is wrong with for_each? Josuttis has it in his table of modifying algorithms.
'for_each' is designed for calling essentially a 'void' function. That function can modify its argument, but the return value of that function is not used by 'for_each'. 'transform', OTOH, takes the functor and uses the return value of each invocation to assign to the object from the other sequence.
Just try writing the uppercasing using for_each, you will have to create a modifying functor for that.
The behaviour required is not present with the function toupper. I see
for_each as definitely being the right algorithm. I would rather make a
function or functor work than use the wrong algorithm.
A missing algorithm is one that modifies a range using a second range and a
binary operation:
template <typename ForwardIterator _tp, typename InputIterator_t p, typename
BinaryOperation _tp>
BinaryOperation _tp transform_each( ForwardIterator _tp first1,
InputIterator_t p const last1, InputIterator_t p first2,
BinaryOperation _tp binaryOp) {
while (first1 != last1) {
binaryOp(*first 1, *first2);
++first1, ++first2;
}
return binaryOp;
}
Fraser. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alex Vinokur |
last post by:
Functor-parameters in the for_each() and transform() algorithms are passed by value.
Might it make sense to have also algorithms for_each2() and transform2()
which pass Functor-parameters by non-const reference?
Here is some program which demonstrates probable necessity
in such forms of for_each() and transform().
|
by: Xiaolei Li |
last post by:
first off, i'm a total newbie at this stuff so excuse any wrong usage of
terminology or whatever else.
i have a XSL to transform a Document such that all "text" nodes will
have a "SPAN" inserted around it. the XSL is given below:
<xsl:transform version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xhtml" ...
|
by: John Lehmann |
last post by:
I have an interesting problem. I am performing an XSL
transform using the System.Xml.Xsl.Transform class.
I have a database that contains the XSL style sheet
string. And it seems to work pretty well for simple
transforms. But as soon as I add Xsl variables or For each
loops to the XSL string in the db, it fails to transform
the XML. I can...
|
by: Patrick Guio |
last post by:
Dear all,
I am trying to use the std::transform algorithm to to the following
vector< vector<char> >::iterator ik = keys.begin(); // key list iterator
vector< vector<char> >::iterator is = ik; // save begin
vector<char>::const_iterator i = ik->begin();
vector<char>::const_iterator e = ik->end();
vector<char>::iterator s = is->begin();
|
by: Stephen Cook |
last post by:
Having worked through the problems around enabling the document function
using an XmlUrlResolver I started work on building a useful class to hide
the intricacies.
Trying to generalise the process I've hit a snag.
How do I resolve multiple external references?
The transform method on a stylesheet only takes one resolver, not an array
...
| |
by: Jason S |
last post by:
Hello Group,
I am just about tearing my hair out with this one and thought someone may
have some insight. I have a transform that wasn't working so I grabbed the
nearest debugger (xselerator) and saw that it works just fine. Now what I
mean by not working is that it just silently fails to produce the expected
output... no exceptions are...
|
by: schneider |
last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use
them as an
xml transform with-out use files for the Xslt?
All the methods I see use files.
I want to create a Xslt transform via code?
Any examples would be great.
|
by: Mike Hofer |
last post by:
I've got two statements in my code that are both generating weird,
weird, weird messages:
The first one was,
Dim document As System.Xml.XmlDocument
Dim navigator As System.Xml.XPath.XPathNavigator
Dim transform As System.Xml.Xsl.XslTransform
..
..
|
by: Dean Card |
last post by:
Okay, so here is the situation. I have need to do some on-the-fly image
creation. I have everything working great except for the last part of it,
applying a perspective type transform to the image. The transform will take
a rectangular 2D image and transform it to a 3D representation in 2D.
Please see the link to see what I am trying to...
|
by: Vijai Kalyan |
last post by:
Hello,
I am trying to use std::transform to take in a collection of strings,
transform them and insert the result into an output container. So, I
wrote something like this:
std::wstring doSomething (std::wstring const& str)
{
// do something to copy of str and return new value
}
|
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...
| |
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |