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

Using namespace in a class

P: n/a
Hi,

I have the following code. However, the lambda expression becomes too
complicated, because I put "boost::lambda::" before _1 and _2.

To make it more readable, I can uncomment the commented line
"using ...". However, this would pollute the global namespace, which
is undesirable.

I'm wondering if there is any way to enable a namespace inside a class
just like enable a namespace in another namespace?

Thanks,
Peng

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/core.hpp>
#include <iostream>

//using namespace boost::lambda;

struct A {
int doit() {
int a = 10;
return (boost::lambda::_1 + boost::lambda::_2)(a, a);
}
};

int main() {
A a;
std::cout << a.doit() << std::endl;
}

Mar 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Pe*******@gmail.com wrote:
>
struct A {
int doit() {
// use the namespace inside the enclosing scope
using namespace boost::lambda;
// or bring in the structs that you want to use
using boost::lambda::_1;
using boost::lambda::_2;
int a = 10;
return (boost::lambda::_1 + boost::lambda::_2)(a, a);
}
};
Mar 14 '07 #2

P: n/a
Piyo wrote:
Pe*******@gmail.com wrote:
>>
struct A {
int doit() {
// use the namespace inside the enclosing scope
using namespace boost::lambda;
// or bring in the structs that you want to use
using boost::lambda::_1;
using boost::lambda::_2;
> int a = 10;
return (boost::lambda::_1 + boost::lambda::_2)(a, a);
}
};
or...
namespace l = boost::lambda;

return (l::_1 + l::_2)(a,a)...

or

return (l::_1 + l::_1)(a)
Mar 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.