By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

problem with stl compose1

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.