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

problem with stl compose1

i wrote a program which uses the stl compose1 functor
but the compiler seems cannot find it
here is the code
//////////////////////////////////////////

#include <vector>
#include <numeric>
#include <ext/numeric>
#include <algorithm>
#include <ext/algorithm>
#include <functional>
#include <ext/functional>
using namespace std;

int main()
{
int n=10;
vector<intaa(n);
iota(aa.begin(),aa.end(),2);
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));

vector<int>::iterator
new_end=remove_if(aa.begin(),aa.end(),compose1(
bind2nd(equal_to<int>(),0),
bind2nd(modulus<int>(),2)));
aa.erase(new_end,aa.end());
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));
return 0;
}

////////////////////////////////////////////////////////
above is the code
tostrem.cc: In function 'int main()':
tostrem.cc:20: error: 'compose1' was not declared in this scope

above is the compiler information from the command g++ tostream.cc

It's strange, since I went to the file /ext/functional , it does have
compose1 there?

Does anybody know why?

Sep 17 '06 #1
4 4476
fightwater wrote:
i wrote a program which uses the stl compose1 functor
but the compiler seems cannot find it
here is the code
//////////////////////////////////////////

#include <vector>
#include <numeric>
#include <ext/numeric>
#include <algorithm>
#include <ext/algorithm>
#include <functional>
#include <ext/functional>
using namespace std;

int main()
{
int n=10;
vector<intaa(n);
iota(aa.begin(),aa.end(),2);
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));

vector<int>::iterator
new_end=remove_if(aa.begin(),aa.end(),compose1(
bind2nd(equal_to<int>(),0),
bind2nd(modulus<int>(),2)));
aa.erase(new_end,aa.end());
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));
return 0;
}

////////////////////////////////////////////////////////
above is the code
tostrem.cc: In function 'int main()':
tostrem.cc:20: error: 'compose1' was not declared in this scope

above is the compiler information from the command g++ tostream.cc

It's strange, since I went to the file /ext/functional , it does have
compose1 there?

Does anybody know why?
There is no "compose1" functor in the C++ Standard Library, so the
compiler is correct.

<OT/>

gcc includes some SGI extensions, including compose1, as extensions.
Because they are not part of the Standard Library, gcc puts them in
namespace __gnu_cxx. Accordingly, if you add "using namespace
__gnu_cxx;" to the program, you should be able to access
__gnu_cxx::compose1. You're on your own for how to use it, though,
since it's not standard.

</OT>

Best regards,

Tom

Sep 17 '06 #2
fightwater wrote:
i wrote a program which uses the stl compose1 functor
but the compiler seems cannot find it
here is the code
//////////////////////////////////////////

#include <vector>
#include <numeric>
#include <ext/numeric>
#include <algorithm>
#include <ext/algorithm>
#include <functional>
#include <ext/functional>
using namespace std;

int main()
{
int n=10;
vector<intaa(n);
iota(aa.begin(),aa.end(),2);
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));

vector<int>::iterator
new_end=remove_if(aa.begin(),aa.end(),compose1(
bind2nd(equal_to<int>(),0),
bind2nd(modulus<int>(),2)));
aa.erase(new_end,aa.end());
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));
return 0;
}

////////////////////////////////////////////////////////
above is the code
tostrem.cc: In function 'int main()':
tostrem.cc:20: error: 'compose1' was not declared in this scope

above is the compiler information from the command g++ tostream.cc

It's strange, since I went to the file /ext/functional , it does have
compose1 there?

Does anybody know why?
Whatever those ext/... headers are, they are not part of the standard. So
why would they dump their stuff into namespace std? Probably, your are
dealing with some extensions provided by either by your compiler vendor or
some third party. You should find a forum dedicated to that library and
people over there might know which namespace contains compose1. (A guess
form the pathname would be ext::compose1.)
Best

Kai-Uwe Bux
Sep 17 '06 #3
"fightwater" <ha*****@gmail.comwrote:
i wrote a program which uses the stl compose1 functor
but the compiler seems cannot find it
here is the code
//////////////////////////////////////////

#include <vector>
#include <numeric>
#include <ext/numeric>
#include <algorithm>
#include <ext/algorithm>
#include <functional>
#include <ext/functional>
using namespace std;

int main()
{
int n=10;
vector<intaa(n);
iota(aa.begin(),aa.end(),2);
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));

vector<int>::iterator
new_end=remove_if(aa.begin(),aa.end(),compose1(
bind2nd(equal_to<int>(),0),
bind2nd(modulus<int>(),2)));
aa.erase(new_end,aa.end());
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));
return 0;
}

////////////////////////////////////////////////////////
above is the code
tostrem.cc: In function 'int main()':
tostrem.cc:20: error: 'compose1' was not declared in this scope

above is the compiler information from the command g++ tostream.cc

It's strange, since I went to the file /ext/functional , it does have
compose1 there?

Does anybody know why?
'compose1' is not part of the standard library. If your functional
include has it, it probably either has some sort of conditional
compilation removing it, or doesn't put it in the std namespace.

--
There are two things that simply cannot be doubted. Logic and our
ability to sense the world around us. Doubt those, and you no longer
have anyone to discuss it with, nor any ability to discuss it.
Sep 17 '06 #4
Thomas Tutone 写道:
fightwater wrote:
i wrote a program which uses the stl compose1 functor
but the compiler seems cannot find it
here is the code
//////////////////////////////////////////

#include <vector>
#include <numeric>
#include <ext/numeric>
#include <algorithm>
#include <ext/algorithm>
#include <functional>
#include <ext/functional>
using namespace std;

int main()
{
int n=10;
vector<intaa(n);
iota(aa.begin(),aa.end(),2);
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));

vector<int>::iterator
new_end=remove_if(aa.begin(),aa.end(),compose1(
bind2nd(equal_to<int>(),0),
bind2nd(modulus<int>(),2)));
aa.erase(new_end,aa.end());
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));
return 0;
}

////////////////////////////////////////////////////////
above is the code
tostrem.cc: In function 'int main()':
tostrem.cc:20: error: 'compose1' was not declared in this scope

above is the compiler information from the command g++ tostream.cc

It's strange, since I went to the file /ext/functional , it does have
compose1 there?

Does anybody know why?

There is no "compose1" functor in the C++ Standard Library, so the
compiler is correct.

<OT/>

gcc includes some SGI extensions, including compose1, as extensions.
Because they are not part of the Standard Library, gcc puts them in
namespace __gnu_cxx. Accordingly, if you add "using namespace
__gnu_cxx;" to the program, you should be able to access
__gnu_cxx::compose1. You're on your own for how to use it, though,
since it's not standard.

</OT>

Best regards,

Tom
ok, I see.
the compose1 is under namespace __gnu_cxx
If I using __gnu_cxx, it will compile fine.

But I have strange question to ask here.
the iota function, which is define in <ext/numeric>, is also under
namespace __gnu_cxx.
Why I can use it without using namespace __gnu_cxx

here is the code I tested the iota function
//////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <ext/numeric>
using namespace std;

int main()
{
int n=10;
vector<intaa(n);
iota(aa.begin(),aa.end(),2);
copy(aa.begin(),aa.end(),ostream_iterator<int>(cou t,"\n"));

return 0;
}
///////////////////////////////////////////////////////////////////////////
it compiles fine, and works fine.

Can anybody explain that to me?

Sep 18 '06 #5

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

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
0
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: Lutz Altmann | last post by:
hi :) i'm trying to use the "functional extensions" of the stl. having a "problem" with the unary_compose.. The following code seems right to me, but doesnt compile - if i declare "operator()"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.